@@ -5,10 +5,6 @@ import { fromWindowsRelativePathToUnix } from '../common/helpers';
5
5
class TestInitCommand implements ICommand {
6
6
public allowedParameters : ICommandParameter [ ] = [ ] ;
7
7
8
- private frameworkDependencies : IDictionary < string [ ] > = {
9
- mocha : [ 'karma-chai' , 'mocha' ] ,
10
- } ;
11
-
12
8
private karmaConfigAdditionalFrameworks : IDictionary < string [ ] > = {
13
9
mocha : [ 'chai' ]
14
10
} ;
@@ -21,7 +17,8 @@ class TestInitCommand implements ICommand {
21
17
private $fs : IFileSystem ,
22
18
private $resources : IResourceLoader ,
23
19
private $pluginsService : IPluginsService ,
24
- private $logger : ILogger ) {
20
+ private $logger : ILogger ,
21
+ private $testInitializationService : ITestInitializationService ) {
25
22
this . $projectData . initializeProjectData ( ) ;
26
23
}
27
24
@@ -34,28 +31,25 @@ class TestInitCommand implements ICommand {
34
31
this . $errors . fail ( `Unknown or unsupported unit testing framework: ${ frameworkToInstall } ` ) ;
35
32
}
36
33
37
- const dependencies = this . frameworkDependencies [ frameworkToInstall ] || [ ] ;
38
- const modulesToInstall : IDependencyInformation [ ] = [
39
- {
40
- name : 'karma' ,
41
- // Hardcode the version unitl https://github.com/karma-runner/karma/issues/3052 is fixed
42
- version : "2.0.2"
43
- } ,
44
- {
45
- name : `karma-${ frameworkToInstall } `
46
- } ,
47
- {
48
- name : 'karma-nativescript-launcher'
49
- }
50
- ] ;
34
+ let modulesToInstall : IDependencyInformation [ ] = [ ] ;
35
+ try {
36
+ const dependencies = this . $testInitializationService . getDependencies ( frameworkToInstall ) ;
37
+ const dependenciesVersions = this . $testInitializationService . getDependenciesVersions ( ) ;
38
+ modulesToInstall = dependencies . map ( dependency => {
39
+ const dependencyVersion = dependenciesVersions [ dependency ] ;
40
+ if ( ! dependencyVersion ) {
41
+ this . $errors . failWithoutHelp ( `'${ dependency } ' is not a registered dependency.` ) ;
42
+ }
51
43
52
- modulesToInstall . push ( ...dependencies . map ( f => ( { name : f } ) ) ) ;
44
+ return { name : dependency , version : dependencyVersion } ;
45
+ } ) ;
46
+ } catch ( err ) {
47
+ this . $errors . failWithoutHelp ( `Unable to install the unit testing dependencies. Error: '${ err . message } '` ) ;
48
+ }
53
49
54
50
for ( const mod of modulesToInstall ) {
55
51
let moduleToInstall = mod . name ;
56
- if ( mod . version ) {
57
- moduleToInstall += `@${ mod . version } ` ;
58
- }
52
+ moduleToInstall += `@${ mod . version } ` ;
59
53
await this . $packageManager . install ( moduleToInstall , projectDir , {
60
54
'save-dev' : true ,
61
55
'save-exact' : true ,
0 commit comments