Commit daa6195f authored by Winnie Hellmann's avatar Winnie Hellmann

Add option to run a single Karma spec file

parent 539996f7
...@@ -12,8 +12,16 @@ if (webpackConfig.plugins) { ...@@ -12,8 +12,16 @@ if (webpackConfig.plugins) {
plugin instanceof webpack.DefinePlugin plugin instanceof webpack.DefinePlugin
); );
}); });
} else {
webpackConfig.plugins = [];
} }
webpackConfig.plugins.push(
new webpack.DefinePlugin({
TEST_FILE: JSON.stringify(process.env.TEST_FILE),
})
);
webpackConfig.devtool = 'cheap-inline-source-map'; webpackConfig.devtool = 'cheap-inline-source-map';
// Karma configuration // Karma configuration
......
...@@ -6,6 +6,7 @@ import '~/commons'; ...@@ -6,6 +6,7 @@ import '~/commons';
import Vue from 'vue'; import Vue from 'vue';
import VueResource from 'vue-resource'; import VueResource from 'vue-resource';
import Translate from '~/vue_shared/translate';
const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent); const isHeadlessChrome = /\bHeadlessChrome\//.test(navigator.userAgent);
Vue.config.devtools = !isHeadlessChrome; Vue.config.devtools = !isHeadlessChrome;
...@@ -24,6 +25,7 @@ Vue.config.errorHandler = function (err) { ...@@ -24,6 +25,7 @@ Vue.config.errorHandler = function (err) {
}; };
Vue.use(VueResource); Vue.use(VueResource);
Vue.use(Translate);
// enable test fixtures // enable test fixtures
jasmine.getFixtures().fixturesPath = '/base/spec/javascripts/fixtures'; jasmine.getFixtures().fixturesPath = '/base/spec/javascripts/fixtures';
...@@ -61,11 +63,20 @@ beforeEach(() => { ...@@ -61,11 +63,20 @@ beforeEach(() => {
Vue.http.interceptors = builtinVueHttpInterceptors.slice(); Vue.http.interceptors = builtinVueHttpInterceptors.slice();
}); });
// render all of our tests // eslint-disable-next-line no-undef
let testFile = TEST_FILE;
if (testFile) {
console.log(`Running only ${testFile}`);
testFile = testFile.replace(/^spec\/javascripts\//, '');
testFile = testFile.replace(/\.js$/, '');
}
const testsContext = require.context('.', true, /_spec$/); const testsContext = require.context('.', true, /_spec$/);
testsContext.keys().forEach(function (path) { testsContext.keys().forEach(function (path) {
try { try {
if (!testFile || path.indexOf(testFile) > -1) {
testsContext(path); testsContext(path);
}
} catch (err) { } catch (err) {
console.error('[ERROR] Unable to load spec: ', path); console.error('[ERROR] Unable to load spec: ', path);
describe('Test bundle', function () { describe('Test bundle', function () {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment