|
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 projectFilesExtension = 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 === projectFilesExtension); |
| 44 | + |
41 | 45 | for (const mod of modulesToInstall) {
|
42 | 46 | let moduleToInstall = mod.name;
|
43 | 47 | moduleToInstall += `@${mod.version}`;
|
@@ -96,16 +100,16 @@ 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)}/**/*${projectFilesExtension}'`; |
100 | 104 | const karmaConfTemplate = this.$resources.readText('test/karma.conf.js');
|
101 | 105 | const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles });
|
102 | 106 |
|
103 | 107 | this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf);
|
104 | 108 |
|
105 |
| - const exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}.js`); |
| 109 | + const exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}${projectFilesExtension}`); |
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${projectFilesExtension}`)); |
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