diff --git a/config/test-dependencies.json b/config/test-dependencies.json index 7a4868e2fb..879c04a950 100644 --- a/config/test-dependencies.json +++ b/config/test-dependencies.json @@ -28,5 +28,25 @@ { "name": "karma-qunit", "framework": "qunit" + }, + { + "name": "@types/karma-chai", + "framework": "mocha", + "projectType": ".ts" + }, + { + "name": "@types/mocha", + "framework": "mocha", + "projectType": ".ts" + }, + { + "name": "@types/jasmine", + "framework": "jasmine", + "projectType": ".ts" + }, + { + "name": "@types/qunit", + "framework": "qunit", + "projectType": ".ts" } ] \ No newline at end of file diff --git a/lib/commands/test-init.ts b/lib/commands/test-init.ts index 5a17fb42f8..fb0985fa65 100644 --- a/lib/commands/test-init.ts +++ b/lib/commands/test-init.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { TESTING_FRAMEWORKS } from '../constants'; +import { TESTING_FRAMEWORKS, ProjectTypes } from '../constants'; import { fromWindowsRelativePathToUnix } from '../common/helpers'; class TestInitCommand implements ICommand { @@ -31,6 +31,8 @@ class TestInitCommand implements ICommand { this.$errors.fail(`Unknown or unsupported unit testing framework: ${frameworkToInstall}`); } + const projectFilesExtension = this.$projectData.projectType === ProjectTypes.TsFlavorName || this.$projectData.projectType === ProjectTypes.NgFlavorName ? ".ts" : ".js"; + let modulesToInstall: IDependencyInformation[] = []; try { modulesToInstall = this.$testInitializationService.getDependencies(frameworkToInstall); @@ -38,6 +40,8 @@ class TestInitCommand implements ICommand { this.$errors.failWithoutHelp(`Unable to install the unit testing dependencies. Error: '${err.message}'`); } + modulesToInstall = modulesToInstall.filter(moduleToInstall => !moduleToInstall.projectType || moduleToInstall.projectType === projectFilesExtension); + for (const mod of modulesToInstall) { let moduleToInstall = mod.name; moduleToInstall += `@${mod.version}`; @@ -96,16 +100,16 @@ class TestInitCommand implements ICommand { const frameworks = [frameworkToInstall].concat(this.karmaConfigAdditionalFrameworks[frameworkToInstall] || []) .map(fw => `'${fw}'`) .join(', '); - const testFiles = `'${fromWindowsRelativePathToUnix(relativeTestsDir)}/**/*.js'`; + const testFiles = `'${fromWindowsRelativePathToUnix(relativeTestsDir)}/**/*${projectFilesExtension}'`; const karmaConfTemplate = this.$resources.readText('test/karma.conf.js'); const karmaConf = _.template(karmaConfTemplate)({ frameworks, testFiles }); this.$fs.writeFile(path.join(projectDir, 'karma.conf.js'), karmaConf); - const exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}.js`); + const exampleFilePath = this.$resources.resolvePath(`test/example.${frameworkToInstall}${projectFilesExtension}`); if (shouldCreateSampleTests && this.$fs.exists(exampleFilePath)) { - this.$fs.copyFile(exampleFilePath, path.join(testsDir, 'example.js')); + this.$fs.copyFile(exampleFilePath, path.join(testsDir, `example${projectFilesExtension}`)); this.$logger.info(`\nExample test file created in ${relativeTestsDir}`.yellow); } else { this.$logger.info(`\nPlace your test files under ${relativeTestsDir}`.yellow); diff --git a/lib/common/declarations.d.ts b/lib/common/declarations.d.ts index 5e096b0368..d07d3efd7e 100644 --- a/lib/common/declarations.d.ts +++ b/lib/common/declarations.d.ts @@ -1467,6 +1467,7 @@ interface IProcessService { interface IDependencyInformation { name: string; version?: string; + projectType?: string; excludedPeerDependencies?: string[]; } diff --git a/resources/test/example.jasmine.ts b/resources/test/example.jasmine.ts new file mode 100644 index 0000000000..c31134716f --- /dev/null +++ b/resources/test/example.jasmine.ts @@ -0,0 +1,6 @@ +// A sample Jasmine test +describe("A suite", function() { + it("contains spec with an expectation", function() { + expect(true).toBe(true); + }); +}); diff --git a/resources/test/example.mocha.ts b/resources/test/example.mocha.ts new file mode 100644 index 0000000000..a287a2eba2 --- /dev/null +++ b/resources/test/example.mocha.ts @@ -0,0 +1,9 @@ +// A sample Mocha test +describe('Array', function () { + describe('#indexOf()', function () { + it('should return -1 when the value is not present', function () { + assert.equal(-1, [1, 2, 3].indexOf(5)); + assert.equal(-1, [1, 2, 3].indexOf(0)); + }); + }); +}); diff --git a/resources/test/example.qunit.ts b/resources/test/example.qunit.ts new file mode 100644 index 0000000000..6933144e37 --- /dev/null +++ b/resources/test/example.qunit.ts @@ -0,0 +1,7 @@ +// A sample QUnit test +QUnit.test("equal test", function (assert) { + assert.equal( 0, 0, "Zero, Zero; equal succeeds" ); + assert.equal( "", 0, "Empty, Zero; equal succeeds" ); + assert.equal( "", "", "Empty, Empty; equal succeeds" ); + assert.equal( 0, false, "Zero, false; equal succeeds" ); +}); diff --git a/resources/test/karma.conf.js b/resources/test/karma.conf.js index 1cc877d6e4..918a6cee93 100644 --- a/resources/test/karma.conf.js +++ b/resources/test/karma.conf.js @@ -11,9 +11,7 @@ module.exports = function(config) { // list of files / patterns to load in the browser - files: [ - ${ testFiles } - ], + files: [ ${ testFiles } ], // list of files to exclude diff --git a/tsconfig.json b/tsconfig.json index d3eeb57049..3253e8f14e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "node_modules", "lib/common/node_modules", "scratch", - "coverage" + "coverage", + "resources/test" ] }