Skip to content

Commit

Permalink
ci: refactor smoke tests flow (#762)
Browse files Browse the repository at this point in the history
* test: separate unit & smoke tests

* chore: linting

* ci: fix artifact path

* ci: smoke tests tweak up

* chore: linting

* test: optimize bun test setup
  • Loading branch information
antongolub authored Apr 1, 2024
1 parent cd1e7e3 commit bf348a1
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 23 deletions.
79 changes: 59 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,95 @@ name: Test
on: [push, pull_request]

jobs:
test:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: build
path: |
build
package.json
retention-days: 1

test:
needs: build
runs-on: ubuntu-latest
env:
FORCE_COLOR: 3
strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/download-artifact@v4
with:
name: build
- run: npm ci
- run: npm test
- name: run all tests
if: matrix.node-version == '20.x'
run: npm run test
- name: run unit tests
if: matrix.node-version != '20.x'
run: npm run test:unit
timeout-minutes: 1
env:
FORCE_COLOR: 3

win32:
smoke-win32-node16:
runs-on: windows-latest

needs: build
steps:
- uses: actions/checkout@v4
- name: Use Node.js 16.x
uses: actions/setup-node@v4
with:
node-version: 16.x
- run: npm ci
- run: npm run build
- run: node ./test/win32.test.js
- uses: actions/download-artifact@v4
with:
name: build
- run: npm run test:smoke:win32
timeout-minutes: 1
env:
FORCE_COLOR: 3

bun:
runs-on: ubuntu-latest
# smoke-node14:
# needs: build
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Use Node.js 14.x
# uses: actions/setup-node@v4
# with:
# node-version: 14.x
# - uses: actions/download-artifact@v4
# with:
# name: build
# - run: npm run test:smoke:node14
# timeout-minutes: 1
# env:
# FORCE_COLOR: 3

smoke-bun:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Setup Bun
uses: antongolub/action-setup-bun@v1

- run: npm ci
- run: npm run build
- run: bun test ./test/bun.test.js
- uses: actions/download-artifact@v4
with:
name: build
- run: bun test ./test/smoke/bun.test.js
timeout-minutes: 1
env:
FORCE_COLOR: 3
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"test": "npm run build && npm run test:unit && npm run test:types",
"test:unit": "node ./test/all.test.js",
"test:types": "tsd",
"test:smoke:bun": "bun test ./test/smoke/bun.test.js",
"test:smoke:node14": "node --experimental-modules ./test/smoke/node-esm.test.js",
"test:smoke:win32": "node ./test/smoke/win32.test.js",
"coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test",
"circular": "madge --circular src/*",
"version": "cat package.json | fx .version"
Expand Down
1 change: 1 addition & 0 deletions scripts/build-js.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const argv = minimist(process.argv.slice(2), {
minify: false,
sourcemap: false,
format: 'cjs,esm',
target: 'node12',
cwd: process.cwd(),
},
boolean: ['minify', 'sourcemap', 'banner'],
Expand Down
1 change: 0 additions & 1 deletion test/all.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ import './goods.test.js'
import './index.test.js'
import './package.test.js'
import './util.test.js'
import './win32.test.js'
2 changes: 1 addition & 1 deletion test/bun.test.js → test/smoke/bun.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import assert from 'node:assert'
import { test, describe } from 'bun:test'
import '../build/globals.js'
import '../../build/globals.js'

describe('bun', () => {
test('smoke test', async () => {
Expand Down
31 changes: 31 additions & 0 deletions test/smoke/node-esm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import assert from 'assert'
import '../../build/globals.js'
;(async () => {
// smoke test
{
const p = await $`echo foo`
assert.match(p.stdout, /foo/)
}

// captures err stack
{
const p = await $({ nothrow: true })`echo foo; exit 3`
assert.match(p.message, /exit code: 3/)
}
})()

console.log('smoke: ok')
2 changes: 1 addition & 1 deletion test/win32.test.js → test/smoke/win32.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import assert from 'node:assert'
import { test, describe } from 'node:test'
import '../build/globals.js'
import '../../build/globals.js'

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

Expand Down

0 comments on commit bf348a1

Please sign in to comment.