This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathunit-testing-config-loader.js
46 lines (40 loc) · 1.89 KB
/
unit-testing-config-loader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const { join, relative } = require("path");
const { existsSync } = require("fs");
const { convertSlashesInPath } = require("./projectHelpers");
function getRunnerFullPath(projectRoot) {
const runnerRootPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner");
const runnerAppPath = join(runnerRootPath, "app");
const result = existsSync(runnerAppPath) ? runnerAppPath : runnerRootPath;
return result;
}
module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) {
// TODO: Consider to use the files property from karma.conf.js
const testFilesRegExp = /tests\/.*\.(ts|js)/;
const runnerFullPath = getRunnerFullPath(projectRoot);
const runnerRelativePath = convertSlashesInPath(relative(appFullPath, runnerFullPath));
const appCssFilePath = convertSlashesInPath(join(runnerRelativePath, "app.css"));
let source = `
require("tns-core-modules/bundle-entry-points");
const runnerContext = require.context("${runnerRelativePath}", true, ${rootPagesRegExp});
global.registerWebpackModules(runnerContext);
global.registerModule("${appCssFilePath}", () => require("${appCssFilePath}"));
require("tns-core-modules/application").setCssFileName("${appCssFilePath}");
`;
if (angular) {
source += `
const context = require.context("~/", true, ${testFilesRegExp});
global.registerWebpackModules(context);
`;
} else {
const registerModules = new RegExp(`(${rootPagesRegExp.source})|(${testFilesRegExp.source})`);
source += `
const context = require.context("~/", true, ${registerModules});
global.registerWebpackModules(context);
`;
}
const runnerEntryPointPath = convertSlashesInPath(join(runnerRelativePath, "bundle-app.js"));
source += `
require("${runnerEntryPointPath}");
`;
return source;
}