Skip to content

fix: Trying to run unit test fails with latest karma #3698

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 1 commit into from
Jun 22, 2018
Merged
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
34 changes: 29 additions & 5 deletions lib/commands/test-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ class TestInitCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];

private frameworkDependencies: IDictionary<string[]> = {
mocha: ['chai'],
mocha: ['karma-chai', 'mocha'],
};

private karmaConfigAdditionalFrameworks: IDictionary<string[]> = {
mocha: ['chai']
};

constructor(private $npm: INodePackageManager,
Expand All @@ -30,19 +34,38 @@ class TestInitCommand implements ICommand {
}

const dependencies = this.frameworkDependencies[frameworkToInstall] || [];
const modulesToInstall = ['karma', 'karma-' + frameworkToInstall, 'karma-nativescript-launcher'].concat(dependencies.map(f => 'karma-' + f));
const modulesToInstall: IDependencyInformation[] = [
{
name: 'karma',
// Hardcode the version unitl https://github.com/karma-runner/karma/issues/3052 is fixed
version: "2.0.2"
},
{
name: `karma-${frameworkToInstall}`
},
{
name: 'karma-nativescript-launcher'
}
];

modulesToInstall.push(...dependencies.map(f => ({ name: f })));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be {name: 'karma-' + f }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


for (const mod of modulesToInstall) {
await this.$npm.install(mod, projectDir, {
let moduleToInstall = mod.name;
if (mod.version) {
moduleToInstall += `@${mod.version}`;
}
await this.$npm.install(moduleToInstall, projectDir, {
'save-dev': true,
'save-exact': true,
optional: false,
disableNpmInstall: this.$options.disableNpmInstall,
frameworkPath: this.$options.frameworkPath,
ignoreScripts: this.$options.ignoreScripts,
path: this.$options.path
});

const modulePath = path.join(projectDir, "node_modules", mod);
const modulePath = path.join(projectDir, "node_modules", mod.name);
const modulePackageJsonPath = path.join(modulePath, "package.json");
const modulePackageJsonContent = this.$fs.readJson(modulePackageJsonPath);
const modulePeerDependencies = modulePackageJsonContent.peerDependencies || {};
Expand All @@ -55,6 +78,7 @@ class TestInitCommand implements ICommand {
try {
await this.$npm.install(`${peerDependency}@${dependencyVersion}`, projectDir, {
'save-dev': true,
'save-exact': true,
disableNpmInstall: false,
frameworkPath: this.$options.frameworkPath,
ignoreScripts: this.$options.ignoreScripts,
Expand All @@ -79,7 +103,7 @@ class TestInitCommand implements ICommand {

const karmaConfTemplate = this.$resources.readText('test/karma.conf.js');
const karmaConf = _.template(karmaConfTemplate)({
frameworks: [frameworkToInstall].concat(dependencies)
frameworks: [frameworkToInstall].concat(this.karmaConfigAdditionalFrameworks[frameworkToInstall])
.map(fw => `'${fw}'`)
.join(', ')
});
Expand Down