Skip to content

Commit 877cc3c

Browse files
edusperoniNathanWalker
authored andcommitted
feat: add --env.codeCoverage
1 parent 145f8eb commit 877cc3c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

nativescript.webpack.js

+23
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ function setupUnitTestBuild(config, env, webpack) {
102102
config.module.rule('css').include.add(runnerPath);
103103
config.module.rule('xml').include.add(runnerPath);
104104
config.module.rule('js').include.add(runnerPath);
105+
if (!env.testTsConfig && env.testTSConfig) {
106+
webpack.Utils.log.warn('Mapping env.testTSConfig to env.testTsConfig');
107+
}
108+
env.testTsConfig = env.testTsConfig || env.testTSConfig;
105109
const defaultTsConfig = webpack.Utils.project.getProjectFilePath('tsconfig.spec.json');
106110
const testTsEntryPath = join(webpack.Utils.platform.getEntryDirPath(), 'test.ts');
107111
const testJsEntryPath = join(webpack.Utils.platform.getEntryDirPath(), 'test.js');
@@ -122,6 +126,25 @@ function setupUnitTestBuild(config, env, webpack) {
122126
return args;
123127
});
124128

129+
if (env.codeCoverage) {
130+
config.module
131+
.rule('istanbul-loader')
132+
.enforce('post')
133+
.include
134+
.add(webpack.Utils.platform.getEntryDirPath())
135+
.end()
136+
.exclude
137+
.add(/\.spec\.(tsx?|jsx?)$/)
138+
.add(join(webpack.Utils.platform.getEntryDirPath(), 'tests'))
139+
.add(join(webpack.Utils.platform.getEntryDirPath(), 'test.ts'))
140+
.add(join(webpack.Utils.platform.getEntryDirPath(), 'test.js'))
141+
.end()
142+
.test(/\.(tsx?|jsx?)/)
143+
.use('@jsdevtools/coverage-istanbul-loader')
144+
.loader(require.resolve('@jsdevtools/coverage-istanbul-loader'))
145+
.options({ esModules: true });
146+
}
147+
125148
// config.entryPoints.clear()
126149
config.entry('bundle')
127150
.clear()

0 commit comments

Comments
 (0)