Skip to content

Commit 5262184

Browse files
Merge pull request #4811 from NativeScript/vladimirov/fix-migrate-unit-test
fix: migrate fails when karma.config.js is missing
2 parents b954d31 + b29248e commit 5262184

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/controllers/migrate-controller.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -286,23 +286,26 @@ export class MigrateController extends UpdateControllerBase implements IMigrateC
286286

287287
private async migrateUnitTestRunner(projectData: IProjectData, migrationBackupDirPath: string): Promise<IMigrationDependency[]> {
288288
// Migrate karma.conf.js
289-
const oldKarmaContent = this.$fs.readText(path.join(migrationBackupDirPath, constants.KARMA_CONFIG_NAME));
289+
const pathToKarmaConfig = path.join(migrationBackupDirPath, constants.KARMA_CONFIG_NAME);
290+
if (this.$fs.exists(pathToKarmaConfig)) {
291+
const oldKarmaContent = this.$fs.readText(pathToKarmaConfig);
290292

291-
const regExp = /frameworks:\s+\[([\S\s]*?)\]/g;
292-
const matches = regExp.exec(oldKarmaContent);
293-
const frameworks = (matches && matches[1] && matches[1].trim()) || '["jasmine"]';
293+
const regExp = /frameworks:\s+\[([\S\s]*?)\]/g;
294+
const matches = regExp.exec(oldKarmaContent);
295+
const frameworks = (matches && matches[1] && matches[1].trim()) || '["jasmine"]';
294296

295-
const testsDir = path.join(projectData.appDirectoryPath, 'tests');
296-
const relativeTestsDir = path.relative(projectData.projectDir, testsDir);
297-
const testFiles = `'${fromWindowsRelativePathToUnix(relativeTestsDir)}/**/*.*'`;
297+
const testsDir = path.join(projectData.appDirectoryPath, 'tests');
298+
const relativeTestsDir = path.relative(projectData.projectDir, testsDir);
299+
const testFiles = `'${fromWindowsRelativePathToUnix(relativeTestsDir)}/**/*.*'`;
298300

299-
const karmaConfTemplate = this.$resources.readText('test/karma.conf.js');
300-
const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles });
301-
this.$fs.writeFile(path.join(projectData.projectDir, constants.KARMA_CONFIG_NAME), karmaConf);
301+
const karmaConfTemplate = this.$resources.readText('test/karma.conf.js');
302+
const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles });
303+
this.$fs.writeFile(path.join(projectData.projectDir, constants.KARMA_CONFIG_NAME), karmaConf);
304+
}
302305

303306
// Dependencies to migrate
304307
const dependencies = [
305-
{ packageName: "karma-webpack", verifiedVersion: "3.0.5", isDev: true, shouldAddIfMissing: !this.hasDependency({ packageName: "karma-webpack", isDev: true }, projectData) },
308+
{ packageName: "karma-webpack", verifiedVersion: "3.0.5", isDev: true, shouldAddIfMissing: true },
306309
{ packageName: "karma-jasmine", verifiedVersion: "2.0.1", isDev: true },
307310
{ packageName: "karma-mocha", verifiedVersion: "1.3.0", isDev: true },
308311
{ packageName: "karma-chai", verifiedVersion: "0.1.0", isDev: true },

0 commit comments

Comments
 (0)