@@ -5,10 +5,6 @@ import { fromWindowsRelativePathToUnix } from '../common/helpers';
55class TestInitCommand implements ICommand {
66 public allowedParameters : ICommandParameter [ ] = [ ] ;
77
8- private frameworkDependencies : IDictionary < string [ ] > = {
9- mocha : [ 'karma-chai' , 'mocha' ] ,
10- } ;
11-
128 private karmaConfigAdditionalFrameworks : IDictionary < string [ ] > = {
139 mocha : [ 'chai' ]
1410 } ;
@@ -21,7 +17,8 @@ class TestInitCommand implements ICommand {
2117 private $fs : IFileSystem ,
2218 private $resources : IResourceLoader ,
2319 private $pluginsService : IPluginsService ,
24- private $logger : ILogger ) {
20+ private $logger : ILogger ,
21+ private $testInitializationService : ITestInitializationService ) {
2522 this . $projectData . initializeProjectData ( ) ;
2623 }
2724
@@ -34,28 +31,25 @@ class TestInitCommand implements ICommand {
3431 this . $errors . fail ( `Unknown or unsupported unit testing framework: ${ frameworkToInstall } ` ) ;
3532 }
3633
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+ }
5143
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+ }
5349
5450 for ( const mod of modulesToInstall ) {
5551 let moduleToInstall = mod . name ;
56- if ( mod . version ) {
57- moduleToInstall += `@${ mod . version } ` ;
58- }
52+ moduleToInstall += `@${ mod . version } ` ;
5953 await this . $packageManager . install ( moduleToInstall , projectDir , {
6054 'save-dev' : true ,
6155 'save-exact' : true ,
0 commit comments