Skip to content

Commit

Permalink
chore: fix jest environment error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Nov 17, 2023
1 parent 44c6ee9 commit b16a859
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 0 additions & 1 deletion 3d/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const esm = ["internmap", "d3-*", "lodash-es"].map((d) => `_${d}|${d}`).join("|"

module.exports = {
testTimeout: 100000,
preset: "ts-jest/presets/js-with-ts",
transform: {
"^.+\\.[tj]s$": [
"ts-jest",
Expand Down
7 changes: 2 additions & 5 deletions 3d/scripts/jest/environment.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const { readFile } = require("fs").promises;
const path = require("path");
const NodeEnvironment = require("jest-environment-node");
const NodeEnvironment = require("jest-environment-node").TestEnvironment;
const { TMP_DIR } = require("./constants");

// @see https://stackoverflow.com/questions/75047051/jest-class-extends-value-object-is-not-a-constructor-or-null
global.TextEncoder = require("util").TextEncoder;
global.TextDecoder = require("util").TextDecoder;

/**
* @see https://jestjs.io/docs/puppeteer
*/
Expand All @@ -16,6 +12,7 @@ class Environment extends NodeEnvironment {
}

async setup() {
await super.setup();
this.global.PORT = await readFile(path.join(TMP_DIR, "PORT"), "utf8");
}
}
Expand Down

0 comments on commit b16a859

Please sign in to comment.