Skip to content

Commit 03d68d6

Browse files
authored
fix: test init and karma conf for 8.0 with webpack5 (#5528)
1 parent f32773d commit 03d68d6

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ node_js:
1616
git:
1717
submodules: true
1818
install:
19-
- npm install --ignore-scripts
19+
- npm install --ignore-scripts --legacy-peer-deps
2020
before_script:
2121
- gem install xcodeproj
2222
- gem install cocoapods

config/test-dependencies.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
},
88
{
99
"name": "karma-webpack",
10-
"excludedPeerDependencies": ["webpack"],
11-
"version": "3.0.5"
10+
"excludedPeerDependencies": ["webpack"]
1211
},
1312
{
1413
"name": "mocha",

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,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"clean": "npx rimraf node_modules package-lock.json && npm run setup",
3333
"build": "grunt",
3434
"build.all": "grunt test",
35-
"setup": "npm i --ignore-scripts && npm rebuild husky",
35+
"setup": "npm i --ignore-scripts --legacy-peer-deps && npm rebuild husky",
3636
"test": "mocha --config=test/.mocharc.yml",
3737
"postinstall": "node postinstall.js",
3838
"preuninstall": "node preuninstall.js",

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)