From b26f6ac576d722139683e128d3f1cb1c5db6fbf8 Mon Sep 17 00:00:00 2001 From: Alex Miller Date: Mon, 11 Sep 2023 11:02:18 +1200 Subject: [PATCH] Test: add import smoke tests for cjs, esm, ts for both Node and Bun --- .github/workflows/test.yml | 36 ++++++++++++++++++++++++++++++++++ smoke-tests/smoke-test-cjs.cjs | 24 +++++++++++++++++++++++ smoke-tests/smoke-test-esm.mjs | 25 +++++++++++++++++++++++ smoke-tests/smoke-test.ts | 23 ++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 smoke-tests/smoke-test-cjs.cjs create mode 100644 smoke-tests/smoke-test-esm.mjs create mode 100644 smoke-tests/smoke-test.ts diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9529a083..c4650c1e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,6 +59,14 @@ jobs: - name: Build & Test run: concurrently --prefix none --group "pnpm:build" "pnpm:test" + - name: Import with CJS + if: ${{ always() }} + run: node smoke-tests/smoke-test-cjs.cjs + + - name: Import with ESM + if: ${{ always() }} + run: node smoke-tests/smoke-test-esm.mjs + - name: Submit coverage uses: coverallsapp/github-action@master continue-on-error: true @@ -66,7 +74,35 @@ jobs: github-token: ${{ secrets.github_token }} flag-name: Node.js ${{ matrix.node }} on ${{ matrix.os.name }} parallel: true + bun: + name: Bun on ${{ matrix.os.name }} + runs-on: ${{ matrix.os.version }} + strategy: + fail-fast: false + matrix: + os: + - name: Ubuntu + version: ubuntu-latest + - name: Windows + version: windows-latest + - name: macOS + version: macOS-latest + steps: + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest + + - name: Import with CJS + if: ${{ always() }} + run: bun smoke-tests/smoke-test-cjs.cjs + + - name: Import with ESM + if: ${{ always() }} + run: bun smoke-tests/smoke-test-esm.mjs + - name: Import with both CJS and ESM vis TS + if: ${{ always() }} + run: bun smoke-tests/smoke-test.ts coverage: name: Coverage needs: test diff --git a/smoke-tests/smoke-test-cjs.cjs b/smoke-tests/smoke-test-cjs.cjs new file mode 100644 index 00000000..31375347 --- /dev/null +++ b/smoke-tests/smoke-test-cjs.cjs @@ -0,0 +1,24 @@ +// @ts-check +/* eslint-disable @typescript-eslint/no-var-requires, no-console */ + +const assert = require('node:assert'); +const concurrently = require('../index.js'); + +(async () => { + try { + // Assert the functions loaded by checking their names load and types are correct + assert.strictEqual( + typeof concurrently === 'function', + true, + 'Expected default to be function', + ); + + console.info('Imported cjs successfully'); + } catch (error) { + console.error(error); + console.debug(error.stack); + + // Prevent an unhandled rejection, exit gracefully. + process.exit(1); + } +})(); diff --git a/smoke-tests/smoke-test-esm.mjs b/smoke-tests/smoke-test-esm.mjs new file mode 100644 index 00000000..cf457fb3 --- /dev/null +++ b/smoke-tests/smoke-test-esm.mjs @@ -0,0 +1,25 @@ +// @ts-check +/* eslint-disable no-console */ + +import assert from 'node:assert'; + +import concurrently from '../index.mjs'; + +(async () => { + try { + // Assert the functions loaded by checking their names load and types are correct + assert.strictEqual( + typeof concurrently === 'function', + true, + 'Expected default to be function', + ); + + console.info('Imported esm successfully'); + } catch (error) { + console.error(error); + console.debug(error.stack); + + // Prevent an unhandled rejection, exit gracefully. + process.exit(1); + } +})(); diff --git a/smoke-tests/smoke-test.ts b/smoke-tests/smoke-test.ts new file mode 100644 index 00000000..c96d6682 --- /dev/null +++ b/smoke-tests/smoke-test.ts @@ -0,0 +1,23 @@ +/* eslint-disable no-console */ + +import assert from 'node:assert'; + +(async () => { + try { + const { default: esm } = await import('../index.mjs'); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { default: cjs } = require('../index.js'); + + // Assert the functions loaded by checking their names load and types are correct + assert.strictEqual(typeof esm === 'function', true, 'Expected esm default to be function'); + assert.strictEqual(typeof cjs === 'function', true, 'Expected cjs default to be function'); + + console.info('Imported with both CJS and ESM successfully'); + } catch (error) { + console.error(error); + console.debug(error.stack); + + // Prevent an unhandled rejection, exit gracefully. + process.exit(1); + } +})();