From 2f3673333ba8a7096db5ca2566842d3e91cc9ec5 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Fri, 11 Oct 2024 08:04:17 -0700 Subject: [PATCH] chore: native ESM tests --- .github/workflows/ci.yml | 2 +- builder.js | 19 +++++++++---------- package.json | 5 ++--- packages/sirv/{index.js => index.mjs} | 0 tests/{helpers.js => helpers.mjs} | 23 +++++++++++++++-------- tests/{sirv-cli.js => sirv-cli.mjs} | 4 ++-- tests/{sirv.js => sirv.mjs} | 6 +++--- 7 files changed, 32 insertions(+), 27 deletions(-) rename packages/sirv/{index.js => index.mjs} (100%) rename tests/{helpers.js => helpers.mjs} (80%) rename tests/{sirv-cli.js => sirv-cli.mjs} (98%) rename tests/{sirv.js => sirv.mjs} (99%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faaa954..67f06ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - nodejs: [10, 12, 14, 16, 18, 20] + nodejs: [14, 16, 18, 20] steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 diff --git a/builder.js b/builder.js index f478573..8ab46da 100644 --- a/builder.js +++ b/builder.js @@ -1,18 +1,17 @@ -// TODO: temporary -const { promisify } = require('util'); -const { execFile } = require('child_process'); -const { packages } = require('./bump.json'); +const { resolve } = require('node:path'); +const { promisify } = require('node:util'); +const { execFile } = require('node:child_process'); -const ENV = { ...process.env, FORCE_COLOR: '1' }; const BIN = require.resolve('bundt'); const run = promisify(execFile); (async function () { - for (let dir of packages) { - console.log('~> "%s"', dir); - let output = await run(BIN, ['index.js'], { env:ENV, cwd:dir }); - process.stdout.write(output.stdout.substring(1)); - } + let output = await run(BIN, ['index.mjs'], { + env: { ...process.env, FORCE_COLOR: '1' }, + cwd: resolve('packages/sirv'), + }); + + process.stdout.write(output.stdout.substring(1)); })().catch(err => { console.log('ERROR', err.stack); process.exit(1); diff --git a/package.json b/package.json index 2d12780..fc2ee87 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "url": "https://lukeed.com" }, "scripts": { - "build": "node builder", - "test": "uvu -r esm tests -i public -i helpers" + "build": "node builder.js", + "test": "uvu tests -i public -i helpers" }, "workspaces": [ "packages/*" @@ -15,7 +15,6 @@ "devDependencies": { "bump": "1.0.0-next.1", "bundt": "1.1.5", - "esm": "3.2.25", "httpie": "2.0.0-next.13", "mrmime": "2.0.0", "selfsigned": "2.4.1", diff --git a/packages/sirv/index.js b/packages/sirv/index.mjs similarity index 100% rename from packages/sirv/index.js rename to packages/sirv/index.mjs diff --git a/tests/helpers.js b/tests/helpers.mjs similarity index 80% rename from tests/helpers.js rename to tests/helpers.mjs index 992702c..4e35c05 100644 --- a/tests/helpers.js +++ b/tests/helpers.mjs @@ -1,12 +1,19 @@ -import * as fs from 'fs'; -import { join } from 'path'; +import * as fs from 'node:fs'; +import { promisify } from 'node:util'; +import { createServer } from 'node:http'; +import { join, dirname } from 'node:path'; +import { createRequire } from 'node:module'; +import { spawnSync, execFile } from 'node:child_process'; +import { fileURLToPath } from 'node:url'; + import { send } from 'httpie'; import * as mime from 'mrmime'; -import { promisify } from 'util'; -import { createServer } from 'http'; -import * as child from 'child_process'; import * as assert from 'uvu/assert'; -import sirv from '../packages/sirv'; +import sirv from '../packages/sirv/index.mjs'; + +const require = createRequire(import.meta.url); +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); const www = join(__dirname, 'public'); const BIN = require.resolve('../packages/sirv-cli/bin.js'); @@ -31,13 +38,13 @@ export function http(opts) { } export function exec(...argv) { - return child.spawnSync('node', [BIN, www, ...argv]); + return spawnSync('node', [BIN, www, ...argv]); } export function spawn(...argv) { return new Promise(r => { let address, output=''; - let pid = child.execFile('node', [BIN, www, ...argv]); + let pid = execFile('node', [BIN, www, ...argv]); pid.stdout.on('data', x => { output += x.toString(); diff --git a/tests/sirv-cli.js b/tests/sirv-cli.mjs similarity index 98% rename from tests/sirv-cli.js rename to tests/sirv-cli.mjs index d731218..87531a8 100644 --- a/tests/sirv-cli.js +++ b/tests/sirv-cli.mjs @@ -1,7 +1,7 @@ import { suite } from 'uvu'; -import assert from 'uvu/assert'; import selfsigned from 'selfsigned'; -import * as utils from './helpers'; +import * as assert from 'uvu/assert'; +import * as utils from './helpers.mjs'; const help = suite('help'); diff --git a/tests/sirv.js b/tests/sirv.mjs similarity index 99% rename from tests/sirv.js rename to tests/sirv.mjs index 8235497..d2e23e2 100644 --- a/tests/sirv.js +++ b/tests/sirv.mjs @@ -1,7 +1,7 @@ import { suite } from 'uvu'; -import assert from 'uvu/assert'; -import sirv from '../packages/sirv'; -import * as utils from './helpers'; +import * as assert from 'uvu/assert'; +import sirv from '../packages/sirv/index.mjs'; +import * as utils from './helpers.mjs'; const types = suite('types');