Skip to content

fix: test init and karma conf for 8.0 with webpack5 #5528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ node_js:
git:
submodules: true
install:
- npm install --ignore-scripts
- npm install --ignore-scripts --legacy-peer-deps
before_script:
- gem install xcodeproj
- gem install cocoapods
Expand Down
3 changes: 1 addition & 2 deletions config/test-dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
},
{
"name": "karma-webpack",
"excludedPeerDependencies": ["webpack"],
"version": "3.0.5"
"excludedPeerDependencies": ["webpack"]
},
{
"name": "mocha",
Expand Down
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"clean": "npx rimraf node_modules package-lock.json && npm run setup",
"build": "grunt",
"build.all": "grunt test",
"setup": "npm i --ignore-scripts && npm rebuild husky",
"setup": "npm i --ignore-scripts --legacy-peer-deps && npm rebuild husky",
"test": "mocha --config=test/.mocharc.yml",
"postinstall": "node postinstall.js",
"preuninstall": "node preuninstall.js",
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