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 fcaa531
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
with:
node-version: ${{ matrix.node }}

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

Expand All @@ -59,6 +63,26 @@ jobs:
- name: Build & Test
run: concurrently --prefix none --group "pnpm:build" "pnpm:test"

- name: Node import with CJS
if: ${{ always() }}
run: node ./smoke-tests/smoke-test-cjs.cjs

- name: Node import with ESM
if: ${{ always() }}
run: node ./smoke-tests/smoke-test-esm.mjs

- name: Bun import with CJS
if: ${{ always() }}
run: bun ./smoke-tests/smoke-test-cjs.cjs

- name: Bun import with ESM
if: ${{ always() }}
run: bun ./smoke-tests/smoke-test-esm.mjs

- name: Bun import with both CJS and ESM vis TS
if: ${{ always() }}
run: bun ./smoke-tests/smoke-test.ts

- name: Submit coverage
uses: coverallsapp/github-action@master
continue-on-error: true
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 fcaa531

Please sign in to comment.