Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const path = require('path');

// limestone or agate based on provided `--theme` command line argument
const themeEnvArg = process.argv.filter((x) => x.startsWith('--theme='))[0];

// set base default to limestone
const base = themeEnvArg ? themeEnvArg.split('=')[1] : 'limestone';

module.exports = {
setupFilesAfterEnv: ['./jest.setup.js', './puppeteer.setup.js'],
testEnvironment: '<rootDir>/jsdom-extended.js',
setupFilesAfterEnv: [
path.resolve(__dirname, 'jest.setup.js'),
path.resolve(__dirname, 'puppeteer.setup.js'),
],
testEnvironment: path.resolve(__dirname, 'jsdom-extended.js'),
testMatch: [
'<rootDir>/performance/tests/' + base + '/*.test.js'
]
path.resolve(__dirname, 'performance/tests/', base, '*.test.js')
],
};
31 changes: 18 additions & 13 deletions jsdom-extended.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
const JSDOMEnvironment = require("jest-environment-jsdom").default; // or import JSDOMEnvironment from 'jest-environment-jsdom' if you are using ESM modules
const { TestEnvironment: JSDOMEnvironment } = require('jest-environment-jsdom');

class JSDOMEnvironmentExtended extends JSDOMEnvironment {
constructor (...args) {
super(...args);

this.global.ReadableStream = ReadableStream;
this.global.TextDecoder = TextDecoder;
this.global.TextEncoder = TextEncoder;
this.global.ReadableStream = global.ReadableStream || ReadableStream;
this.global.TextDecoder = global.TextDecoder || TextDecoder;
this.global.TextEncoder = global.TextEncoder || TextEncoder;

this.global.Blob = Blob;
this.global.Headers = Headers;
this.global.FormData = FormData;
this.global.Request = Request;
this.global.Response = Response;
this.global.Request = Request;
this.global.Response = Response;
this.global.fetch = fetch;
this.global.structuredClone = structuredClone;
this.global.Blob = global.Blob || Blob;
this.global.Headers = global.Headers || Headers;
this.global.FormData = global.FormData || FormData;
this.global.Request = global.Request || Request;
this.global.Response = global.Response || Response;

// optional fetch polyfill if not defined
if (typeof this.global.fetch === 'undefined') {
this.global.fetch = fetch;
}

if (typeof this.global.structuredClone === 'undefined') {
this.global.structuredClone = structuredClone;
}
}
}

Expand Down
Loading