ft-webplatform/aurelia_project/tasks/test.js
Martin Donnelly 76920442b1 init
2017-09-28 13:04:16 +01:00

88 lines
2.7 KiB
JavaScript

import gulp from 'gulp';
import gutil from 'gulp-util';
import jest from 'gulp-jest';
import {Server as Karma} from 'karma';
import {CLIOptions} from 'aurelia-cli';
function testUIInKarma(done) {
let karamConfig = {
configFile: __dirname + '/../../karma.conf.js'
};
if (CLIOptions.hasFlag('watch')) {
karamConfig.singleRun = false;
karamConfig.specReporter = {
showSpecTiming: true,
suppressSkipped: true,
suppressErrorSummary: false
};
}
let focusedTest = CLIOptions.getFlagValue('focused-test');
if (focusedTest) {
focusedTest = focusedTest.replace(/(.spec)?.js/g, '');
// use args to pass information to aurelia-karma
karamConfig.client = {
captureConsole: true,
args: ['focused-test', focusedTest]
};
// use turn on debugging
karamConfig.browserConsoleLogOptions = {
level: 'debug',
format: '%b %T: %m',
terminal: true
};
}
let browser = CLIOptions.getFlagValue('browser');
if (browser) {
karamConfig.browsers = [browser];
}
new Karma(karamConfig, done).start();
}
function testUIInJest() {
gutil.log('UI Tests do not in JEST: Due to JSDOM incompatibility with StageComponent');
gutil.log('UI Tests do not in JEST: Currently Expected to fail solved by COREWEB-1242');
let focusedTest = CLIOptions.getFlagValue('focused-test');
let jestConfig = {
config: require('../../test/jest/jest-ui.json')
};
if (focusedTest) {
focusedTest = focusedTest.replace(/(.spec)?.js/g, '');
jestConfig.config.testRegex = `(?!util|lib|value-converters|configuration)[\\\/\\\\].*${focusedTest}.*.spec.js$`;
}
return gulp.src('src').pipe(jest(jestConfig));
}
function testBusinessLogic() {
let focusedTest = CLIOptions.getFlagValue('focused-test');
let jestConfig = {
config: require('../../test/jest/jest-bl.json')
};
if (focusedTest) {
focusedTest = focusedTest.replace(/(.spec)?.js/g, '');
jestConfig.config.testRegex = `(util|lib|value-converters|configuration).*${focusedTest}.*.spec.js$`;
}
gutil.log('UI Tests do not in JEST: Due to JSDOM incompatibility with StageComponent');
return gulp.src('src').pipe(jest({
config: require('../../test/jest/jest-bl.json')
}));
}
export default function test(done) {
if (CLIOptions.hasFlag('bl')) {
return testBusinessLogic();
} else if (CLIOptions.hasFlag('ui-dual-run')) {
return gulp.series(
testUIInJest,
testUIInKarma
)(done);
} else if (CLIOptions.hasFlag('ui') || CLIOptions.hasFlag('ui-karma')) {
return testUIInKarma(done);
} else if (CLIOptions.hasFlag('ui-jest')) {
return testUIInJest();
}
return gulp.series(
testBusinessLogic,
testUIInKarma
)();
}