|
1 | 1 | const { join, dirname } = require('path'); |
2 | 2 | const { merge } = require('webpack-merge'); |
3 | | -const globRegex = require('glob-regex'); |
4 | | - |
5 | | -function getKarmaTestsRegex(webpack) { |
6 | | - const karmaConfig = require(webpack.Utils.project.getProjectFilePath('karma.conf.js')); |
7 | | - let filesRegex = karmaConfig.filesRegex || |
8 | | - new RegExp((karmaConfig.filePatterns || []).map((glob) => |
9 | | - globRegex(`./${glob}`).source // all webpack require.context start with `./` and glob-regex adds ^ |
10 | | - ).join('|')); |
11 | | - |
12 | | - if (!filesRegex || !filesRegex.source) { |
13 | | - webpack.Utils.log.warn("Karma files regex not found, falling back to tests/**/*.ts"); |
14 | | - filesRegex = /tests\/.*\.ts/; |
15 | | - } |
16 | | - return filesRegex; |
17 | | -} |
18 | 3 |
|
19 | 4 | /** |
20 | 5 | * @param {typeof import("@nativescript/webpack")} webpack |
21 | 6 | */ |
22 | 7 | module.exports = webpack => { |
23 | 8 | webpack.chainWebpack((config, env) => { |
24 | | - if (env.karmaWebpack) { |
25 | | - return setupKarmaBuild(config, env, webpack); |
26 | | - } |
27 | 9 |
|
28 | 10 | if (env.unitTesting) { |
29 | 11 | return setupUnitTestBuild(config, env, webpack); |
30 | 12 | } |
31 | 13 | }); |
32 | 14 | }; |
33 | 15 |
|
34 | | -/** |
35 | | - * @param {import("webpack-chain")} config |
36 | | - * @param {typeof import("@nativescript/webpack")} webpack |
37 | | - */ |
38 | | -function setupKarmaBuild(config, env, webpack) { |
39 | | - const karmaWebpack = require('karma-webpack/lib/webpack/defaults'); |
40 | | - const defaults = karmaWebpack.create(); |
41 | | - delete defaults.optimization; |
42 | | - |
43 | | - karmaWebpack.create = () => { |
44 | | - return defaults; |
45 | | - }; |
46 | | - |
47 | | - config.entryPoints.clear(); |
48 | | - config.optimization.clear(); |
49 | | - |
50 | | - config.plugins.delete('WatchStatePlugin'); |
51 | | - config.plugins.delete('AngularCompilerPlugin'); |
52 | | - config.plugins.delete('AngularWebpackPlugin'); |
53 | | - config.module.rules.delete('angular'); |
54 | | - // config.plugins.delete('CleanWebpackPlugin') |
55 | | - config.plugin('DefinePlugin').tap((args) => { |
56 | | - args[0] = merge(args[0], { |
57 | | - __TEST_RUNNER_STAY_OPEN__: !!env.stayOpen, |
58 | | - }); |
59 | | - |
60 | | - return args; |
61 | | - }); |
62 | | - |
63 | | - |
64 | | - |
65 | | - config.output.delete('path'); // use temp path |
66 | | - config.output.set('iife', true); |
67 | | - config.output.set('libraryTarget', 'global'); |
68 | | - config.output.set('clean', true); |
69 | | - |
70 | | - config.module |
71 | | - .rule('unit-test') |
72 | | - .enforce('post') |
73 | | - .include.add(webpack.Utils.platform.getEntryDirPath()).end() |
74 | | - .test(/\.(ts|js)/) |
75 | | - .use('unit-test-loader') |
76 | | - .loader(join(__dirname, 'loaders', 'unit-test-loader')) |
77 | | - .options({ |
78 | | - appPath: webpack.Utils.platform.getEntryDirPath(), |
79 | | - platform: webpack.Utils.platform.getPlatformName() |
80 | | - }); |
81 | | -} |
82 | | - |
83 | 16 | /** |
84 | 17 | * @param {import("webpack-chain")} config |
85 | 18 | * @param {typeof import("@nativescript/webpack")} webpack |
|
0 commit comments