This repository has been archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement unit testing with bundle (#835)
* feat: Implement unit testing with bundle NativeScript/nativescript-cli#4392 * chore: share the regex for `root|page` between bundle-config loader and unit-testing config loader
- Loading branch information
Fatme
authored
Mar 19, 2019
1 parent
36824b1
commit 7944611
Showing
6 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { join, relative } = require("path"); | ||
|
||
module.exports = function ({ appFullPath, projectRoot, angular, rootPagesRegExp }) { | ||
// TODO: Consider to use the files property from karma.conf.js | ||
const testFilesRegExp = /tests\/.*\.js/; | ||
const runnerFullPath = join(projectRoot, "node_modules", "nativescript-unit-test-runner"); | ||
const runnerRelativePath = relative(appFullPath, runnerFullPath); | ||
let source = ` | ||
require("tns-core-modules/bundle-entry-points"); | ||
const runnerContext = require.context("${runnerRelativePath}", true, ${rootPagesRegExp}); | ||
global.registerWebpackModules(runnerContext); | ||
`; | ||
|
||
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 = join(runnerRelativePath, "bundle-app.js"); | ||
source += ` | ||
require("${runnerEntryPointPath}"); | ||
`; | ||
|
||
return source; | ||
} |