fbac16b2de
(cherry picked from commit 2917a28a885922a03f2026ddbb2680bc2b6e5d50)
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
/* 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,
|
|
);
|
|
},
|
|
});
|
|
|
|
const { testEnvironmentOptions } = config;
|
|
const { IS_EE } = testEnvironmentOptions;
|
|
this.global.gon = {
|
|
ee: IS_EE,
|
|
};
|
|
|
|
this.rejectedPromises = [];
|
|
|
|
this.global.promiseRejectionHandler = error => {
|
|
this.rejectedPromises.push(error);
|
|
};
|
|
|
|
this.global.fixturesBasePath = `${process.cwd()}/${
|
|
IS_EE ? 'ee/' : ''
|
|
}spec/javascripts/fixtures`;
|
|
}
|
|
|
|
async teardown() {
|
|
await new Promise(setImmediate);
|
|
|
|
if (this.rejectedPromises.length > 0) {
|
|
throw new ErrorWithStack(
|
|
`Unhandled Promise rejections: ${this.rejectedPromises.join(', ')}`,
|
|
this.teardown,
|
|
);
|
|
}
|
|
|
|
await super.teardown();
|
|
}
|
|
}
|
|
|
|
module.exports = CustomEnvironment;
|