diff --git a/tests/specs/json.ts b/tests/specs/json.ts index b09dd7f..4f4d34c 100644 --- a/tests/specs/json.ts +++ b/tests/specs/json.ts @@ -1,4 +1,5 @@ import path from 'path'; +import { pathToFileURL } from 'url'; import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../utils/node-with-loader.js'; @@ -20,30 +21,30 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('full path', ({ test }) => { const importPath = path.join(fixture.path, 'index.json'); - test('Load', async () => { const nodeProcess = await node.load(importPath); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); }); + const importUrl = pathToFileURL(importPath).toString(); test('Import', async () => { - const nodeProcess = await node.import(importPath); + const nodeProcess = await node.import(importUrl); expect(nodeProcess.stdout).toMatch('{"default":{"loaded":"json"},"loaded":"json"}'); }); }); describe('extensionless', ({ test }) => { const importPath = path.join(fixture.path, 'index'); - test('Load', async () => { const nodeProcess = await node.load(importPath); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); }); + const importUrl = pathToFileURL(importPath).toString(); test('Import', async ({ onTestFail }) => { - const nodeProcess = await node.import(importPath); + const nodeProcess = await node.import(importUrl); onTestFail(() => { console.log(nodeProcess); }); @@ -53,7 +54,6 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('directory', ({ test }) => { const importPath = fixture.path; - test('Load', async ({ onTestFail }) => { const nodeProcess = await node.load(importPath); onTestFail(() => { @@ -63,8 +63,9 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toBe(''); }); + const importUrl = pathToFileURL(importPath).toString(); test('Import', async () => { - const nodeProcess = await node.import(importPath); + const nodeProcess = await node.import(importUrl); expect(nodeProcess.stdout).toMatch('{"default":{"loaded":"json"},"loaded":"json"}'); }); }); @@ -81,24 +82,24 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('ambiguous path to directory should fallback to file', async ({ test }) => { const importPath = path.join(fixture.path, 'index'); - test('Load', async () => { const nodeProcess = await node.load(importPath); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); }); + const importUrl = pathToFileURL(importPath).toString(); test('Import', async () => { - const nodeProcess = await node.import(importPath); + const nodeProcess = await node.import(importUrl); expect(nodeProcess.stdout).toMatch('{"default":{"loaded":"json"},"loaded":"json"}'); }); }); describe('explicit directory should not fallback to file', ({ test }) => { - const importPath = path.join(fixture.path, 'index/'); + const importUrl = pathToFileURL(path.join(fixture.path, 'index/')).toString(); test('Import', async () => { - const nodeProcess = await node.import(importPath); + const nodeProcess = await node.import(importUrl); expect(nodeProcess.stderr).toMatch('ERR_MODULE_NOT_FOUND'); }); }); diff --git a/tests/utils/node-with-loader.ts b/tests/utils/node-with-loader.ts index ee537d5..7772b5a 100644 --- a/tests/utils/node-with-loader.ts +++ b/tests/utils/node-with-loader.ts @@ -21,6 +21,7 @@ export const nodeWithLoader = ( { env: { ESBK_DISABLE_CACHE: '1', + TEST: '1', ...options.env, }, nodeOptions: [