Skip to content

Commit 3e21d36

Browse files
authored
ci: migrate to github actions (#901)
* ci: migrate to github actions * test: support skipping browser setup
1 parent be959be commit 3e21d36

File tree

7 files changed

+134
-147
lines changed

7 files changed

+134
-147
lines changed

.circleci/config.yml

Lines changed: 0 additions & 117 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint-and-format:
15+
name: Lint and Format
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
cache: yarn
24+
node-version: 22
25+
- name: Install Dependencies
26+
run: yarn install --frozen-lockfile
27+
- name: Check Linting
28+
run: yarn lint
29+
- name: Check Formatting
30+
run: yarn format:check
31+
32+
test:
33+
name: Tests (Node ${{ matrix.node-version }} - WDS ${{ matrix.wds-version }})
34+
runs-on: ubuntu-latest
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
node-version:
39+
- '18'
40+
- '20'
41+
- '22'
42+
wds-version:
43+
- '4'
44+
- '5'
45+
steps:
46+
- name: Checkout Repository
47+
uses: actions/checkout@v4
48+
- name: Setup Node.js
49+
uses: actions/setup-node@v4
50+
with:
51+
cache: yarn
52+
node-version: ${{ matrix.node-version }}
53+
- name: Install Dependencies
54+
run: yarn install --frozen-lockfile
55+
- name: Run Tests
56+
run: yarn test --testPathIgnorePatterns conformance
57+
env:
58+
BROWSER: false
59+
WDS_VERSION: ${{ matrix.wds-version }}
60+
61+
conformance:
62+
name: Conformance (Node ${{ matrix.node-version }} - WDS ${{ matrix.wds-version }})
63+
runs-on: ubuntu-latest
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
node-version:
68+
- '18'
69+
- '20'
70+
- '22'
71+
wds-version:
72+
- '4'
73+
- '5'
74+
steps:
75+
- name: Checkout Repository
76+
uses: actions/checkout@v4
77+
- name: Setup Node.js
78+
uses: actions/setup-node@v4
79+
with:
80+
cache: yarn
81+
node-version: ${{ matrix.node-version }}
82+
- name: Install Dependencies
83+
run: yarn install --frozen-lockfile
84+
- name: Disable AppArmor
85+
run: echo 0 | sudo tee /proc/sys/kernel/apparmor_restrict_unprivileged_userns
86+
- name: Run Conformance Tests
87+
run: yarn test conformance
88+
env:
89+
WDS_VERSION: ${{ matrix.wds-version }}

scripts/test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const yn = require('yn');
1313
let argv = process.argv.slice(2);
1414

1515
if (yn(process.env.CI)) {
16-
// Force headless mode in CI environments
17-
process.env.HEADLESS = 'true';
18-
1916
// Use CI mode
2017
argv.push('--ci');
2118
// Parallelized puppeteer tests have high memory overhead in CI environments.

test/conformance/ReactRefreshRequire.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @jest-environment <rootDir>/conformance/environment
3+
*/
4+
15
const getSandbox = require('../helpers/sandbox');
26

37
// https://github.com/facebook/metro/blob/c083da2a9465ef53f10ded04bb7c0b748c8b90cb/packages/metro/src/lib/polyfills/__tests__/require-test.js#L1028-L1087

test/conformance/environment.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const puppeteer = require('puppeteer');
2+
const TestEnvironment = require('../jest-environment');
3+
4+
class SandboxEnvironment extends TestEnvironment {
5+
async setup() {
6+
await super.setup();
7+
8+
const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT;
9+
if (!wsEndpoint) {
10+
throw new Error('Puppeteer wsEndpoint not found!');
11+
}
12+
13+
this.global.browser = await puppeteer.connect({
14+
browserWSEndpoint: wsEndpoint,
15+
});
16+
}
17+
18+
async teardown() {
19+
await super.teardown();
20+
21+
if (this.global.browser) {
22+
await this.global.browser.disconnect();
23+
}
24+
}
25+
}
26+
27+
module.exports = SandboxEnvironment;

test/jest-environment.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
const { TestEnvironment } = require('jest-environment-node');
2-
const puppeteer = require('puppeteer');
1+
const { TestEnvironment: NodeEnvironment } = require('jest-environment-node');
32
const semver = require('semver');
43
const yn = require('yn');
54

6-
class SandboxEnvironment extends TestEnvironment {
5+
class TestEnvironment extends NodeEnvironment {
76
async setup() {
87
await super.setup();
98

@@ -15,24 +14,7 @@ class SandboxEnvironment extends TestEnvironment {
1514
: semver.major(process.version) < 18 || this.global.WEBPACK_VERSION === 4
1615
? 4
1716
: 5;
18-
19-
const wsEndpoint = process.env.PUPPETEER_WS_ENDPOINT;
20-
if (!wsEndpoint) {
21-
throw new Error('Puppeteer wsEndpoint not found!');
22-
}
23-
24-
this.global.browser = await puppeteer.connect({
25-
browserWSEndpoint: wsEndpoint,
26-
});
27-
}
28-
29-
async teardown() {
30-
await super.teardown();
31-
32-
if (this.global.browser) {
33-
await this.global.browser.disconnect();
34-
}
3517
}
3618
}
3719

38-
module.exports = SandboxEnvironment;
20+
module.exports = TestEnvironment;

test/jest-global-setup.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ const puppeteer = require('puppeteer');
22
const yn = require('yn');
33

44
async function setup() {
5-
const browser = await puppeteer.launch({
6-
devtools: yn(process.env.DEBUG, { default: false }),
7-
headless: yn(process.env.HEADLESS, { default: false }),
8-
});
5+
if (yn(process.env.BROWSER, { default: true })) {
6+
const browser = await puppeteer.launch({
7+
devtools: yn(process.env.DEBUG, { default: false }),
8+
headless: yn(process.env.HEADLESS, {
9+
// Force headless mode in CI environments
10+
default: yn(process.env.CI, { default: false }),
11+
}),
12+
});
913

10-
global.__BROWSER_INSTANCE__ = browser;
14+
global.__BROWSER_INSTANCE__ = browser;
1115

12-
process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint();
16+
process.env.PUPPETEER_WS_ENDPOINT = browser.wsEndpoint();
17+
}
1318
}
1419

1520
module.exports = setup;

0 commit comments

Comments
 (0)