Skip to content

Commit

Permalink
Faster CI (#1882)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Dec 12, 2024
1 parent ed32964 commit 6a42223
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 38 deletions.
46 changes: 9 additions & 37 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

env:
NODE_OPTIONS: --max-old-space-size=4096
CI: true

jobs:
prettier-check:
Expand Down Expand Up @@ -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
Expand All @@ -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}}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ try {
}

module.exports = {
displayName: process.env.LEAK_TEST ? 'Leak Tests' : 'Unit Tests',
testEnvironment: 'node',
rootDir: ROOT_DIR,
restoreMocks: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 33 additions & 0 deletions patches/jest-leak-detector+29.7.0.patch
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 6a42223

Please sign in to comment.