Commit bf348a1

Anton Golub <antongolub@antongolub.com>
2024-04-01 19:04:37
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
.github/workflows/test.yml
@@ -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
scripts/build-js.mjs
@@ -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'],
test/bun.test.js → test/smoke/bun.test.js
@@ -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 () => {
test/smoke/node-esm.test.js
@@ -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')
test/win32.test.js → test/smoke/win32.test.js
@@ -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
 
test/all.test.js
@@ -21,4 +21,3 @@ import './goods.test.js'
 import './index.test.js'
 import './package.test.js'
 import './util.test.js'
-import './win32.test.js'
package.json
@@ -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"