Skip to content

Commit

Permalink
Fix TS unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaspit committed May 31, 2018
1 parent b54f2a3 commit c0a0290
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 325 deletions.
94 changes: 80 additions & 14 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,91 @@ gulp.task('test-php-debug:watch', function () {
gulp.watch(phpPatterns, ['test-php-debug']);
});

function runKarmaTests(applicationName, cb, type) {
var config = {
configFile: __dirname + '/karma.conf.js',
applicationName: applicationName
};

switch (type) {
case 'ci':
config.reporters = 'teamcity';
break;

case 'watch':
config.autoWatch = true;
config.singleRun = false;
break;

case 'debug':
config.autoWatch = true;
config.singleRun = false;
config.browsers = [];
break;
}

new Server(config, function(err) {
if (err === 0) {
cb();
} else {
cb(new gutil.PluginError('karma', { message: 'Karma Tests failed' }));
}
}).start();
}

// -------------------------------------
// Task: test-ts
// -------------------------------------
gulp.task('test-ts', function (cb) {
var params = require('yargs')
.option('applicationName', {
demand: true,
type: 'string' })
.fail(yargFailure)
.argv;
runKarmaTests(params.applicationName, cb, 'ci');
});

// -------------------------------------
// Task: test-ts-lf
// -------------------------------------
gulp.task('test-ts-lf', function (cb) {
runKarmaTests('languageforge', cb);
});

// -------------------------------------
// Task: test-ts-lf:watch
// -------------------------------------
gulp.task('test-ts-lf:watch', function (cb) {
runKarmaTests('languageforge', cb, 'watch');
});

// -------------------------------------
// Task: test-ts-lf:debug
// -------------------------------------
gulp.task('test-ts-lf:debug', function (cb) {
runKarmaTests('languageforge', cb, 'debug');
});

// -------------------------------------
// Task: test-ts-sf
// -------------------------------------
gulp.task('test-ts-sf', function (cb) {
runKarmaTests('scriptureforge', cb);
});

// -------------------------------------
// Task: test-js
// Task: test-ts-sf:watch
// -------------------------------------
gulp.task('test-js', function (cb) {
new Server({
configFile: __dirname + '/test/app/karma.conf.js',
reporters: 'teamcity'
}, cb).start();
gulp.task('test-ts-sf:watch', function (cb) {
runKarmaTests('scriptureforge', cb, 'watch');
});

// -------------------------------------
// Task: test-js:watch
// Task: test-ts-sf:debug
// -------------------------------------
gulp.task('test-js:watch', function (cb) {
new Server({
configFile: __dirname + '/test/app/karma.conf.js',
autoWatch: true,
singleRun: false
}, cb).start();
gulp.task('test-ts-sf:debug', function (cb) {
runKarmaTests('scriptureforge', cb, 'debug');
});

// -------------------------------------
Expand Down Expand Up @@ -1396,7 +1462,7 @@ gulp.task('build-and-test',
'build',
'test-php',

// 'test-js',
'test-ts',
'test-dotnet',
'test-restart-webserver',
'local-restart-xforge-web-api',
Expand Down
50 changes: 50 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';
var getWebpackConfig = require('./webpack.config.js');

// Karma configuration
module.exports = function (config) {
if (config.applicationName == null) {
config.applicationName = 'languageforge';
}
var webpackConfig = getWebpackConfig({ applicationName: config.applicationName, isTest: true });
var main = webpackConfig.entry.main;
delete webpackConfig.entry;

config.set({
basePath: '.',
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [main],

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
[main]: ['webpack', 'sourcemap']
},

webpack: webpackConfig,

// test results reporter to use
// possible values: dots || progress || growl
reporters: ['progress'],

// web server port
port: 8080,

// cli runner port
runnerPort: 9100,

colors: true,
logLevel: config.LOG_WARN,
browsers: ['ChromiumHeadless'],
captureTimeout: 8000,
singleRun: true,
mime: {
'text/x-typescript': ['ts','tsx']
}
});
};
Loading

0 comments on commit c0a0290

Please sign in to comment.