Skip to content
Snippets Groups Projects
Commit 3bdd7ff4 authored by Phil Hughes's avatar Phil Hughes
Browse files

Merge branch 'winh-jest-console' into 'master'

Provide custom Jest environment with mocked console

Closes #58203

See merge request gitlab-org/gitlab-ce!26577
parents 581b839f fbe1f8b4
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -37,4 +37,5 @@ module.exports = {
},
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
timers: 'fake',
testEnvironment: '<rootDir>/spec/frontend/environment.js',
};
Loading
Loading
@@ -160,7 +160,9 @@
"jasmine-diff": "^0.1.3",
"jasmine-jquery": "^2.1.1",
"jest": "^24.1.0",
"jest-environment-jsdom": "^24.0.0",
"jest-junit": "^6.3.0",
"jest-util": "^24.0.0",
"jsdoc": "^3.5.5",
"jsdoc-vue": "^1.0.0",
"karma": "^3.0.0",
Loading
Loading
/* eslint-disable import/no-commonjs */
const { ErrorWithStack } = require('jest-util');
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(
`Unexpected call of console.error() with:\n\n${args.join(', ')}`,
this.error,
);
},
warn(...args) {
throw new ErrorWithStack(
`Unexpected call of console.warn() with:\n\n${args.join(', ')}`,
this.warn,
);
},
});
}
}
module.exports = CustomEnvironment;
Loading
Loading
@@ -3,8 +3,6 @@
import fs from 'fs';
import path from 'path';
 
// jest-util is part of Jest
// eslint-disable-next-line import/no-extraneous-dependencies
import { ErrorWithStack } from 'jest-util';
 
const fixturesBasePath = path.join(process.cwd(), 'spec', 'javascripts', 'fixtures');
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment