feat: provide a decorated fetch environment for js-dom
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -48,7 +48,7 @@ function getRoleConfig(role) {
|
||||
case 'common-library':
|
||||
case 'frontend-plugin':
|
||||
case 'frontend-plugin-module':
|
||||
return { testEnvironment: require.resolve('jest-environment-jsdom') };
|
||||
return { testEnvironment: require.resolve('./jsdomEnvironment') };
|
||||
case 'cli':
|
||||
case 'backend':
|
||||
case 'node-library':
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 } 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user