Skip to content

Commit

Permalink
Test: add import smoke tests for cjs, esm, ts for both Node and Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
Codex- committed Sep 10, 2023
1 parent f4fdd59 commit b26f6ac
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,50 @@ 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
with:
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
Expand Down
24 changes: 24 additions & 0 deletions smoke-tests/smoke-test-cjs.cjs
Original file line number Diff line number Diff line change
@@ -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);
}
})();
25 changes: 25 additions & 0 deletions smoke-tests/smoke-test-esm.mjs
Original file line number Diff line number Diff line change
@@ -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);
}
})();
23 changes: 23 additions & 0 deletions smoke-tests/smoke-test.ts
Original file line number Diff line number Diff line change
@@ -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);
}
})();

0 comments on commit b26f6ac

Please sign in to comment.