Skip to content

Commit 754388c

Browse files
edusperoniNathanWalker
authored andcommitted
chore: wip
1 parent 97eea37 commit 754388c

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

app/main-view-model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { KarmaHostResolver } from './services/karma-host-resolver';
44
import { KarmaFilesService } from './services/karma-files-service';
55
import { TestExecutionService } from './services/test-execution-service';
66
import { killProcess } from "./stop-process";
7+
import { executeWebpackTests } from "./services/webpack-test-runner";
78

89
declare var global: any;
910
declare const __TEST_RUNNER_STAY_OPEN__: boolean;
@@ -126,6 +127,8 @@ export class TestBrokerViewModel extends Observable {
126127
const errors = this.testExecutionService.runTests(scripts);
127128
errors.forEach(err => this.error(err.msg, err.url, err.line));
128129

130+
executeWebpackTests();
131+
129132
if (!this.hasError) {
130133
console.log('NSUTR: beginning test run');
131134
if (config.options.debugBrk) {

app/main.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
declare let require: any;
3+
4+
import { Application } from "@nativescript/core";
5+
import "./app.css"
6+
import { registerTestRunner } from "./services/webpack-test-runner";
7+
8+
const context = require.context('./', true, /.*\.(js|css|xml)/)
9+
global.registerWebpackModules(context);
10+
11+
12+
export { registerTestRunner };
13+
14+
15+
export function runApp() {
16+
Application.run({ moduleName: "bundle-app-root" });
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let runTests: () => unknown;
2+
3+
export function registerTestRunner(testRunner: () => unknown) {
4+
runTests = testRunner;
5+
}
6+
7+
8+
export function executeWebpackTests() {
9+
runTests?.();
10+
}

nativescript.webpack.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ 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-
const filesRegex = getKarmaTestsRegex(webpack);
105+
const defaultTsConfig = webpack.Utils.project.getProjectFilePath('tsconfig.spec.json');
106+
const testTsEntryPath = join(webpack.Utils.platform.getEntryDirPath(), 'test.ts');
107+
const testJsEntryPath = join(webpack.Utils.platform.getEntryDirPath(), 'test.js');
108+
const tsConfigPath = env.testTsConfig || (require('fs').existsSync(defaultTsConfig) ? defaultTsConfig : undefined);
109+
if (tsConfigPath) {
110+
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 })));
111+
config.when(config.plugins.has('AngularWebpackPlugin'), (config) => config.plugin('AngularWebpackPlugin').tap((args) => {
112+
args[0] = merge(args[0], { tsconfig: tsConfigPath });
113+
return args[0];
114+
}));
115+
}
106116

107117
config.plugin('DefinePlugin').tap((args) => {
108118
args[0] = merge(args[0], {
@@ -128,9 +138,10 @@ function setupUnitTestBuild(config, env, webpack) {
128138
.clear()
129139
.add('@nativescript/core/globals/index.js')
130140
.add('@nativescript/core/bundle-entry-points')
131-
.add('@nativescript/unit-test-runner/app/bundle-app')
141+
// .add('@nativescript/unit-test-runner/app/bundle-app')
142+
.add(require('fs').existsSync(testTsEntryPath) ? testTsEntryPath : testJsEntryPath)
132143
// .add('@nativescript/unit-test-runner/app/entry')
133-
.add(entryPath);
144+
// .add(entryPath);
134145
if (webpack.Utils.platform.getPlatformName() === 'android') {
135146
config.entry('bundle')
136147
.add('@nativescript/core/ui/frame')

0 commit comments

Comments
 (0)