Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

test: fix json tests on Windows #74

Merged
merged 9 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions tests/specs/json.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
});
Expand All @@ -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(() => {
Expand All @@ -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"}');
});
});
Expand All @@ -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');
});
});
Expand Down
1 change: 1 addition & 0 deletions tests/utils/node-with-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const nodeWithLoader = (
{
env: {
ESBK_DISABLE_CACHE: '1',
TEST: '1',
...options.env,
},
nodeOptions: [
Expand Down