Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: test init and karma conf
  • Loading branch information
NathanWalker committed May 11, 2021
commit 3027ca2ced90f4e039ced12df2f5a67fd7538d3b
18 changes: 13 additions & 5 deletions lib/commands/test-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,18 @@ class TestInitCommand implements ICommand {
);

const testsDir = path.join(this.$projectData.appDirectoryPath, "tests");
const relativeTestsDir = path.relative(
const projectTestsDir = path.relative(
this.$projectData.projectDir,
testsDir
);
const relativeTestsDir = path.relative(
this.$projectData.appDirectoryPath,
testsDir
);
let shouldCreateSampleTests = true;
if (this.$fs.exists(testsDir)) {
this.$logger.info(
`${relativeTestsDir} directory already exists, will not create an example test project.`
`${projectTestsDir} directory already exists, will not create an example test project.`
);
shouldCreateSampleTests = false;
}
Expand All @@ -157,7 +161,11 @@ class TestInitCommand implements ICommand {
relativeTestsDir
)}/**/*${projectFilesExtension}'`;
const karmaConfTemplate = this.$resources.readText("test/karma.conf.js");
const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles });
const karmaConf = _.template(karmaConfTemplate)({
frameworks,
testFiles,
basePath: this.$projectData.getAppDirectoryRelativePath(),
});

this.$fs.writeFile(path.join(projectDir, "karma.conf.js"), karmaConf);

Expand All @@ -171,11 +179,11 @@ class TestInitCommand implements ICommand {
path.join(testsDir, `example${projectFilesExtension}`)
);
this.$logger.info(
`\nExample test file created in ${relativeTestsDir}`.yellow
`\nExample test file created in ${projectTestsDir}`.yellow
);
} else {
this.$logger.info(
`\nPlace your test files under ${relativeTestsDir}`.yellow
`\nPlace your test files under ${projectTestsDir}`.yellow
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/migrate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class MigrateController
},
{
packageName: "@nativescript/unit-test-runner",
minVersion: "1.0.0",
minVersion: "2.0.0",
async shouldMigrateAction(
dependency: IMigrationDependency,
projectData: IProjectData,
Expand Down
9 changes: 7 additions & 2 deletions resources/test/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const filePatterns = [${ testFiles }];
module.exports = function (config) {
const options = {

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
basePath: '${ basePath }',


// frameworks to use
Expand All @@ -11,7 +12,7 @@ module.exports = function (config) {


// list of files / patterns to load in the browser
files: [${ testFiles }],
files: filePatterns,


// list of files to exclude
Expand Down Expand Up @@ -78,6 +79,9 @@ module.exports = function (config) {

config.set(options);
}
module.exports.filePatterns = filePatterns;
// You can also use RegEx if you'd like:
// module.exports.filesRegex = /\.\/tests\/.*\.ts$/;

function setWebpackPreprocessor(config, options) {
if (config && config.bundle) {
Expand All @@ -100,6 +104,7 @@ function setWebpack(config, options) {
env[config.platform] = true;
env.sourceMap = config.debugBrk;
env.appPath = config.appPath;
env.karmaWebpack = true;
options.webpack = require('./webpack.config')(env);
delete options.webpack.entry;
delete options.webpack.output.libraryTarget;
Expand Down