1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Description: Fix tests to work with ESM/CJS more properly
They relied on confused pre-nodejs 22 behavior about mixing
CJS/ESM modules.
Author: Jérémy Lal <kapouer@melix.org>
Forwarded: no, dead upstream
Last-Update: 2025-11-21
--- a/bin.js
+++ b/bin.js
@@ -1,7 +1,7 @@
#!/usr/bin/env node
-const sade = require('sade');
-const pkg = require('./package');
-const { parse } = require('./parse');
+import { default as sade} from 'sade';
+import * as pkg from './package.json' with { type: 'json' };
+import { parse } from "uvu/parse";
const dimport = x => new Function(`return import(${ JSON.stringify(x) })`).call(0);
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"bin": {
"uvu": "bin.js"
},
+ "type": "module",
"exports": {
".": {
"types": "./index.d.ts",
--- a/test/assert.js
+++ b/test/assert.js
@@ -1,6 +1,6 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
-import * as $ from '../src/assert';
+import * as $ from '../src/assert.js';
function isError(err, msg, input, expect, operator, details) {
assert.instance(err, Error);
--- a/test/diff.js
+++ b/test/diff.js
@@ -1,6 +1,6 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
-import * as $ from '../src/diff';
+import * as $ from '../src/diff.js';
const isNode8 = process.versions.node.startsWith('8.');
const strip = str => str.replace(/[\u001B\u009B][[\]()#;?]*(?:(?:(?:[a-zA-Z\d]*(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)|(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-ntqry=><~]))/g, '');
--- a/test/parse.js
+++ b/test/parse.js
@@ -2,8 +2,10 @@
import { readdirSync } from 'fs';
import { isAbsolute } from 'path';
import * as assert from 'uvu/assert';
-import * as $ from '../parse';
+import * as $ from 'uvu/parse';
+const __dirname = decodeURIComponent(new URL('.', import.meta.url).pathname.slice(0, -1));
+console.log(__dirname)
const FILES = readdirSync(__dirname);
const parse = suite('parse');
--- a/test/uvu.js
+++ b/test/uvu.js
@@ -1,6 +1,6 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';
-import * as uvu from '../src/index';
+import * as uvu from '../src/index.js';
const ste = suite('suite');
|