Skip to content

Commit bf348a1

Browse files
authoredApr 1, 2024··
ci: refactor smoke tests flow (#762)
* test: separate unit & smoke tests * chore: linting * ci: fix artifact path * ci: smoke tests tweak up * chore: linting * test: optimize bun test setup
1 parent cd1e7e3 commit bf348a1

File tree

7 files changed

+96
-23
lines changed

7 files changed

+96
-23
lines changed
 

‎.github/workflows/test.yml

+59-20
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,95 @@ name: Test
33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
build:
77
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Use Node.js 20.x
11+
uses: actions/setup-node@v4
12+
with:
13+
node-version: 20.x
14+
- run: npm ci
15+
- run: npm run build
16+
- uses: actions/upload-artifact@v4
17+
with:
18+
name: build
19+
path: |
20+
build
21+
package.json
22+
retention-days: 1
823

24+
test:
25+
needs: build
26+
runs-on: ubuntu-latest
27+
env:
28+
FORCE_COLOR: 3
929
strategy:
1030
matrix:
1131
node-version: [16.x, 18.x, 20.x]
12-
1332
steps:
1433
- uses: actions/checkout@v4
1534
- name: Use Node.js ${{ matrix.node-version }}
1635
uses: actions/setup-node@v4
1736
with:
1837
node-version: ${{ matrix.node-version }}
38+
- uses: actions/download-artifact@v4
39+
with:
40+
name: build
1941
- run: npm ci
20-
- run: npm test
42+
- name: run all tests
43+
if: matrix.node-version == '20.x'
44+
run: npm run test
45+
- name: run unit tests
46+
if: matrix.node-version != '20.x'
47+
run: npm run test:unit
2148
timeout-minutes: 1
22-
env:
23-
FORCE_COLOR: 3
2449

25-
win32:
50+
smoke-win32-node16:
2651
runs-on: windows-latest
27-
52+
needs: build
2853
steps:
2954
- uses: actions/checkout@v4
3055
- name: Use Node.js 16.x
3156
uses: actions/setup-node@v4
3257
with:
3358
node-version: 16.x
34-
- run: npm ci
35-
- run: npm run build
36-
- run: node ./test/win32.test.js
59+
- uses: actions/download-artifact@v4
60+
with:
61+
name: build
62+
- run: npm run test:smoke:win32
3763
timeout-minutes: 1
3864
env:
3965
FORCE_COLOR: 3
4066

41-
bun:
42-
runs-on: ubuntu-latest
67+
# smoke-node14:
68+
# needs: build
69+
# runs-on: ubuntu-latest
70+
# steps:
71+
# - uses: actions/checkout@v4
72+
# - name: Use Node.js 14.x
73+
# uses: actions/setup-node@v4
74+
# with:
75+
# node-version: 14.x
76+
# - uses: actions/download-artifact@v4
77+
# with:
78+
# name: build
79+
# - run: npm run test:smoke:node14
80+
# timeout-minutes: 1
81+
# env:
82+
# FORCE_COLOR: 3
4383

84+
smoke-bun:
85+
runs-on: ubuntu-latest
86+
needs: build
4487
steps:
4588
- uses: actions/checkout@v4
46-
- name: Use Node.js 20.x
47-
uses: actions/setup-node@v4
48-
with:
49-
node-version: 20.x
5089
- name: Setup Bun
5190
uses: antongolub/action-setup-bun@v1
52-
53-
- run: npm ci
54-
- run: npm run build
55-
- run: bun test ./test/bun.test.js
91+
- uses: actions/download-artifact@v4
92+
with:
93+
name: build
94+
- run: bun test ./test/smoke/bun.test.js
5695
timeout-minutes: 1
5796
env:
5897
FORCE_COLOR: 3

‎package.json

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
"test": "npm run build && npm run test:unit && npm run test:types",
4646
"test:unit": "node ./test/all.test.js",
4747
"test:types": "tsd",
48+
"test:smoke:bun": "bun test ./test/smoke/bun.test.js",
49+
"test:smoke:node14": "node --experimental-modules ./test/smoke/node-esm.test.js",
50+
"test:smoke:win32": "node ./test/smoke/win32.test.js",
4851
"coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test",
4952
"circular": "madge --circular src/*",
5053
"version": "cat package.json | fx .version"

‎scripts/build-js.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const argv = minimist(process.argv.slice(2), {
3030
minify: false,
3131
sourcemap: false,
3232
format: 'cjs,esm',
33+
target: 'node12',
3334
cwd: process.cwd(),
3435
},
3536
boolean: ['minify', 'sourcemap', 'banner'],

‎test/all.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ import './goods.test.js'
2121
import './index.test.js'
2222
import './package.test.js'
2323
import './util.test.js'
24-
import './win32.test.js'

‎test/bun.test.js ‎test/smoke/bun.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import assert from 'node:assert'
1616
import { test, describe } from 'bun:test'
17-
import '../build/globals.js'
17+
import '../../build/globals.js'
1818

1919
describe('bun', () => {
2020
test('smoke test', async () => {

‎test/smoke/node-esm.test.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import assert from 'assert'
16+
import '../../build/globals.js'
17+
;(async () => {
18+
// smoke test
19+
{
20+
const p = await $`echo foo`
21+
assert.match(p.stdout, /foo/)
22+
}
23+
24+
// captures err stack
25+
{
26+
const p = await $({ nothrow: true })`echo foo; exit 3`
27+
assert.match(p.message, /exit code: 3/)
28+
}
29+
})()
30+
31+
console.log('smoke: ok')

‎test/win32.test.js ‎test/smoke/win32.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import assert from 'node:assert'
1616
import { test, describe } from 'node:test'
17-
import '../build/globals.js'
17+
import '../../build/globals.js'
1818

1919
const _describe = process.platform === 'win32' ? describe : describe.skip
2020

0 commit comments

Comments
 (0)
Please sign in to comment.