@@ -5,7 +5,11 @@ class TestInitCommand implements ICommand {
5
5
public allowedParameters : ICommandParameter [ ] = [ ] ;
6
6
7
7
private frameworkDependencies : IDictionary < string [ ] > = {
8
- mocha : [ 'chai' ] ,
8
+ mocha : [ 'karma-chai' , 'mocha' ] ,
9
+ } ;
10
+
11
+ private karmaConfigAdditionalFrameworks : IDictionary < string [ ] > = {
12
+ mocha : [ 'chai' ]
9
13
} ;
10
14
11
15
constructor ( private $npm : INodePackageManager ,
@@ -30,19 +34,38 @@ class TestInitCommand implements ICommand {
30
34
}
31
35
32
36
const dependencies = this . frameworkDependencies [ frameworkToInstall ] || [ ] ;
33
- const modulesToInstall = [ 'karma' , 'karma-' + frameworkToInstall , 'karma-nativescript-launcher' ] . concat ( dependencies . map ( f => 'karma-' + f ) ) ;
37
+ const modulesToInstall : IDependencyInformation [ ] = [
38
+ {
39
+ name : 'karma' ,
40
+ // Hardcode the version unitl https://github.com/karma-runner/karma/issues/3052 is fixed
41
+ version : "2.0.2"
42
+ } ,
43
+ {
44
+ name : `karma-${ frameworkToInstall } `
45
+ } ,
46
+ {
47
+ name : 'karma-nativescript-launcher'
48
+ }
49
+ ] ;
50
+
51
+ modulesToInstall . push ( ...dependencies . map ( f => ( { name : f } ) ) ) ;
34
52
35
53
for ( const mod of modulesToInstall ) {
36
- await this . $npm . install ( mod , projectDir , {
54
+ let moduleToInstall = mod . name ;
55
+ if ( mod . version ) {
56
+ moduleToInstall += `@${ mod . version } ` ;
57
+ }
58
+ await this . $npm . install ( moduleToInstall , projectDir , {
37
59
'save-dev' : true ,
60
+ 'save-exact' : true ,
38
61
optional : false ,
39
62
disableNpmInstall : this . $options . disableNpmInstall ,
40
63
frameworkPath : this . $options . frameworkPath ,
41
64
ignoreScripts : this . $options . ignoreScripts ,
42
65
path : this . $options . path
43
66
} ) ;
44
67
45
- const modulePath = path . join ( projectDir , "node_modules" , mod ) ;
68
+ const modulePath = path . join ( projectDir , "node_modules" , mod . name ) ;
46
69
const modulePackageJsonPath = path . join ( modulePath , "package.json" ) ;
47
70
const modulePackageJsonContent = this . $fs . readJson ( modulePackageJsonPath ) ;
48
71
const modulePeerDependencies = modulePackageJsonContent . peerDependencies || { } ;
@@ -55,6 +78,7 @@ class TestInitCommand implements ICommand {
55
78
try {
56
79
await this . $npm . install ( `${ peerDependency } @${ dependencyVersion } ` , projectDir , {
57
80
'save-dev' : true ,
81
+ 'save-exact' : true ,
58
82
disableNpmInstall : false ,
59
83
frameworkPath : this . $options . frameworkPath ,
60
84
ignoreScripts : this . $options . ignoreScripts ,
@@ -79,7 +103,7 @@ class TestInitCommand implements ICommand {
79
103
80
104
const karmaConfTemplate = this . $resources . readText ( 'test/karma.conf.js' ) ;
81
105
const karmaConf = _ . template ( karmaConfTemplate ) ( {
82
- frameworks : [ frameworkToInstall ] . concat ( dependencies )
106
+ frameworks : [ frameworkToInstall ] . concat ( this . karmaConfigAdditionalFrameworks [ frameworkToInstall ] )
83
107
. map ( fw => `'${ fw } '` )
84
108
. join ( ', ' )
85
109
} ) ;
0 commit comments