Skip to content

Commit

Permalink
chore: split build into standalone jobs (#2386)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito authored Dec 15, 2024
1 parent de3bedf commit a6c419c
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 59 deletions.
159 changes: 129 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,86 @@ on:
workflow_dispatch:

jobs:
build:
build-18:
name: build (18)
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 18
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Cache build output
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-18-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-18
build-20:
name: build (20)
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Lint
run: pnpm lint

- name: Build
run: pnpm build

- name: Cache build output
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }}
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-build-${{ matrix.node-version }}
${{ runner.os }}-build-20
test_unit:
name: test (unit)
needs: build
test-unit-18:
name: test (unit) (18)
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand All @@ -73,39 +110,33 @@ jobs:
- name: Install Playwright browsers
run: pnpm exec playwright install

- name: Lint
run: pnpm lint

- name: Unit tests
run: pnpm test:unit

test-node:
name: test (node.js)
needs: build
test-node-18:
name: test (node.js) (18)
needs: build-18
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
node-version: [18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
node-version: 18
cache: 'pnpm'

- name: Restore build cache
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }}
key: ${{ runner.os }}-node-18-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-18-build-
Expand All @@ -115,15 +146,82 @@ jobs:
- name: Node.js tests
run: pnpm test:node

test-node-20:
name: test (node.js) (20)
needs: build-20
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'

- name: Restore build cache
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-20-build-
- name: Install dependencies
run: pnpm install

- name: Node.js tests
run: pnpm test:node

test-e2e:
name: test (e2e) (18)
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'

- name: Restore build cache
uses: actions/cache@v4
with:
path: ./lib
key: ${{ runner.os }}-node-20-build-${{ github.sha }}
restore-keys: |
${{ runner.os }}-node-20-build-
- name: Install dependencies
run: pnpm install

- name: E2E tests
run: pnpm test:e2e

test-browser:
name: test (browser)
needs: build
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand Down Expand Up @@ -159,13 +257,14 @@ jobs:

test-native:
name: test (react-native)
needs: build
needs: build-18
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.0

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@
"check:exports": "node \"./config/scripts/validate-esm.js\"",
"test": "pnpm test:unit && pnpm test:node && pnpm test:browser && pnpm test:native",
"test:unit": "vitest",
"test:node": "vitest run --config=./test/node/vitest.config.mts",
"test:node": "vitest --config=./test/node/vitest.config.mts",
"test:native": "vitest --config=./test/native/vitest.config.mts",
"test:browser": "playwright test -c ./test/browser/playwright.config.ts",
"test:modules:node": "vitest --config=./test/modules/node/vitest.config.mts",
"test:modules:browser": "playwright test -c ./test/modules/browser/playwright.config.ts",
"test:e2e": "vitest run --config=./test/e2e/vitest.config.mts",
"test:ts": "vitest --typecheck --config=./test/typings/vitest.config.mts",
"prepare": "pnpm simple-git-hooks init",
"prepack": "pnpm build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/**
* @vitest-environment node
*/
import * as fs from 'fs'
import { execSync } from 'child_process'
import fs from 'node:fs'
import { execSync } from 'node:child_process'
import { createTeardown } from 'fs-teardown'
import { fromTemp } from '../../support/utils'
import * as packageJson from '../../../package.json'
import { fromTemp } from '../support/utils'
import * as packageJson from '../../package.json'

const fsMock = createTeardown({
rootDir: fromTemp('auto-update-worker'),
rootDir: fromTemp('worker-script-auto-update'),
})

describe.sequential(
describe(
'worker script auto-update',
{
sequential: true,
// These tests actually build, pack, and install MSW so they may take time.
timeout: 60_000,
},
() => {
beforeAll(async () => {
await fsMock.prepare()
Expand All @@ -26,7 +28,7 @@ describe.sequential(
await fsMock.cleanup()
})

test('updates the worker script on the postinstall hook', async () => {
it('updates the worker script on the "postinstall" hook', async () => {
await fsMock.create({
'package.json': JSON.stringify({
name: 'example',
Expand All @@ -53,7 +55,7 @@ describe.sequential(
).toEqual(true)
})

test('updates multiple directories on the postinstall hook', async () => {
it('updates multiple directories on the "postinstall" hook', async () => {
await fsMock.create({
'package.json': JSON.stringify({
name: 'example-multiple-dirs',
Expand Down Expand Up @@ -84,8 +86,4 @@ describe.sequential(
).toEqual(true)
})
},
{
// These tests actually build, pack, and install MSW so they may take time.
timeout: 60_000,
},
)
9 changes: 9 additions & 0 deletions test/e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./**/*.test.ts"],
"compilerOptions": {
"types": ["node", "vitest/globals"],
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true
}
}
22 changes: 22 additions & 0 deletions test/e2e/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from 'vitest/config'
import { mswExports, customViteEnvironments } from '../support/alias'

export default defineConfig({
test: {
dir: './test/e2e',
globals: true,
environment: 'node',
poolOptions: {
threads: {
/**
* @note Run Node.js integration tests in sequence.
* There's a test that involves building the library,
* which results in the "lib" directory being deleted.
* If any tests attempt to run during that window,
* they will fail, unable to resolve the "msw" import alias.
*/
singleThread: true,
},
},
},
})
1 change: 0 additions & 1 deletion test/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"noEmit": true,
"declaration": false,
"resolveJsonModule": true,
// Support default imports for modules that have no default exports.
// This way "http" imports stay "import http from 'http'".
// Using wildcard there breaks request interception since it
Expand Down
12 changes: 0 additions & 12 deletions test/node/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,5 @@ export default defineConfig({
url: 'http://localhost/',
},
},
poolOptions: {
threads: {
/**
* @note Run Node.js integration tests in sequence.
* There's a test that involves building the library,
* which results in the "lib" directory being deleted.
* If any tests attempt to run during that window,
* they will fail, unable to resolve the "msw" import alias.
*/
singleThread: true,
},
},
},
})

0 comments on commit a6c419c

Please sign in to comment.