diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 940599c66d1..7a374608e72 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,6 +8,7 @@ on: env: NODE_OPTIONS: --max-old-space-size=4096 + CI: true jobs: prettier-check: @@ -64,7 +65,7 @@ jobs: - 8888:80 strategy: matrix: - node-version: [18, 20, 22] + node-version: [18, 20, 22, 23] fail-fast: false steps: - name: Checkout Master @@ -82,12 +83,18 @@ jobs: key: ${{ runner.os }}-${{matrix.node-version}}-jest-${{ hashFiles('yarn.lock') }} restore-keys: | ${{ runner.os }}-${{matrix.node-version}}-jest- - - name: Test + - name: Unit Tests uses: nick-fields/retry@v3 with: timeout_minutes: 10 max_attempts: 5 command: yarn test --ci + - name: Leak Tests + uses: nick-fields/retry@v3 + with: + timeout_minutes: 10 + max_attempts: 5 + command: yarn test:leaks --ci unit-bun: name: unit / bun ${{matrix.node-version}} @@ -118,41 +125,6 @@ jobs: - name: Test run: yarn test:bun --ci - unit-leaks: - name: unit / leaks / node ${{matrix.node-version}} - runs-on: ubuntu-latest - services: - httpbin: - image: kennethreitz/httpbin - ports: - - 8888:80 - strategy: - matrix: - node-version: [18, 22] - fail-fast: false - steps: - - name: Checkout Master - uses: actions/checkout@v4 - - name: Install Required Libraries - run: sudo apt update && sudo apt install -y libcurl4-openssl-dev libssl-dev - - name: Setup env - uses: the-guild-org/shared-config/setup@main - with: - nodeVersion: ${{ matrix.node-version }} - - name: Cache Jest - uses: actions/cache@v4 - with: - path: .cache/jest - key: ${{ runner.os }}-${{matrix.node-version}}-jest-${{ hashFiles('yarn.lock') }} - restore-keys: | - ${{ runner.os }}-${{matrix.node-version}}-jest- - - name: Test - uses: nick-fields/retry@v3 - with: - timeout_minutes: 10 - max_attempts: 5 - command: yarn test:leaks --ci - esm: name: esm runs-on: ubuntu-latest diff --git a/jest.config.js b/jest.config.js index 4f83cb02334..942592dd26f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -22,6 +22,7 @@ try { } module.exports = { + displayName: process.env.LEAK_TEST ? 'Leak Tests' : 'Unit Tests', testEnvironment: 'node', rootDir: ROOT_DIR, restoreMocks: true, diff --git a/package.json b/package.json index 49e8aea1aba..85323af659c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "release": "changeset publish", "test": "jest --runInBand --forceExit", "test:bun": "bun test --bail", - "test:leaks": "LEAK_TEST=1 jest --runInBand --detectOpenHandles --detectLeaks --logHeapUsage --forceExit", + "test:leaks": "LEAK_TEST=1 jest --detectOpenHandles --detectLeaks --runInBand --forceExit", "ts:check": "tsc --noEmit" }, "optionalDependencies": { diff --git a/patches/jest-leak-detector+29.7.0.patch b/patches/jest-leak-detector+29.7.0.patch new file mode 100644 index 00000000000..027a9ddc104 --- /dev/null +++ b/patches/jest-leak-detector+29.7.0.patch @@ -0,0 +1,33 @@ +diff --git a/node_modules/jest-leak-detector/build/index.js b/node_modules/jest-leak-detector/build/index.js +index a8ccb1e..70699fd 100644 +--- a/node_modules/jest-leak-detector/build/index.js ++++ b/node_modules/jest-leak-detector/build/index.js +@@ -74,26 +74,14 @@ class LeakDetector { + value = null; + } + async isLeaking() { +- this._runGarbageCollector(); ++ (0, _v().setFlagsFromString)('--allow-natives-syntax'); + + // wait some ticks to allow GC to run properly, see https://github.com/nodejs/node/issues/34636#issuecomment-669366235 + for (let i = 0; i < 10; i++) { ++ eval('%CollectGarbage(true)'); + await tick(); + } + return this._isReferenceBeingHeld; + } +- _runGarbageCollector() { +- // @ts-expect-error: not a function on `globalThis` +- const isGarbageCollectorHidden = globalThis.gc == null; +- +- // GC is usually hidden, so we have to expose it before running. +- (0, _v().setFlagsFromString)('--expose-gc'); +- (0, _vm().runInNewContext)('gc')(); +- +- // The GC was not initially exposed, so let's hide it again. +- if (isGarbageCollectorHidden) { +- (0, _v().setFlagsFromString)('--no-expose-gc'); +- } +- } + } + exports.default = LeakDetector;