-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathjest.setup.js
49 lines (40 loc) · 1.36 KB
/
jest.setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import '@testing-library/jest-dom';
import 'whatwg-fetch'; // Polyfill fetch and Request
import packageJson from './package.json';
import express from 'express';
import path from 'path'; // Import path module for resolving paths
import { jest } from '@jest/globals'; // Ensure Jest is recognized
// Ensure Request is explicitly available
if (typeof global.Request === 'undefined') {
global.Request = window.Request;
global.Headers = window.Headers;
global.origin = window.location.origin;
}
// Define global variables for Jest environment
global.NAME = packageJson.name;
global.DESCRIPTION = packageJson.description + ' (Test Jest-env)';
global.VERSION = packageJson.version;
let examples_server;
beforeAll(() => {
// Mock getBBox for SVG elements
Object.defineProperty(SVGElement.prototype, 'getBBox', {
value: jest.fn().mockReturnValue({
x: 0,
y: 0,
width: 100,
height: 100,
}),
});
// Mock SVGTextElement
global.SVGTextElement = class extends SVGElement {};
const app = express();
const examplesPath = path.resolve(process.cwd(), 'docs/_docs/floorplan');
app.use('/', express.static(examplesPath));
examples_server = app.listen(8080, () => {
console.log('Serving examples folder at http://localhost:8080/');
});
});
afterAll((done) => {
// Close the server after tests are done
examples_server.close(done);
});