2018-05-01 13:40:35 -04:00
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const webpack = require('webpack');
|
|
|
|
const argumentsParser = require('commander');
|
|
|
|
const webpackConfig = require('./webpack.config.js');
|
|
|
|
|
|
|
|
const ROOT_PATH = path.resolve(__dirname, '..');
|
|
|
|
|
|
|
|
function fatalError(message) {
|
|
|
|
console.error(chalk.red(`\nError: ${message}\n`));
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2016-12-29 16:42:48 -05:00
|
|
|
|
2018-03-02 16:12:49 -05:00
|
|
|
// disable problematic options
|
|
|
|
webpackConfig.entry = undefined;
|
|
|
|
webpackConfig.mode = 'development';
|
|
|
|
webpackConfig.optimization.runtimeChunk = false;
|
|
|
|
webpackConfig.optimization.splitChunks = false;
|
|
|
|
|
|
|
|
// use quicker sourcemap option
|
|
|
|
webpackConfig.devtool = 'cheap-inline-source-map';
|
2017-03-02 17:35:36 -05:00
|
|
|
|
2018-05-01 13:40:35 -04:00
|
|
|
const specFilters = argumentsParser
|
2018-04-10 18:34:18 -04:00
|
|
|
.option(
|
|
|
|
'-f, --filter-spec [filter]',
|
|
|
|
'Filter run spec files by path. Multiple filters are like a logical OR.',
|
2018-05-01 13:40:35 -04:00
|
|
|
(filter, memo) => {
|
|
|
|
memo.push(filter, filter.replace(/\/?$/, '/**/*.js'));
|
2018-04-10 18:34:18 -04:00
|
|
|
return memo;
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
.parse(process.argv).filterSpec;
|
2018-04-10 05:12:24 -04:00
|
|
|
|
2018-05-01 13:40:35 -04:00
|
|
|
if (specFilters.length) {
|
|
|
|
const specsPath = /^(?:\.[\\\/])?spec[\\\/]javascripts[\\\/]/;
|
|
|
|
|
|
|
|
// resolve filters
|
|
|
|
let filteredSpecFiles = specFilters.map(filter =>
|
|
|
|
glob
|
|
|
|
.sync(filter, {
|
|
|
|
root: ROOT_PATH,
|
|
|
|
matchBase: true,
|
|
|
|
})
|
|
|
|
.filter(path => path.endsWith('spec.js'))
|
|
|
|
);
|
|
|
|
|
|
|
|
// flatten
|
|
|
|
filteredSpecFiles = Array.prototype.concat.apply([], filteredSpecFiles);
|
|
|
|
|
|
|
|
// remove duplicates
|
|
|
|
filteredSpecFiles = [...new Set(filteredSpecFiles)];
|
|
|
|
|
|
|
|
if (filteredSpecFiles.length < 1) {
|
|
|
|
fatalError('Your filter did not match any test files.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filteredSpecFiles.every(file => specsPath.test(file))) {
|
|
|
|
fatalError('Test files must be located within /spec/javascripts.');
|
|
|
|
}
|
|
|
|
|
|
|
|
const newContext = filteredSpecFiles.reduce((context, file) => {
|
|
|
|
const relativePath = file.replace(specsPath, '');
|
|
|
|
context[file] = `./${relativePath}`;
|
|
|
|
return context;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
webpackConfig.plugins.push(
|
|
|
|
new webpack.ContextReplacementPlugin(
|
|
|
|
/spec[\\\/]javascripts$/,
|
|
|
|
path.join(ROOT_PATH, 'spec/javascripts'),
|
|
|
|
newContext
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-12-21 18:01:51 -05:00
|
|
|
|
2016-12-29 16:42:48 -05:00
|
|
|
// Karma configuration
|
|
|
|
module.exports = function(config) {
|
2018-01-21 01:16:25 -05:00
|
|
|
process.env.TZ = 'Etc/UTC';
|
|
|
|
|
2018-05-01 13:40:35 -04:00
|
|
|
const progressReporter = process.env.CI ? 'mocha' : 'progress';
|
2017-03-20 18:29:45 -04:00
|
|
|
|
2018-05-01 13:40:35 -04:00
|
|
|
const karmaConfig = {
|
2016-12-29 16:42:48 -05:00
|
|
|
basePath: ROOT_PATH,
|
2017-06-14 14:58:10 -04:00
|
|
|
browsers: ['ChromeHeadlessCustom'],
|
2017-06-13 13:37:36 -04:00
|
|
|
customLaunchers: {
|
2017-06-14 14:58:10 -04:00
|
|
|
ChromeHeadlessCustom: {
|
2017-06-13 13:37:36 -04:00
|
|
|
base: 'ChromeHeadless',
|
2017-06-14 14:58:10 -04:00
|
|
|
displayName: 'Chrome',
|
|
|
|
flags: [
|
|
|
|
// chrome cannot run in sandboxed mode inside a docker container unless it is run with
|
|
|
|
// escalated kernel privileges (e.g. docker run --cap-add=CAP_SYS_ADMIN)
|
|
|
|
'--no-sandbox',
|
|
|
|
],
|
2018-03-23 12:52:54 -04:00
|
|
|
},
|
2017-06-13 13:37:36 -04:00
|
|
|
},
|
2017-01-06 18:21:54 -05:00
|
|
|
frameworks: ['jasmine'],
|
2016-12-29 16:42:48 -05:00
|
|
|
files: [
|
2017-01-07 02:38:36 -05:00
|
|
|
{ pattern: 'spec/javascripts/test_bundle.js', watched: false },
|
2018-04-08 06:20:05 -04:00
|
|
|
{ pattern: 'spec/javascripts/fixtures/**/*@(.json|.html|.html.raw|.png)', included: false },
|
2016-12-29 16:42:48 -05:00
|
|
|
],
|
|
|
|
preprocessors: {
|
2017-03-15 19:31:01 -04:00
|
|
|
'spec/javascripts/**/*.js': ['webpack', 'sourcemap'],
|
2016-12-29 16:42:48 -05:00
|
|
|
},
|
2017-03-20 18:29:45 -04:00
|
|
|
reporters: [progressReporter],
|
|
|
|
webpack: webpackConfig,
|
|
|
|
webpackMiddleware: { stats: 'errors-only' },
|
|
|
|
};
|
|
|
|
|
|
|
|
if (process.env.BABEL_ENV === 'coverage' || process.env.NODE_ENV === 'coverage') {
|
|
|
|
karmaConfig.reporters.push('coverage-istanbul');
|
|
|
|
karmaConfig.coverageIstanbulReporter = {
|
2017-02-10 13:29:03 -05:00
|
|
|
reports: ['html', 'text-summary'],
|
|
|
|
dir: 'coverage-javascript/',
|
|
|
|
subdir: '.',
|
2018-03-23 12:52:54 -04:00
|
|
|
fixWebpackSourcePaths: true,
|
2017-03-20 18:29:45 -04:00
|
|
|
};
|
2017-06-16 16:40:28 -04:00
|
|
|
karmaConfig.browserNoActivityTimeout = 60000; // 60 seconds
|
2017-03-20 18:29:45 -04:00
|
|
|
}
|
|
|
|
|
2017-06-14 14:58:10 -04:00
|
|
|
if (process.env.DEBUG) {
|
|
|
|
karmaConfig.logLevel = config.LOG_DEBUG;
|
|
|
|
process.env.CHROME_LOG_FILE = process.env.CHROME_LOG_FILE || 'chrome_debug.log';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.CHROME_LOG_FILE) {
|
|
|
|
karmaConfig.customLaunchers.ChromeHeadlessCustom.flags.push('--enable-logging', '--v=1');
|
|
|
|
}
|
|
|
|
|
2017-03-20 18:29:45 -04:00
|
|
|
config.set(karmaConfig);
|
2016-12-29 16:42:48 -05:00
|
|
|
};
|