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

Commit f8bdfec

Browse files
committed
wip
1 parent 6aa91b6 commit f8bdfec

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

src/loaders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
type NodeError,
2323
} from './utils.js';
2424

25-
const isJsonPattern = /\.json($|\?)/;
26-
const isDirectoryPattern = /\/($|\?)/; // Not sure if queries are allowed in directories
25+
const isJsonPattern = /\.json(?:$|\?)/;
26+
const isDirectoryPattern = /\/(?:$|\?)/;
2727

2828
type NextResolve = (
2929
specifier: string,
@@ -109,7 +109,7 @@ async function tryDirectory(
109109
context: ResolveHookContext,
110110
defaultResolve: NextResolve,
111111
) {
112-
const isExplicitDirectory = isDirectoryPattern.test(specifier);//.endsWith('/');
112+
const isExplicitDirectory = isDirectoryPattern.test(specifier);
113113
const appendIndex = isExplicitDirectory ? 'index' : '/index';
114114
const [specifierWithoutQuery, query] = specifier.split('?');
115115

tests/specs/json.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
3131
});
3232

3333
test('Import with query', async () => {
34-
const nodeProcess = await node.importFile(fixture.path, './index.json' + query);
34+
const nodeProcess = await node.importFile(fixture.path, `./index.json${query}`);
3535
expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }');
3636
});
3737
});
@@ -49,13 +49,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
4949
});
5050

5151
test('Import with query', async () => {
52-
const nodeProcess = await node.importFile(fixture.path, './index' + query);
52+
const nodeProcess = await node.importFile(fixture.path, `./index${query}`);
5353
expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }');
5454
});
5555
});
5656

5757
describe('directory', ({ test }) => {
58-
test('Load', async ({ onTestFail }) => {
58+
test('Load', async () => {
5959
const nodeProcess = await node.loadFile(fixture.path, '.');
6060
expect(nodeProcess.exitCode).toBe(0);
6161
expect(nodeProcess.stdout).toBe('');
@@ -66,8 +66,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
6666
expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }');
6767
});
6868

69-
test('Import with query', async ({ onTestFail }) => {
70-
const nodeProcess = await node.importFile(fixture.path, './' + query);
69+
test('Import with query', async () => {
70+
const nodeProcess = await node.importFile(fixture.path, `./${query}`);
7171
expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }');
7272
});
7373
});

tests/specs/typescript/mts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
2929
assertResults(nodeProcess.stdout);
3030
});
3131

32-
test('Import', async ({ onTestFail }) => {
32+
test('Import', async () => {
3333
const nodeProcess = await node.import(importPath + query);
3434
assertResults(nodeProcess.stdout);
3535
expect(nodeProcess.stdout).toMatch('{"default":1234}');

tests/specs/typescript/ts.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
5959
assertResults(nodeProcess.stdout);
6060
expect(nodeProcess.stdout).toMatch('{"default":1234}');
6161
});
62+
63+
test('Import with query', async () => {
64+
const nodeProcess = await node.import(importPath + query, { typescript: true });
65+
assertResults(nodeProcess.stdout);
66+
expect(nodeProcess.stdout).toMatch('{"default":1234}');
67+
});
6268
});
6369

6470
describe('extensionless', ({ test }) => {
@@ -74,6 +80,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
7480
assertResults(nodeProcess.stdout);
7581
expect(nodeProcess.stdout).toMatch('{"default":1234}');
7682
});
83+
84+
test('Import with query', async () => {
85+
const nodeProcess = await node.import(importPath + query, { typescript: true });
86+
assertResults(nodeProcess.stdout);
87+
expect(nodeProcess.stdout).toMatch('{"default":1234}');
88+
});
7789
});
7890

7991
describe('extensionless with subextension', ({ test }) => {
@@ -89,6 +101,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
89101
assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts');
90102
expect(nodeProcess.stdout).toMatch('{"default":1234}');
91103
});
104+
105+
test('Import with query', async () => {
106+
const nodeProcess = await node.import(importPath + query);
107+
assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts');
108+
expect(nodeProcess.stdout).toMatch('{"default":1234}');
109+
});
92110
});
93111

94112
describe('directory', ({ test }) => {
@@ -104,6 +122,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
104122
assertResults(nodeProcess.stdout);
105123
expect(nodeProcess.stdout).toMatch('{"default":1234}');
106124
});
125+
126+
test('Import with query', async () => {
127+
const nodeProcess = await node.import(importPath + query);
128+
assertResults(nodeProcess.stdout);
129+
expect(nodeProcess.stdout).toMatch('{"default":1234}');
130+
});
107131
});
108132

109133
describe('empty directory should fallback to file', ({ test }) => {
@@ -119,6 +143,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
119143
assertResults(nodeProcess.stdout);
120144
expect(nodeProcess.stdout).toMatch('{"default":1234}');
121145
});
146+
147+
test('Import with query', async () => {
148+
const nodeProcess = await node.import(importPath + query);
149+
assertResults(nodeProcess.stdout);
150+
expect(nodeProcess.stdout).toMatch('{"default":1234}');
151+
});
122152
});
123153

124154
describe('empty but explicit directory should not fallback to file', ({ test }) => {
@@ -128,6 +158,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
128158
const nodeProcess = await node.import(importPath);
129159
assertNotFound(nodeProcess.stderr, importPath);
130160
});
161+
162+
test('Import with query', async () => {
163+
const nodeProcess = await node.import(importPath + query);
164+
assertNotFound(nodeProcess.stderr, importPath);
165+
});
131166
});
132167
});
133168
});

0 commit comments

Comments
 (0)