Skip to content

Commit

Permalink
chore: native ESM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Oct 11, 2024
1 parent e5e0826 commit 2f36733
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions builder.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@
"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/*"
],
"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",
Expand Down
File renamed without changes.
23 changes: 15 additions & 8 deletions tests/helpers.js → tests/helpers.mjs
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/sirv-cli.js → tests/sirv-cli.mjs
Original file line number Diff line number Diff line change
@@ -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');

Expand Down
6 changes: 3 additions & 3 deletions tests/sirv.js → tests/sirv.mjs
Original file line number Diff line number Diff line change
@@ -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');

Expand Down

0 comments on commit 2f36733

Please sign in to comment.