diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2019-03-29 09:57:38 +0000 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2019-03-29 09:57:38 +0000 |
commit | 36ecc88d2cf38508eda7f6cf280b85a7057b9952 (patch) | |
tree | 5c0de45900f68460eeee14a985f9741f8d3db0e9 | |
parent | 7ae35d0a78535218c7e01b917dccc1cea766707b (diff) | |
parent | 63f6fcd0b7876b74f7d42f3c787a8fdb53a264e2 (diff) | |
download | gitlab-ce-36ecc88d2cf38508eda7f6cf280b85a7057b9952.tar.gz |
Merge branch 'winh-jest-gon' into 'master'
Set gon.ee in Jest
Closes #59634
See merge request gitlab-org/gitlab-ce!26713
-rw-r--r-- | .eslintignore | 1 | ||||
-rw-r--r-- | config/helpers/is_ee_env.js | 9 | ||||
-rw-r--r-- | config/webpack.config.js | 6 | ||||
-rw-r--r-- | jest.config.js | 5 | ||||
-rw-r--r-- | spec/frontend/environment.js | 6 |
5 files changed, 21 insertions, 6 deletions
diff --git a/.eslintignore b/.eslintignore index f78840e67be..9a5e15c86ae 100644 --- a/.eslintignore +++ b/.eslintignore @@ -9,5 +9,6 @@ /scripts/ /tmp/ /vendor/ +jest.config.js karma.config.js webpack.config.js diff --git a/config/helpers/is_ee_env.js b/config/helpers/is_ee_env.js new file mode 100644 index 00000000000..1fdbca591c0 --- /dev/null +++ b/config/helpers/is_ee_env.js @@ -0,0 +1,9 @@ +const fs = require('fs'); +const path = require('path'); + +const ROOT_PATH = path.resolve(__dirname, '../..'); + +module.exports = + process.env.EE !== undefined + ? JSON.parse(process.env.EE) + : fs.existsSync(path.join(ROOT_PATH, 'ee')); diff --git a/config/webpack.config.js b/config/webpack.config.js index 20b3f4c0264..9a37856a99e 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -1,4 +1,3 @@ -const fs = require('fs'); const path = require('path'); const glob = require('glob'); const webpack = require('webpack'); @@ -12,10 +11,7 @@ const ROOT_PATH = path.resolve(__dirname, '..'); const CACHE_PATH = process.env.WEBPACK_CACHE_PATH || path.join(ROOT_PATH, 'tmp/cache'); const IS_PRODUCTION = process.env.NODE_ENV === 'production'; const IS_DEV_SERVER = process.argv.join(' ').indexOf('webpack-dev-server') !== -1; -const IS_EE = - process.env.EE !== undefined - ? JSON.parse(process.env.EE) - : fs.existsSync(path.join(ROOT_PATH, 'ee')); +const IS_EE = require('./helpers/is_ee_env'); const DEV_SERVER_HOST = process.env.DEV_SERVER_HOST || 'localhost'; const DEV_SERVER_PORT = parseInt(process.env.DEV_SERVER_PORT, 10) || 3808; const DEV_SERVER_LIVERELOAD = IS_DEV_SERVER && process.env.DEV_SERVER_LIVERELOAD !== 'false'; diff --git a/jest.config.js b/jest.config.js index cd0d311779d..c7518be9e96 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,4 +1,4 @@ -/* eslint-disable filenames/match-regex */ +const IS_EE = require('./config/helpers/is_ee_env'); const reporters = ['default']; @@ -38,4 +38,7 @@ module.exports = { transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'], timers: 'fake', testEnvironment: '<rootDir>/spec/frontend/environment.js', + testEnvironmentOptions: { + IS_EE, + }, }; diff --git a/spec/frontend/environment.js b/spec/frontend/environment.js index cb128c7d880..1067a53906a 100644 --- a/spec/frontend/environment.js +++ b/spec/frontend/environment.js @@ -6,6 +6,7 @@ const JSDOMEnvironment = require('jest-environment-jsdom'); class CustomEnvironment extends JSDOMEnvironment { constructor(config, context) { super(config, context); + Object.assign(context.console, { error(...args) { throw new ErrorWithStack( @@ -21,6 +22,11 @@ class CustomEnvironment extends JSDOMEnvironment { ); }, }); + + const { testEnvironmentOptions } = config; + this.global.gon = { + ee: testEnvironmentOptions.IS_EE, + }; } } |