From 0d1b15c78e49391f43e6e9ecf16bfe662f5615fa Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 10 May 2021 14:45:16 -0700 Subject: [PATCH 1/3] fix: karma-webpack version to latest --- config/test-dependencies.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/test-dependencies.json b/config/test-dependencies.json index a1557d3bfe..879c04a950 100644 --- a/config/test-dependencies.json +++ b/config/test-dependencies.json @@ -7,8 +7,7 @@ }, { "name": "karma-webpack", - "excludedPeerDependencies": ["webpack"], - "version": "3.0.5" + "excludedPeerDependencies": ["webpack"] }, { "name": "mocha", From 3027ca2ced90f4e039ced12df2f5a67fd7538d3b Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 10 May 2021 21:50:23 -0700 Subject: [PATCH 2/3] fix: test init and karma conf --- lib/commands/test-init.ts | 18 +++++++++++++----- lib/controllers/migrate-controller.ts | 2 +- resources/test/karma.conf.js | 9 +++++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/commands/test-init.ts b/lib/commands/test-init.ts index 2e68c779cc..1417084122 100644 --- a/lib/commands/test-init.ts +++ b/lib/commands/test-init.ts @@ -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; } @@ -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); @@ -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 ); } diff --git a/lib/controllers/migrate-controller.ts b/lib/controllers/migrate-controller.ts index c296ce621a..b2ba60aa97 100644 --- a/lib/controllers/migrate-controller.ts +++ b/lib/controllers/migrate-controller.ts @@ -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, diff --git a/resources/test/karma.conf.js b/resources/test/karma.conf.js index 3b96bbbc9f..4238002584 100644 --- a/resources/test/karma.conf.js +++ b/resources/test/karma.conf.js @@ -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 @@ -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 @@ -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) { @@ -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; From b411bd979503ffec30d99039b8c8216f368f68a2 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 10 May 2021 21:51:14 -0700 Subject: [PATCH 3/3] chore: npm 7 handling --- .travis.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ecdd34f5d8..bb08d1a660 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package.json b/package.json index ae44546f41..e5a9db2469 100644 --- a/package.json +++ b/package.json @@ -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",