Skip to content

Commit 2f36733

Browse files
committed
chore: native ESM tests
1 parent e5e0826 commit 2f36733

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
nodejs: [10, 12, 14, 16, 18, 20]
11+
nodejs: [14, 16, 18, 20]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- uses: actions/setup-node@v4

builder.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
// TODO: temporary
2-
const { promisify } = require('util');
3-
const { execFile } = require('child_process');
4-
const { packages } = require('./bump.json');
1+
const { resolve } = require('node:path');
2+
const { promisify } = require('node:util');
3+
const { execFile } = require('node:child_process');
54

6-
const ENV = { ...process.env, FORCE_COLOR: '1' };
75
const BIN = require.resolve('bundt');
86
const run = promisify(execFile);
97

108
(async function () {
11-
for (let dir of packages) {
12-
console.log('~> "%s"', dir);
13-
let output = await run(BIN, ['index.js'], { env:ENV, cwd:dir });
14-
process.stdout.write(output.stdout.substring(1));
15-
}
9+
let output = await run(BIN, ['index.mjs'], {
10+
env: { ...process.env, FORCE_COLOR: '1' },
11+
cwd: resolve('packages/sirv'),
12+
});
13+
14+
process.stdout.write(output.stdout.substring(1));
1615
})().catch(err => {
1716
console.log('ERROR', err.stack);
1817
process.exit(1);

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
"url": "https://lukeed.com"
77
},
88
"scripts": {
9-
"build": "node builder",
10-
"test": "uvu -r esm tests -i public -i helpers"
9+
"build": "node builder.js",
10+
"test": "uvu tests -i public -i helpers"
1111
},
1212
"workspaces": [
1313
"packages/*"
1414
],
1515
"devDependencies": {
1616
"bump": "1.0.0-next.1",
1717
"bundt": "1.1.5",
18-
"esm": "3.2.25",
1918
"httpie": "2.0.0-next.13",
2019
"mrmime": "2.0.0",
2120
"selfsigned": "2.4.1",

tests/helpers.js renamed to tests/helpers.mjs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import * as fs from 'fs';
2-
import { join } from 'path';
1+
import * as fs from 'node:fs';
2+
import { promisify } from 'node:util';
3+
import { createServer } from 'node:http';
4+
import { join, dirname } from 'node:path';
5+
import { createRequire } from 'node:module';
6+
import { spawnSync, execFile } from 'node:child_process';
7+
import { fileURLToPath } from 'node:url';
8+
39
import { send } from 'httpie';
410
import * as mime from 'mrmime';
5-
import { promisify } from 'util';
6-
import { createServer } from 'http';
7-
import * as child from 'child_process';
811
import * as assert from 'uvu/assert';
9-
import sirv from '../packages/sirv';
12+
import sirv from '../packages/sirv/index.mjs';
13+
14+
const require = createRequire(import.meta.url);
15+
const __filename = fileURLToPath(import.meta.url);
16+
const __dirname = dirname(__filename);
1017

1118
const www = join(__dirname, 'public');
1219
const BIN = require.resolve('../packages/sirv-cli/bin.js');
@@ -31,13 +38,13 @@ export function http(opts) {
3138
}
3239

3340
export function exec(...argv) {
34-
return child.spawnSync('node', [BIN, www, ...argv]);
41+
return spawnSync('node', [BIN, www, ...argv]);
3542
}
3643

3744
export function spawn(...argv) {
3845
return new Promise(r => {
3946
let address, output='';
40-
let pid = child.execFile('node', [BIN, www, ...argv]);
47+
let pid = execFile('node', [BIN, www, ...argv]);
4148

4249
pid.stdout.on('data', x => {
4350
output += x.toString();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { suite } from 'uvu';
2-
import assert from 'uvu/assert';
32
import selfsigned from 'selfsigned';
4-
import * as utils from './helpers';
3+
import * as assert from 'uvu/assert';
4+
import * as utils from './helpers.mjs';
55

66
const help = suite('help');
77

tests/sirv.js renamed to tests/sirv.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { suite } from 'uvu';
2-
import assert from 'uvu/assert';
3-
import sirv from '../packages/sirv';
4-
import * as utils from './helpers';
2+
import * as assert from 'uvu/assert';
3+
import sirv from '../packages/sirv/index.mjs';
4+
import * as utils from './helpers.mjs';
55

66
const types = suite('types');
77

0 commit comments

Comments
 (0)