UNPKG

1.38 kBJavaScriptView Raw
1const { join, relative } = require("path");
2const { convertSlashesInPath } = require("./projectHelpers");
3
4module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) {
5 // TODO: Consider to use the files property from karma.conf.js
6 const testFilesRegExp = /tests\/.*\.(ts|js)/;
7 const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner");
8 const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath));
9 let source = `
10 require("tns-core-modules/bundle-entry-points");
11 const runnerContext = require.context("${runnerRelativePath}", true, ${rootPagesRegExp});
12 global.registerWebpackModules(runnerContext);
13 `;
14
15 if (angular) {
16 source += `
17 const context = require.context("~/", true, ${testFilesRegExp});
18 global.registerWebpackModules(context);
19 `;
20 } else {
21 const registerModules = new RegExp(`(${rootPagesRegExp.source})|(${testFilesRegExp.source})`);
22 source += `
23 const context = require.context("~/", true, ${registerModules});
24 global.registerWebpackModules(context);
25 `;
26 }
27
28 const runnerEntryPointPath = convertSlashesInPath(join(runnerRelativePath, "bundle-app.js"));
29 source += `
30 require("${runnerEntryPointPath}");
31 `;
32
33 return source;
34}
\No newline at end of file