diff options
-rw-r--r-- | config/karma.config.js | 8 | ||||
-rw-r--r-- | spec/javascripts/test_bundle.js | 14 |
2 files changed, 21 insertions, 1 deletions
diff --git a/config/karma.config.js b/config/karma.config.js index c378e621953..3be4d5220f4 100644 --- a/config/karma.config.js +++ b/config/karma.config.js @@ -12,8 +12,16 @@ if (webpackConfig.plugins) { 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'; // Karma configuration diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js index d158786e484..72671cbbda7 100644 --- a/spec/javascripts/test_bundle.js +++ b/spec/javascripts/test_bundle.js @@ -5,6 +5,7 @@ import '~/commons'; import Vue from 'vue'; import VueResource from 'vue-resource'; +import Translate from '~/vue_shared/translate'; import { getDefaultAdapter } from '~/lib/utils/axios_utils'; import { FIXTURES_PATH, TEST_HOST } from './test_constants'; @@ -28,6 +29,7 @@ Vue.config.errorHandler = function (err) { }; Vue.use(VueResource); +Vue.use(Translate); // enable test fixtures jasmine.getFixtures().fixturesPath = FIXTURES_PATH; @@ -67,13 +69,23 @@ beforeEach(() => { Vue.http.interceptors = builtinVueHttpInterceptors.slice(); }); +// 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 axiosDefaultAdapter = getDefaultAdapter(); // render all of our tests const testsContext = require.context('.', true, /_spec$/); testsContext.keys().forEach(function (path) { try { - testsContext(path); + if (!testFile || path.indexOf(testFile) > -1) { + testsContext(path); + } } catch (err) { console.error('[ERROR] Unable to load spec: ', path); describe('Test bundle', function () { |