Skip to content

Commit 145f8eb

Browse files
edusperoniNathanWalker
authored andcommitted
feat: better API
1 parent 754388c commit 145f8eb

File tree

6 files changed

+797
-5509
lines changed

6 files changed

+797
-5509
lines changed

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ tscommand.tmp.txt
1111
.tscache/
1212
.vscode/
1313
*.ts
14+
!app/main.d.ts
1415
*.js.map
1516
definitions
1617
platforms/android/*

app/main.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface RunTestAppOptions {
2+
runTests?: () => unknown
3+
}
4+
5+
export function runTestApp(options?: RunTestAppOptions);

app/main.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ import { registerTestRunner } from "./services/webpack-test-runner";
88
const context = require.context('./', true, /.*\.(js|css|xml)/)
99
global.registerWebpackModules(context);
1010

11+
export interface RunTestAppOptions {
12+
runTests?: () => unknown
13+
}
1114

12-
export { registerTestRunner };
1315

14-
15-
export function runApp() {
16+
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+
}
1626
Application.run({ moduleName: "bundle-app-root" });
1727
}

nativescript.webpack.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function setupUnitTestBuild(config, env, webpack) {
110110
config.when(config.module.rules.has('ts'), (config) => config.module.rule('ts').uses.get('ts-loader').options(merge(config.module.rule('ts').uses.get('ts-loader').get('options'), { configFile: tsConfigPath })));
111111
config.when(config.plugins.has('AngularWebpackPlugin'), (config) => config.plugin('AngularWebpackPlugin').tap((args) => {
112112
args[0] = merge(args[0], { tsconfig: tsConfigPath });
113-
return args[0];
113+
return args;
114114
}));
115115
}
116116

@@ -122,24 +122,13 @@ function setupUnitTestBuild(config, env, webpack) {
122122
return args;
123123
});
124124

125-
const entryPath = webpack.Utils.virtualModules.addVirtualEntry(config, 'unit-test-runner', `
126-
// VIRTUAL ENTRY START
127-
const context = require.context(
128-
"~/",
129-
/* deep: */ true,
130-
/* filter: */ ${filesRegex}
131-
);
132-
global.registerWebpackModules(context);
133-
// VIRTUAL ENTRY END
134-
`);
135-
136125
// config.entryPoints.clear()
137126
config.entry('bundle')
138127
.clear()
139128
.add('@nativescript/core/globals/index.js')
140129
.add('@nativescript/core/bundle-entry-points')
141130
// .add('@nativescript/unit-test-runner/app/bundle-app')
142-
.add(require('fs').existsSync(testTsEntryPath) ? testTsEntryPath : testJsEntryPath)
131+
.add(require('fs').existsSync(testTsEntryPath) ? testTsEntryPath : testJsEntryPath);
143132
// .add('@nativescript/unit-test-runner/app/entry')
144133
// .add(entryPath);
145134
if (webpack.Utils.platform.getPlatformName() === 'android') {

0 commit comments

Comments
 (0)