1
1
import * as path from 'path' ;
2
- import { TESTING_FRAMEWORKS } from '../constants' ;
2
+ import { TESTING_FRAMEWORKS , ProjectTypes } from '../constants' ;
3
3
import { fromWindowsRelativePathToUnix } from '../common/helpers' ;
4
4
5
5
class TestInitCommand implements ICommand {
@@ -31,13 +31,17 @@ class TestInitCommand implements ICommand {
31
31
this . $errors . fail ( `Unknown or unsupported unit testing framework: ${ frameworkToInstall } ` ) ;
32
32
}
33
33
34
+ const projectType = this . $projectData . projectType === ProjectTypes . TsFlavorName || this . $projectData . projectType === ProjectTypes . NgFlavorName ? ".ts" : ".js" ;
35
+
34
36
let modulesToInstall : IDependencyInformation [ ] = [ ] ;
35
37
try {
36
38
modulesToInstall = this . $testInitializationService . getDependencies ( frameworkToInstall ) ;
37
39
} catch ( err ) {
38
40
this . $errors . failWithoutHelp ( `Unable to install the unit testing dependencies. Error: '${ err . message } '` ) ;
39
41
}
40
42
43
+ modulesToInstall = modulesToInstall . filter ( moduleToInstall => ! moduleToInstall . projectType || moduleToInstall . projectType === projectType ) ;
44
+
41
45
for ( const mod of modulesToInstall ) {
42
46
let moduleToInstall = mod . name ;
43
47
moduleToInstall += `@${ mod . version } ` ;
@@ -96,7 +100,7 @@ class TestInitCommand implements ICommand {
96
100
const frameworks = [ frameworkToInstall ] . concat ( this . karmaConfigAdditionalFrameworks [ frameworkToInstall ] || [ ] )
97
101
. map ( fw => `'${ fw } '` )
98
102
. join ( ', ' ) ;
99
- const testFiles = `'${ fromWindowsRelativePathToUnix ( relativeTestsDir ) } /**/*.js '` ;
103
+ const testFiles = `'${ fromWindowsRelativePathToUnix ( relativeTestsDir ) } /**/*${ projectType } '` ;
100
104
const karmaConfTemplate = this . $resources . readText ( 'test/karma.conf.js' ) ;
101
105
const karmaConf = _ . template ( karmaConfTemplate ) ( { frameworks, testFiles } ) ;
102
106
@@ -105,7 +109,7 @@ class TestInitCommand implements ICommand {
105
109
const exampleFilePath = this . $resources . resolvePath ( `test/example.${ frameworkToInstall } .js` ) ;
106
110
107
111
if ( shouldCreateSampleTests && this . $fs . exists ( exampleFilePath ) ) {
108
- this . $fs . copyFile ( exampleFilePath , path . join ( testsDir , ' example.js' ) ) ;
112
+ this . $fs . copyFile ( exampleFilePath , path . join ( testsDir , ` example${ projectType } ` ) ) ;
109
113
this . $logger . info ( `\nExample test file created in ${ relativeTestsDir } ` . yellow ) ;
110
114
} else {
111
115
this . $logger . info ( `\nPlace your test files under ${ relativeTestsDir } ` . yellow ) ;
0 commit comments