|
| 1 | +const argv = require('minimist')(process.argv.slice(2)); |
| 2 | +const components = argv.components !== true && argv.components; |
| 3 | +const runCoverage = typeof argv.coverage !== 'undefined'; |
| 4 | +const runFirefox = typeof argv.firefox !== 'undefined'; |
| 5 | +const runChrome = typeof argv.chrome !== 'undefined'; |
| 6 | + |
| 7 | +const rootPath = __dirname; |
| 8 | + |
| 9 | +module.exports = function (config) { |
| 10 | + const plugins = ['karma-webpack', 'karma-jasmine', 'karma-sourcemap-loader']; |
| 11 | + const launcher = []; |
| 12 | + |
| 13 | + if (runCoverage) { |
| 14 | + plugins.push('karma-coverage-istanbul-reporter'); |
| 15 | + } |
| 16 | + |
| 17 | + if (runChrome) { |
| 18 | + plugins.push('karma-chrome-launcher'); |
| 19 | + launcher.push('Chrome'); |
| 20 | + } |
| 21 | + |
| 22 | + if (runFirefox) { |
| 23 | + plugins.push('karma-firefox-launcher'); |
| 24 | + launcher.push('Firefox'); |
| 25 | + } |
| 26 | + |
| 27 | + const tsConfig = { |
| 28 | + compilerOptions: { |
| 29 | + rootDir: rootPath, |
| 30 | + declaration: false, |
| 31 | + strict: false, |
| 32 | + downlevelIteration: true, |
| 33 | + transpileOnly: true, // Faster compilation - skip type checking |
| 34 | + paths: { |
| 35 | + '*': ['*', rootPath + '/packages/*'], |
| 36 | + }, |
| 37 | + }, |
| 38 | + transpileOnly: true, // Enable faster transpilation |
| 39 | + }; |
| 40 | + |
| 41 | + const rules = runCoverage |
| 42 | + ? [ |
| 43 | + { |
| 44 | + test: /lib(\\|\/).*\.ts$/, |
| 45 | + use: [ |
| 46 | + { loader: '@jsdevtools/coverage-istanbul-loader' }, |
| 47 | + { |
| 48 | + loader: 'ts-loader', |
| 49 | + options: tsConfig, |
| 50 | + }, |
| 51 | + ], |
| 52 | + }, |
| 53 | + { |
| 54 | + test: /test(\\|\/).*\.ts$/, |
| 55 | + loader: 'ts-loader', |
| 56 | + options: tsConfig, |
| 57 | + }, |
| 58 | + ] |
| 59 | + : [ |
| 60 | + { |
| 61 | + test: /\.ts$/, |
| 62 | + loader: 'ts-loader', |
| 63 | + options: tsConfig, |
| 64 | + }, |
| 65 | + ]; |
| 66 | + |
| 67 | + const settings = { |
| 68 | + basePath: '.', |
| 69 | + plugins, |
| 70 | + client: { |
| 71 | + components: components, |
| 72 | + clearContext: false, |
| 73 | + captureConsole: true, |
| 74 | + }, |
| 75 | + browsers: launcher, |
| 76 | + files: ['tools/karma.test.all.js'], |
| 77 | + frameworks: ['jasmine'], |
| 78 | + preprocessors: { |
| 79 | + 'tools/karma.test.all.js': ['webpack', 'sourcemap'], |
| 80 | + }, |
| 81 | + port: 9876, |
| 82 | + colors: true, |
| 83 | + logLevel: config.LOG_INFO, |
| 84 | + autoWatch: true, |
| 85 | + autoWatchBatchDelay: 300, // Batch file changes for better performance |
| 86 | + |
| 87 | + // to avoid DISCONNECTED messages |
| 88 | + browserDisconnectTimeout: 10000, // default 2000 |
| 89 | + browserDisconnectTolerance: 1, // default 0 |
| 90 | + browserNoActivityTimeout: 60000, //default 10000 |
| 91 | + browserConsoleLogOptions: { |
| 92 | + level: 'log', |
| 93 | + format: '%b %T: %m', |
| 94 | + terminal: true, |
| 95 | + }, |
| 96 | + |
| 97 | + singleRun: true, |
| 98 | + captureTimeout: 60000, |
| 99 | + |
| 100 | + webpack: { |
| 101 | + mode: 'development', |
| 102 | + devtool: 'eval-source-map', // Faster than inline-source-map |
| 103 | + module: { |
| 104 | + rules, |
| 105 | + }, |
| 106 | + resolve: { |
| 107 | + extensions: ['.ts', '.tsx', '.js'], |
| 108 | + modules: ['./packages', './node_modules'], |
| 109 | + }, |
| 110 | + // Workaround karma-webpack issue https://github.com/ryanclark/karma-webpack/issues/493 |
| 111 | + // Got this solution from https://github.com/ryanclark/karma-webpack/issues/493#issuecomment-780411348 |
| 112 | + optimization: { |
| 113 | + splitChunks: false, |
| 114 | + removeAvailableModules: false, // Performance optimization |
| 115 | + removeEmptyChunks: false, // Performance optimization |
| 116 | + }, |
| 117 | + // Add filesystem caching for better performance |
| 118 | + cache: { |
| 119 | + type: 'filesystem', |
| 120 | + cacheDirectory: require('path').join(rootPath, 'node_modules/.cache/webpack'), |
| 121 | + }, |
| 122 | + stats: 'errors-warnings', // Reduce console output |
| 123 | + }, |
| 124 | + |
| 125 | + // Concurrency level |
| 126 | + // how many browser should be started simultaneous |
| 127 | + concurrency: Infinity, |
| 128 | + }; |
| 129 | + |
| 130 | + if (runCoverage) { |
| 131 | + settings.reporters = ['coverage-istanbul']; |
| 132 | + settings.coverageIstanbulReporter = { |
| 133 | + reports: ['html', 'lcovonly', 'text-summary'], |
| 134 | + dir: './dist/deploy/coverage', |
| 135 | + }; |
| 136 | + } |
| 137 | + |
| 138 | + config.set(settings); |
| 139 | +}; |
0 commit comments