Skip to content

Commit 7a8efea

Browse files
edusperoniNathanWalker
authored andcommitted
chore: cleanup
1 parent c672f88 commit 7a8efea

File tree

5 files changed

+17
-4565
lines changed

5 files changed

+17
-4565
lines changed

app/main-view-model.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,11 @@ export class TestBrokerViewModel extends Observable {
127127
const errors = this.testExecutionService.runTests(scripts);
128128
errors.forEach(err => this.error(err.msg, err.url, err.line));
129129

130-
executeWebpackTests();
130+
try {
131+
executeWebpackTests();
132+
} catch (e) {
133+
this.error(e.message);
134+
}
131135

132136
if (!this.hasError) {
133137
console.log('NSUTR: beginning test run');

app/main.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1-
21
declare let require: any;
32

43
import { Application } from "@nativescript/core";
5-
import "./app.css"
4+
import "./app.css";
65
import { registerTestRunner } from "./services/webpack-test-runner";
76

8-
const context = require.context('./', true, /.*\.(js|css|xml)/)
7+
const context = require.context("./", true, /.*\.(js|css|xml)/);
98
global.registerWebpackModules(context);
109

1110
export interface RunTestAppOptions {
12-
runTests?: () => unknown
11+
runTests?: () => unknown;
1312
}
1413

15-
1614
export function runTestApp(options: RunTestAppOptions = {}) {
17-
if(options?.runTests) {
18-
registerTestRunner(() => {
19-
try {
20-
options.runTests();
21-
} catch (e) {
22-
console.error('Error loading tests', e);
23-
}
24-
});
25-
}
26-
Application.run({ moduleName: "bundle-app-root" });
27-
}
15+
if (options?.runTests) {
16+
registerTestRunner(() => {
17+
options.runTests();
18+
});
19+
}
20+
Application.run({ moduleName: "bundle-app-root" });
21+
}

nativescript.webpack.js

-67
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,18 @@
11
const { join, dirname } = require('path');
22
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-
}
183

194
/**
205
* @param {typeof import("@nativescript/webpack")} webpack
216
*/
227
module.exports = webpack => {
238
webpack.chainWebpack((config, env) => {
24-
if (env.karmaWebpack) {
25-
return setupKarmaBuild(config, env, webpack);
26-
}
279

2810
if (env.unitTesting) {
2911
return setupUnitTestBuild(config, env, webpack);
3012
}
3113
});
3214
};
3315

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-
8316
/**
8417
* @param {import("webpack-chain")} config
8518
* @param {typeof import("@nativescript/webpack")} webpack

0 commit comments

Comments
 (0)