Skip to content

Commit

Permalink
improve esm test & add to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloSzx committed Sep 2, 2021
1 parent d097ae3 commit 324c1ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,7 @@ jobs:
run: pnpm install
- name: Global Jest
run: pnpm i -g jest
- name: Test ESM
run: node scripts/test-esm.mjs
- name: Test everything
run: pnpm test:ci
45 changes: 26 additions & 19 deletions scripts/test-esm.mjs
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
import chalk from 'chalk';
import { execSync } from 'child_process';
import { globby } from 'globby';
import { dirname } from 'path';
import { dirname, resolve } from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';

async function main() {
const cwd = dirname(fileURLToPath(import.meta.url));
const mjsFiles = await globby(['../packages/**/dist/*.mjs'], {
cwd: dirname(fileURLToPath(import.meta.url)),
cwd,
});

const ok = [];
const fail = [];

let i = 0;
await Promise.all(
mjsFiles
.filter((v) => !v.endsWith('bin.mjs'))
.map((mjsFile) => {
const mjsPath = `./${mjsFile}`;
return import(mjsPath)
.then(() => {
ok.push(mjsPath);
})
.catch((err) => {
const color = i++ % 2 === 0 ? chalk.magenta : chalk.red;
console.error(color('\n\n-----\n' + i + '\n'));
console.error(mjsPath, err);
console.error(color('\n-----\n\n'));
fail.push(mjsPath);
});
})
mjsFiles.map((mjsFile) => {
if (mjsFile.endsWith('bin.mjs')) {
execSync(`node ${resolve(cwd, mjsFile)} --help`, {
stdio: 'inherit',
});

return;
}
const mjsPath = `./${mjsFile}`;
return import(mjsPath)
.then(() => {
ok.push(mjsPath);
})
.catch((err) => {
const color = i++ % 2 === 0 ? chalk.magenta : chalk.red;
console.error(color('\n\n-----\n' + i + '\n'));
console.error(mjsPath, err);
console.error(color('\n-----\n\n'));
fail.push(mjsPath);
});
})
);
ok.length && console.log(chalk.blue(`${ok.length} OK: ${ok.join(' | ')}`));
fail.length &&
Expand Down

0 comments on commit 324c1ad

Please sign in to comment.