Skip to content

Commit 3027ca2

Browse files
committed
fix: test init and karma conf
1 parent 0d1b15c commit 3027ca2

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

lib/commands/test-init.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,18 @@ class TestInitCommand implements ICommand {
135135
);
136136

137137
const testsDir = path.join(this.$projectData.appDirectoryPath, "tests");
138-
const relativeTestsDir = path.relative(
138+
const projectTestsDir = path.relative(
139139
this.$projectData.projectDir,
140140
testsDir
141141
);
142+
const relativeTestsDir = path.relative(
143+
this.$projectData.appDirectoryPath,
144+
testsDir
145+
);
142146
let shouldCreateSampleTests = true;
143147
if (this.$fs.exists(testsDir)) {
144148
this.$logger.info(
145-
`${relativeTestsDir} directory already exists, will not create an example test project.`
149+
`${projectTestsDir} directory already exists, will not create an example test project.`
146150
);
147151
shouldCreateSampleTests = false;
148152
}
@@ -157,7 +161,11 @@ class TestInitCommand implements ICommand {
157161
relativeTestsDir
158162
)}/**/*${projectFilesExtension}'`;
159163
const karmaConfTemplate = this.$resources.readText("test/karma.conf.js");
160-
const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles });
164+
const karmaConf = _.template(karmaConfTemplate)({
165+
frameworks,
166+
testFiles,
167+
basePath: this.$projectData.getAppDirectoryRelativePath(),
168+
});
161169

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

@@ -171,11 +179,11 @@ class TestInitCommand implements ICommand {
171179
path.join(testsDir, `example${projectFilesExtension}`)
172180
);
173181
this.$logger.info(
174-
`\nExample test file created in ${relativeTestsDir}`.yellow
182+
`\nExample test file created in ${projectTestsDir}`.yellow
175183
);
176184
} else {
177185
this.$logger.info(
178-
`\nPlace your test files under ${relativeTestsDir}`.yellow
186+
`\nPlace your test files under ${projectTestsDir}`.yellow
179187
);
180188
}
181189

lib/controllers/migrate-controller.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ export class MigrateController
238238
},
239239
{
240240
packageName: "@nativescript/unit-test-runner",
241-
minVersion: "1.0.0",
241+
minVersion: "2.0.0",
242242
async shouldMigrateAction(
243243
dependency: IMigrationDependency,
244244
projectData: IProjectData,

resources/test/karma.conf.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
const filePatterns = [${ testFiles }];
12
module.exports = function (config) {
23
const options = {
34

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

78

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

1213

1314
// list of files / patterns to load in the browser
14-
files: [${ testFiles }],
15+
files: filePatterns,
1516

1617

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

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

8286
function setWebpackPreprocessor(config, options) {
8387
if (config && config.bundle) {
@@ -100,6 +104,7 @@ function setWebpack(config, options) {
100104
env[config.platform] = true;
101105
env.sourceMap = config.debugBrk;
102106
env.appPath = config.appPath;
107+
env.karmaWebpack = true;
103108
options.webpack = require('./webpack.config')(env);
104109
delete options.webpack.entry;
105110
delete options.webpack.output.libraryTarget;

0 commit comments

Comments
 (0)