|
| 1 | +import * as webpack from 'webpack'; |
| 2 | +import * as path from 'path'; |
| 3 | +import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'; |
| 4 | +import * as WebpackKarmaDieHardPlugin from '@mattlewis92/webpack-karma-die-hard'; |
| 5 | + |
| 6 | +export default (config: any) => { |
| 7 | + |
| 8 | + config.set({ |
| 9 | + |
| 10 | + // base path that will be used to resolve all patterns (eg. files, exclude) |
| 11 | + basePath: './', |
| 12 | + |
| 13 | + // frameworks to use |
| 14 | + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter |
| 15 | + frameworks: ['mocha'], |
| 16 | + |
| 17 | + // list of files / patterns to load in the browser |
| 18 | + files: [ |
| 19 | + 'test/entry.ts' |
| 20 | + ], |
| 21 | + |
| 22 | + // preprocess matching files before serving them to the browser |
| 23 | + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor |
| 24 | + preprocessors: { |
| 25 | + 'test/entry.ts': ['webpack', 'sourcemap'] |
| 26 | + }, |
| 27 | + |
| 28 | + webpack: { |
| 29 | + resolve: { |
| 30 | + extensions: ['.ts', '.js'] |
| 31 | + }, |
| 32 | + module: { |
| 33 | + rules: [{ |
| 34 | + test: /\.ts$/, |
| 35 | + loader: 'tslint-loader', |
| 36 | + exclude: /node_modules/, |
| 37 | + enforce: 'pre', |
| 38 | + options: { |
| 39 | + emitErrors: config.singleRun, |
| 40 | + failOnHint: config.singleRun |
| 41 | + } |
| 42 | + }, { |
| 43 | + test: /\.ts$/, |
| 44 | + loader: 'ts-loader', |
| 45 | + exclude: /node_modules/, |
| 46 | + options: { |
| 47 | + transpileOnly: !config.singleRun |
| 48 | + } |
| 49 | + }, { |
| 50 | + test: /src(\\|\/).+\.ts$/, |
| 51 | + exclude: /(node_modules|\.spec\.ts$)/, |
| 52 | + loader: 'istanbul-instrumenter-loader', |
| 53 | + enforce: 'post' |
| 54 | + }] |
| 55 | + }, |
| 56 | + plugins: [ |
| 57 | + new webpack.SourceMapDevToolPlugin({ |
| 58 | + filename: null, |
| 59 | + columns: false, |
| 60 | + test: /\.(ts|js)($|\?)/i |
| 61 | + }), |
| 62 | + new webpack.ContextReplacementPlugin( |
| 63 | + /angular(\\|\/)core(\\|\/)@angular/, |
| 64 | + path.join(__dirname, 'src') |
| 65 | + ), |
| 66 | + ...(config.singleRun ? [ |
| 67 | + new WebpackKarmaDieHardPlugin(), |
| 68 | + new webpack.NoEmitOnErrorsPlugin() |
| 69 | + ] : [ |
| 70 | + new ForkTsCheckerWebpackPlugin({ |
| 71 | + watch: ['./src', './test'], |
| 72 | + formatter: 'codeframe' |
| 73 | + }) |
| 74 | + ]) |
| 75 | + ] |
| 76 | + }, |
| 77 | + |
| 78 | + mochaReporter: { |
| 79 | + showDiff: true, |
| 80 | + output: 'autowatch' |
| 81 | + }, |
| 82 | + |
| 83 | + coverageIstanbulReporter: { |
| 84 | + reports: ['text-summary', 'html', 'lcovonly'], |
| 85 | + fixWebpackSourcePaths: true |
| 86 | + }, |
| 87 | + |
| 88 | + mime: { |
| 89 | + 'text/x-typescript': ['ts'] |
| 90 | + }, |
| 91 | + |
| 92 | + // test results reporter to use |
| 93 | + // possible values: 'dots', 'progress' |
| 94 | + // available reporters: https://npmjs.org/browse/keyword/karma-reporter |
| 95 | + reporters: ['mocha', 'coverage-istanbul'], |
| 96 | + |
| 97 | + // level of logging |
| 98 | + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG |
| 99 | + logLevel: config.LOG_INFO, |
| 100 | + |
| 101 | + // start these browsers |
| 102 | + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher |
| 103 | + browsers: ['ChromeHeadless'] |
| 104 | + |
| 105 | + }); |
| 106 | + |
| 107 | +}; |
0 commit comments