@@ -48,7 +48,7 @@ function getRoleConfig(role) {
|
||||
case 'common-library':
|
||||
case 'frontend-plugin':
|
||||
case 'frontend-plugin-module':
|
||||
return { testEnvironment: require.resolve('./jestJsdomEnvironment') };
|
||||
return { testEnvironment: require.resolve('jest-environment-jsdom') };
|
||||
case 'cli':
|
||||
case 'backend':
|
||||
case 'node-library':
|
||||
@@ -194,9 +194,16 @@ async function getProjectConfig(targetPath, extraConfig) {
|
||||
...getRoleConfig(closestPkgJson?.backstage?.role),
|
||||
};
|
||||
|
||||
options.setupFilesAfterEnv = [];
|
||||
|
||||
if (options.testEnvironment === require.resolve('jest-environment-jsdom')) {
|
||||
// FIXME https://github.com/jsdom/jsdom/issues/1724
|
||||
options.setupFilesAfterEnv.push(require.resolve('cross-fetch/polyfill'));
|
||||
}
|
||||
|
||||
// Use src/setupTests.ts as the default location for configuring test env
|
||||
if (fs.existsSync(path.resolve(targetPath, 'src/setupTests.ts'))) {
|
||||
options.setupFilesAfterEnv = ['<rootDir>/setupTests.ts'];
|
||||
options.setupFilesAfterEnv.push('<rootDir>/setupTests.ts');
|
||||
}
|
||||
|
||||
const config = Object.assign(options, ...pkgJsonConfigs);
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import JSDOMEnvironment from 'jest-environment-jsdom';
|
||||
import { Headers, Request, Response, default as fetch } from 'node-fetch';
|
||||
|
||||
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
|
||||
export default class FixJSDOMEnvironment extends JSDOMEnvironment {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
// FIXME https://github.com/jsdom/jsdom/issues/1724
|
||||
this.global.fetch = fetch;
|
||||
this.global.Headers = Headers;
|
||||
this.global.Request = Request;
|
||||
this.global.Response = Response;
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@
|
||||
"chalk": "^4.0.0",
|
||||
"chokidar": "^3.3.1",
|
||||
"commander": "^9.1.0",
|
||||
"cross-fetch": "^3.1.5",
|
||||
"cross-spawn": "^7.0.3",
|
||||
"css-loader": "^6.5.1",
|
||||
"diff": "^5.0.0",
|
||||
|
||||
@@ -37,8 +37,7 @@ describe('The production Airbrake API', () => {
|
||||
);
|
||||
|
||||
const groups = await productionApi.fetchGroups('123456');
|
||||
|
||||
expect(groups).toEqual(mockGroupsData);
|
||||
expect(groups).toStrictEqual(mockGroupsData);
|
||||
});
|
||||
|
||||
it('throws if fetching groups was unsuccessful', async () => {
|
||||
|
||||
Reference in New Issue
Block a user