diff options
-rw-r--r-- | app/assets/javascripts/pages/profiles/show/emoji_menu.js | 1 | ||||
-rw-r--r-- | jest.config.js (renamed from config/jest.config.js) | 4 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | spec/frontend/.eslintrc.yml | 2 | ||||
-rw-r--r-- | spec/frontend/helpers/test_constants.js | 2 | ||||
-rw-r--r-- | spec/frontend/pages/profiles/show/emoji_menu_spec.js (renamed from spec/javascripts/pages/profiles/show/emoji_menu_spec.js) | 6 | ||||
-rw-r--r-- | spec/frontend/test_setup.js | 16 |
7 files changed, 27 insertions, 6 deletions
diff --git a/app/assets/javascripts/pages/profiles/show/emoji_menu.js b/app/assets/javascripts/pages/profiles/show/emoji_menu.js index 094837b40e0..286c1f1e929 100644 --- a/app/assets/javascripts/pages/profiles/show/emoji_menu.js +++ b/app/assets/javascripts/pages/profiles/show/emoji_menu.js @@ -1,3 +1,4 @@ +import '~/commons/bootstrap'; import { AwardsHandler } from '~/awards_handler'; class EmojiMenu extends AwardsHandler { diff --git a/config/jest.config.js b/jest.config.js index 23e62f49be1..23554a117f6 100644 --- a/config/jest.config.js +++ b/jest.config.js @@ -16,6 +16,7 @@ module.exports = { testMatch: ['<rootDir>/spec/frontend/**/*_spec.js'], moduleNameMapper: { '^~(.*)$': '<rootDir>/app/assets/javascripts$1', + '^helpers(.*)$': '<rootDir>/spec/frontend/helpers$1', }, collectCoverageFrom: ['<rootDir>/app/assets/javascripts/**/*.{js,vue}'], coverageDirectory: '<rootDir>/coverage-frontend/', @@ -23,5 +24,6 @@ module.exports = { cacheDirectory: '<rootDir>/tmp/cache/jest', modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'], reporters, - rootDir: '..', // necessary because this file is in the config/ subdirectory + setupTestFrameworkScriptFile: '<rootDir>/spec/frontend/test_setup.js', + restoreMocks: true, }; diff --git a/package.json b/package.json index 7352375f78c..52c211f7afb 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "eslint": "eslint --max-warnings 0 --report-unused-disable-directives --ext .js,.vue .", "eslint-fix": "eslint --max-warnings 0 --report-unused-disable-directives --ext .js,.vue --fix .", "eslint-report": "eslint --max-warnings 0 --ext .js,.vue --format html --output-file ./eslint-report.html --no-inline-config .", - "jest": "BABEL_ENV=jest jest --config=config/jest.config.js", + "jest": "BABEL_ENV=jest jest", "karma": "BABEL_ENV=${BABEL_ENV:=karma} karma start --single-run true config/karma.config.js", "karma-coverage": "BABEL_ENV=coverage karma start --single-run true config/karma.config.js", "karma-start": "BABEL_ENV=karma karma start config/karma.config.js", diff --git a/spec/frontend/.eslintrc.yml b/spec/frontend/.eslintrc.yml index 6d73977a891..046215e4c93 100644 --- a/spec/frontend/.eslintrc.yml +++ b/spec/frontend/.eslintrc.yml @@ -6,4 +6,4 @@ plugins: settings: import/resolver: jest: - jestConfigFile: "config/jest.config.js" + jestConfigFile: "jest.config.js" diff --git a/spec/frontend/helpers/test_constants.js b/spec/frontend/helpers/test_constants.js new file mode 100644 index 00000000000..8dc4aef87e1 --- /dev/null +++ b/spec/frontend/helpers/test_constants.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export const TEST_HOST = 'http://test.host'; diff --git a/spec/javascripts/pages/profiles/show/emoji_menu_spec.js b/spec/frontend/pages/profiles/show/emoji_menu_spec.js index 864bda65736..efc338b36eb 100644 --- a/spec/javascripts/pages/profiles/show/emoji_menu_spec.js +++ b/spec/frontend/pages/profiles/show/emoji_menu_spec.js @@ -1,7 +1,7 @@ import $ from 'jquery'; import axios from '~/lib/utils/axios_utils'; import EmojiMenu from '~/pages/profiles/show/emoji_menu'; -import { TEST_HOST } from 'spec/test_constants'; +import { TEST_HOST } from 'helpers/test_constants'; describe('EmojiMenu', () => { const dummyEmojiTag = '<dummy></tag>'; @@ -56,7 +56,7 @@ describe('EmojiMenu', () => { }); it('does not make an axios requst', done => { - spyOn(axios, 'request').and.stub(); + jest.spyOn(axios, 'request').mockReturnValue(); emojiMenu.addAward(dummyVotesBlock(), dummyAwardUrl, dummyEmoji, false, () => { expect(axios.request).not.toHaveBeenCalled(); @@ -67,7 +67,7 @@ describe('EmojiMenu', () => { describe('bindEvents', () => { beforeEach(() => { - spyOn(emojiMenu, 'registerEventListener').and.stub(); + jest.spyOn(emojiMenu, 'registerEventListener').mockReturnValue(); }); it('binds event listeners to custom toggle button', () => { diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js new file mode 100644 index 00000000000..7ad2e97e7e6 --- /dev/null +++ b/spec/frontend/test_setup.js @@ -0,0 +1,16 @@ +const testTimeoutInMs = 300; +jest.setTimeout(testTimeoutInMs); + +let testStartTime; + +// https://github.com/facebook/jest/issues/6947 +beforeEach(() => { + testStartTime = Date.now(); +}); + +afterEach(() => { + const elapsedTimeInMs = Date.now() - testStartTime; + if (elapsedTimeInMs > testTimeoutInMs) { + throw new Error(`Test took too long (${elapsedTimeInMs}ms > ${testTimeoutInMs}ms)!`); + } +}); |