I have multiple classes located in
root/app/providers/engine/engine.ts
. In my test specification file spec/engine/engine-spec.ts
(the spec/
directory is also where the jasmine support/
resides), I have a simple test:
///<reference path="../../typings/globals/jasmine/index.d.ts"/>
// The typings reference does exist
import {ClassA, ClassB, ClassC, ClassD, ClassE, EnumThing} from '../../app/providers/engine/engine';
describe('In the classes,', () => {
describe('ClassA', () => {
it('exists', () => {
expect(new ClassA()).toBeDefined();
});
});
});
In my gulpfile
, I've configured the test
task to compile this code using tsc
and then run jasmine
. However, when executing the above example, Jasmine cannot find any specifications and terminates. The output file generated by tsc
looks like this:
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
///<reference path="../../../typings/globals/lodash/index.d.ts"/>
///<reference path="../../../typings/globals/chance/index.d.ts"/>
// }}}
///<reference path="../../typings/globals/jasmine/index.d.ts"/>
As shown, this section simply represents TypeScript's implementation of class extends
, leading to all specs disappearing!
If I remove the import statement and run a basic expect(true).toBe(true)
test, everything works fine - Jasmine identifies one spec and passes successfully. The resulting output.spec.js
appears as expected:
///<reference path="../../typings/globals/jasmine/index.d.ts"/>
describe('In the classes,', function () {
describe('ClassA', function () {
it('exists', function () {
expect(true).toBe(true);
});
});
});
Despite these observations, I'll share the gulp test
task here in case it may be causing the issue:
// At the top
var gulp = require('gulp');
var tsc = require('gulp-typescript');
var spawn = require('child_process').spawnSync;
// Few unrelated tasks later ...
gulp.task('test', function(done) {
var stream = gulp.src('spec/**/*.spec.ts')
.pipe(tsc({
out: 'output.spec.js',
target: 'es5'
}))
.pipe(gulp.dest('spec/'));
stream.on('end', function() {
spawn('jasmine', ['--color', 'spec/output.spec.js'], {
stdio: 'inherit'
})
done();
});
});
The problem seems to lie with tsc
itself, but I'm unsure how to resolve it.
Thank you in advance!