From 6aa91b6910bd398699118f4819708e9d24186d13 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 13:57:54 +0900 Subject: [PATCH 1/9] fix: support query in specifier --- src/loaders.ts | 15 ++++++++++----- src/utils.ts | 2 +- tests/specs/javascript/esm.ts | 14 ++++++++++++++ tests/specs/json.ts | 19 ++++++++++++++++--- tests/specs/typescript/mts.ts | 5 +++-- tests/specs/typescript/ts.ts | 1 + tests/utils/node-with-loader.ts | 1 + tests/utils/query.ts | 1 + 8 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 tests/utils/query.ts diff --git a/src/loaders.ts b/src/loaders.ts index ad41edf..8582d4e 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -22,6 +22,9 @@ import { type NodeError, } from './utils.js'; +const isJsonPattern = /\.json($|\?)/; +const isDirectoryPattern = /\/($|\?)/; // Not sure if queries are allowed in directories + type NextResolve = ( specifier: string, context?: ResolveHookContext, @@ -75,11 +78,12 @@ async function tryExtensions( context: ResolveHookContext, defaultResolve: NextResolve, ) { + const [specifierWithoutQuery, query] = specifier.split('?'); let throwError: Error | undefined; for (const extension of extensions) { try { return await resolve( - specifier + extension, + specifierWithoutQuery + extension + (query ? `?${query}` : ''), context, defaultResolve, true, @@ -105,11 +109,12 @@ async function tryDirectory( context: ResolveHookContext, defaultResolve: NextResolve, ) { - const isExplicitDirectory = specifier.endsWith('/'); + const isExplicitDirectory = isDirectoryPattern.test(specifier);//.endsWith('/'); const appendIndex = isExplicitDirectory ? 'index' : '/index'; + const [specifierWithoutQuery, query] = specifier.split('?'); try { - return await tryExtensions(specifier + appendIndex, context, defaultResolve); + return await tryExtensions(specifierWithoutQuery + appendIndex + (query ? `?${query}` : ''), context, defaultResolve); } catch (_error) { if (!isExplicitDirectory) { try { @@ -145,7 +150,7 @@ export const resolve: resolve = async function ( } // If directory, can be index.js, index.ts, etc. - if (specifier.endsWith('/')) { + if (isDirectoryPattern.test(specifier)) { return await tryDirectory(specifier, context, defaultResolve); } @@ -243,7 +248,7 @@ export const load: LoadHook = async function ( }); } - if (url.endsWith('.json')) { + if (isJsonPattern.test(url)) { if (!context.importAssertions) { context.importAssertions = {}; } diff --git a/src/utils.ts b/src/utils.ts index 7b0e8be..ba73adc 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -25,7 +25,7 @@ export const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig); export const fileProtocol = 'file://'; -export const tsExtensionsPattern = /\.([cm]?ts|[tj]sx)$/; +export const tsExtensionsPattern = /\.([cm]?ts|[tj]sx)($|\?)/; const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => { const extension = path.extname(fileUrl); diff --git a/tests/specs/javascript/esm.ts b/tests/specs/javascript/esm.ts index a147b49..591e480 100644 --- a/tests/specs/javascript/esm.ts +++ b/tests/specs/javascript/esm.ts @@ -4,6 +4,8 @@ import type { NodeApis } from '../../utils/node-with-loader.js'; import nodeSupports from '../../utils/node-supports.js'; import { assertNotFound } from '../../utils/assertions.js'; +const query = '?query=123'; + export default testSuite(async ({ describe }, node: NodeApis) => { describe('Load ESM', ({ describe }) => { describe('.mjs extension', ({ describe }) => { @@ -36,6 +38,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertResults(nodeProcess); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + test('TypeScript Import', async () => { const nodeProcess = await node.import(importPath, { typescript: true }); assertResults(nodeProcess); @@ -101,6 +109,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertResults(nodeProcess); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('extensionless', ({ test }) => { diff --git a/tests/specs/json.ts b/tests/specs/json.ts index 4e30692..e322830 100644 --- a/tests/specs/json.ts +++ b/tests/specs/json.ts @@ -1,6 +1,7 @@ import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../utils/node-with-loader.js'; +import { query } from '../utils/query.js'; const jsonFixture = { 'package.json': JSON.stringify({ @@ -28,6 +29,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.importFile(fixture.path, './index.json'); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); + + test('Import with query', async () => { + const nodeProcess = await node.importFile(fixture.path, './index.json' + query); + expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + }); }); describe('extensionless', ({ test }) => { @@ -41,14 +47,16 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.importFile(fixture.path, './index'); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); + + test('Import with query', async () => { + const nodeProcess = await node.importFile(fixture.path, './index' + query); + expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + }); }); describe('directory', ({ test }) => { test('Load', async ({ onTestFail }) => { const nodeProcess = await node.loadFile(fixture.path, '.'); - onTestFail(() => { - console.log(nodeProcess); - }); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); }); @@ -57,6 +65,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.importFile(fixture.path, '.'); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); + + test('Import with query', async ({ onTestFail }) => { + const nodeProcess = await node.importFile(fixture.path, './' + query); + expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + }); }); describe('ambiguous path', async ({ describe, onFinish }) => { diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 95b91f4..3c033ab 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -3,6 +3,7 @@ import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader.js'; import nodeSupports from '../../utils/node-supports.js'; import { assertNotFound } from '../../utils/assertions.js'; +import { query } from '../../utils/query.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.mts extension', ({ describe }) => { @@ -28,8 +29,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); }); - test('Import', async () => { - const nodeProcess = await node.import(importPath); + test('Import', async ({ onTestFail }) => { + const nodeProcess = await node.import(importPath + query); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 7d9ba59..96bbeb8 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -3,6 +3,7 @@ import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader.js'; import nodeSupports from '../../utils/node-supports.js'; import { assertNotFound } from '../../utils/assertions.js'; +import { query } from '../../utils/query.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.ts extension', ({ describe }) => { diff --git a/tests/utils/node-with-loader.ts b/tests/utils/node-with-loader.ts index b59985f..e321846 100644 --- a/tests/utils/node-with-loader.ts +++ b/tests/utils/node-with-loader.ts @@ -36,6 +36,7 @@ export const nodeWithLoader = ( nodePath: options.nodePath, cwd: options.cwd, reject: false, + all: true, }, ); diff --git a/tests/utils/query.ts b/tests/utils/query.ts new file mode 100644 index 0000000..cf4ef6b --- /dev/null +++ b/tests/utils/query.ts @@ -0,0 +1 @@ +export const query = '?query=123'; From f8bdfec4a49761cdadf77758b58c5da7fe1bcea5 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 14:09:46 +0900 Subject: [PATCH 2/9] wip --- src/loaders.ts | 6 +++--- tests/specs/json.ts | 10 +++++----- tests/specs/typescript/mts.ts | 2 +- tests/specs/typescript/ts.ts | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/loaders.ts b/src/loaders.ts index 8582d4e..78aed31 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -22,8 +22,8 @@ import { type NodeError, } from './utils.js'; -const isJsonPattern = /\.json($|\?)/; -const isDirectoryPattern = /\/($|\?)/; // Not sure if queries are allowed in directories +const isJsonPattern = /\.json(?:$|\?)/; +const isDirectoryPattern = /\/(?:$|\?)/; type NextResolve = ( specifier: string, @@ -109,7 +109,7 @@ async function tryDirectory( context: ResolveHookContext, defaultResolve: NextResolve, ) { - const isExplicitDirectory = isDirectoryPattern.test(specifier);//.endsWith('/'); + const isExplicitDirectory = isDirectoryPattern.test(specifier); const appendIndex = isExplicitDirectory ? 'index' : '/index'; const [specifierWithoutQuery, query] = specifier.split('?'); diff --git a/tests/specs/json.ts b/tests/specs/json.ts index e322830..5f1eb48 100644 --- a/tests/specs/json.ts +++ b/tests/specs/json.ts @@ -31,7 +31,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import with query', async () => { - const nodeProcess = await node.importFile(fixture.path, './index.json' + query); + const nodeProcess = await node.importFile(fixture.path, `./index.json${query}`); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); }); @@ -49,13 +49,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import with query', async () => { - const nodeProcess = await node.importFile(fixture.path, './index' + query); + const nodeProcess = await node.importFile(fixture.path, `./index${query}`); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); }); describe('directory', ({ test }) => { - test('Load', async ({ onTestFail }) => { + test('Load', async () => { const nodeProcess = await node.loadFile(fixture.path, '.'); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); @@ -66,8 +66,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); - test('Import with query', async ({ onTestFail }) => { - const nodeProcess = await node.importFile(fixture.path, './' + query); + test('Import with query', async () => { + const nodeProcess = await node.importFile(fixture.path, `./${query}`); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); }); diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 3c033ab..a6de65b 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -29,7 +29,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); }); - test('Import', async ({ onTestFail }) => { + test('Import', async () => { const nodeProcess = await node.import(importPath + query); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 96bbeb8..fed1a15 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -59,6 +59,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query, { typescript: true }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('extensionless', ({ test }) => { @@ -74,6 +80,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query, { typescript: true }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('extensionless with subextension', ({ test }) => { @@ -89,6 +101,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('directory', ({ test }) => { @@ -104,6 +122,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('empty directory should fallback to file', ({ test }) => { @@ -119,6 +143,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('empty but explicit directory should not fallback to file', ({ test }) => { @@ -128,6 +158,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.import(importPath); assertNotFound(nodeProcess.stderr, importPath); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertNotFound(nodeProcess.stderr, importPath); + }); }); }); }); From c1a78bab8ab92f91c57366b2b7498f2d6ff6ae98 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:35:41 +0900 Subject: [PATCH 3/9] wip --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 59dc9e2..1888706 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "prepack": "pnpm build && clean-pkg-json" }, "dependencies": { - "@esbuild-kit/core-utils": "^3.3.0", + "@esbuild-kit/core-utils": "^3.3.2", "get-tsconfig": "^4.7.0" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f62389c..0e5db45 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@esbuild-kit/core-utils': - specifier: ^3.3.0 - version: 3.3.0 + specifier: ^3.3.2 + version: 3.3.2 get-tsconfig: specifier: ^4.7.0 version: 4.7.0 @@ -113,8 +113,8 @@ packages: js-tokens: 4.0.0 dev: true - /@esbuild-kit/core-utils@3.3.0: - resolution: {integrity: sha512-jTtSvVpr5ygNXyPXf9IBbCrKQ0uckq6vWkcGfy1fEr9KjkKdnFn4kFAGjpqZDZim1wsTwh/Be+lhAUemEmxEYA==} + /@esbuild-kit/core-utils@3.3.2: + resolution: {integrity: sha512-sPRAnw9CdSsRmEtnsl2WXWdyquogVpB3yZ3dgwJfe8zrOzTsV7cJvmwrKVa+0ma5BoiGJ+BoqkMvawbayKUsqQ==} dependencies: esbuild: 0.18.20 source-map-support: 0.5.21 From 8e058c675b794b25c24f18a8f847ee84a8b82591 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:37:46 +0900 Subject: [PATCH 4/9] wip --- tests/specs/javascript/esm.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/specs/javascript/esm.ts b/tests/specs/javascript/esm.ts index 591e480..50ea299 100644 --- a/tests/specs/javascript/esm.ts +++ b/tests/specs/javascript/esm.ts @@ -3,8 +3,7 @@ import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader.js'; import nodeSupports from '../../utils/node-supports.js'; import { assertNotFound } from '../../utils/assertions.js'; - -const query = '?query=123'; +import { query } from '../../utils/query.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('Load ESM', ({ describe }) => { From fa634d76cab9ec1ad693026b55ecd60091408ce4 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:39:41 +0900 Subject: [PATCH 5/9] wip --- tests/specs/typescript/mts.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index a6de65b..f6339fd 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -30,6 +30,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + + test('Import with query', async () => { const nodeProcess = await node.import(importPath + query); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); @@ -49,6 +55,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query, { typescript: true }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); describe('extensionless - should not work', ({ test }) => { @@ -63,6 +75,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.import(importPath); assertNotFound(nodeProcess.stderr, importPath); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertNotFound(nodeProcess.stderr, importPath); + }); }); describe('directory - should not work', ({ test }) => { @@ -77,6 +94,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const nodeProcess = await node.import(importPath); assertNotFound(nodeProcess.stderr, importPath); }); + + test('Import with query', async () => { + const nodeProcess = await node.import(importPath + query); + assertNotFound(nodeProcess.stderr, importPath); + }); }); }); }); From ee910582b503d31a64b9d93505b3905f480ddf04 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:56:58 +0900 Subject: [PATCH 6/9] wip --- src/loaders-deprecated.ts | 5 +++-- src/loaders.ts | 2 +- src/utils.ts | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/loaders-deprecated.ts b/src/loaders-deprecated.ts index f8a2afd..e60d1e8 100644 --- a/src/loaders-deprecated.ts +++ b/src/loaders-deprecated.ts @@ -17,6 +17,7 @@ import { tsExtensionsPattern, getFormatFromFileUrl, fileProtocol, + isJsonPattern, type MaybePromise, type NodeError, } from './utils.js'; @@ -32,7 +33,7 @@ const _getFormat: getFormat = async function ( context, defaultGetFormat, ) { - if (url.endsWith('.json')) { + if (isJsonPattern.test(url)) { return { format: 'module' }; } @@ -80,7 +81,7 @@ const _transformSource: transformSource = async function ( } if ( - url.endsWith('.json') + isJsonPattern.test(url) || tsExtensionsPattern.test(url) ) { const transformed = await transform( diff --git a/src/loaders.ts b/src/loaders.ts index 78aed31..a587682 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -16,13 +16,13 @@ import { tsconfigPathsMatcher, fileMatcher, tsExtensionsPattern, + isJsonPattern, getFormatFromFileUrl, fileProtocol, type MaybePromise, type NodeError, } from './utils.js'; -const isJsonPattern = /\.json(?:$|\?)/; const isDirectoryPattern = /\/(?:$|\?)/; type NextResolve = ( diff --git a/src/utils.ts b/src/utils.ts index ba73adc..d34f7d4 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -27,6 +27,8 @@ export const fileProtocol = 'file://'; export const tsExtensionsPattern = /\.([cm]?ts|[tj]sx)($|\?)/; +export const isJsonPattern = /\.json(?:$|\?)/; + const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => { const extension = path.extname(fileUrl); From e6faea45a9091b281a21b49b2e35985e24632b6c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:47:49 +0900 Subject: [PATCH 7/9] wip --- tests/index.ts | 60 +++++++++--------- tests/specs/json.ts | 151 ++++++++++++++++++++++---------------------- 2 files changed, 106 insertions(+), 105 deletions(-) diff --git a/tests/index.ts b/tests/index.ts index 1711bcf..ff050c3 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,7 +2,7 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - '20', + // '20', ...( ( process.env.CI @@ -10,11 +10,11 @@ const nodeVersions = [ ) ? [ '12.20.0', // CJS named export detection added - '12', - '14', - '16', - '17', - '18', + // '12', + // '14', + // '16', + // '17', + // '18', ] : [] ), @@ -26,36 +26,36 @@ const nodeVersions = [ describe('Package: module', async ({ runTestSuite }) => { const node = await createNode(nodeVersion, './tests/fixtures/package-module'); - runTestSuite( - import('./specs/javascript/index.js'), - node, - ); - runTestSuite( - import('./specs/typescript/index.js'), - node, - ); + // runTestSuite( + // import('./specs/javascript/index.js'), + // node, + // ); + // runTestSuite( + // import('./specs/typescript/index.js'), + // node, + // ); runTestSuite( import('./specs/json.js'), node, ); - runTestSuite( - import('./specs/wasm.js'), - node, - ); - runTestSuite( - import('./specs/data.js'), - node, - ); - runTestSuite( - import('./specs/import-map.js'), - node, - ); + // runTestSuite( + // import('./specs/wasm.js'), + // node, + // ); + // runTestSuite( + // import('./specs/data.js'), + // node, + // ); + // runTestSuite( + // import('./specs/import-map.js'), + // node, + // ); }); - runTestSuite( - import('./specs/package-cjs.js'), - await createNode(nodeVersion, './tests/fixtures/package-commonjs'), - ); + // runTestSuite( + // import('./specs/package-cjs.js'), + // await createNode(nodeVersion, './tests/fixtures/package-commonjs'), + // ); }); } })(); diff --git a/tests/specs/json.ts b/tests/specs/json.ts index 5f1eb48..7cacaa8 100644 --- a/tests/specs/json.ts +++ b/tests/specs/json.ts @@ -19,88 +19,89 @@ export default testSuite(async ({ describe }, node: NodeApis) => { onFinish(async () => await fixture.rm()); describe('full path', ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, './index.json'); - expect(nodeProcess.exitCode).toBe(0); - expect(nodeProcess.stdout).toBe(''); - }); + // test('Load', async () => { + // const nodeProcess = await node.loadFile(fixture.path, './index.json'); + // expect(nodeProcess.exitCode).toBe(0); + // expect(nodeProcess.stdout).toBe(''); + // }); - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index.json'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); + // test('Import', async () => { + // const nodeProcess = await node.importFile(fixture.path, './index.json'); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); test('Import with query', async () => { const nodeProcess = await node.importFile(fixture.path, `./index.json${query}`); + console.log(nodeProcess); expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); }); }); - describe('extensionless', ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, './index'); - expect(nodeProcess.exitCode).toBe(0); - expect(nodeProcess.stdout).toBe(''); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); - - test('Import with query', async () => { - const nodeProcess = await node.importFile(fixture.path, `./index${query}`); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); - }); - - describe('directory', ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, '.'); - expect(nodeProcess.exitCode).toBe(0); - expect(nodeProcess.stdout).toBe(''); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, '.'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); - - test('Import with query', async () => { - const nodeProcess = await node.importFile(fixture.path, `./${query}`); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); - }); - - describe('ambiguous path', async ({ describe, onFinish }) => { - const fixture = await createFixture({ - ...jsonFixture, - index: { - file: '', - }, - }); - - onFinish(async () => await fixture.rm()); - - describe('ambiguous path to directory should fallback to file', async ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, './index'); - expect(nodeProcess.exitCode).toBe(0); - expect(nodeProcess.stdout).toBe(''); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - }); - }); - - describe('explicit directory should not fallback to file', ({ test }) => { - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index/'); - expect(nodeProcess.stderr).toMatch('ERR_MODULE_NOT_FOUND'); - }); - }); - }); + // describe('extensionless', ({ test }) => { + // test('Load', async () => { + // const nodeProcess = await node.loadFile(fixture.path, './index'); + // expect(nodeProcess.exitCode).toBe(0); + // expect(nodeProcess.stdout).toBe(''); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.importFile(fixture.path, './index'); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); + + // test('Import with query', async () => { + // const nodeProcess = await node.importFile(fixture.path, `./index${query}`); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); + // }); + + // describe('directory', ({ test }) => { + // test('Load', async () => { + // const nodeProcess = await node.loadFile(fixture.path, '.'); + // expect(nodeProcess.exitCode).toBe(0); + // expect(nodeProcess.stdout).toBe(''); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.importFile(fixture.path, '.'); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); + + // test('Import with query', async () => { + // const nodeProcess = await node.importFile(fixture.path, `./${query}`); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); + // }); + + // describe('ambiguous path', async ({ describe, onFinish }) => { + // const fixture = await createFixture({ + // ...jsonFixture, + // index: { + // file: '', + // }, + // }); + + // onFinish(async () => await fixture.rm()); + + // describe('ambiguous path to directory should fallback to file', async ({ test }) => { + // test('Load', async () => { + // const nodeProcess = await node.loadFile(fixture.path, './index'); + // expect(nodeProcess.exitCode).toBe(0); + // expect(nodeProcess.stdout).toBe(''); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.importFile(fixture.path, './index'); + // expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); + // }); + // }); + + // describe('explicit directory should not fallback to file', ({ test }) => { + // test('Import', async () => { + // const nodeProcess = await node.importFile(fixture.path, './index/'); + // expect(nodeProcess.stderr).toMatch('ERR_MODULE_NOT_FOUND'); + // }); + // }); + // }); }); }); From 152dd3b98b0d7a7fe8e44e4eb8f0726da3b605df Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:49:51 +0900 Subject: [PATCH 8/9] wip --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64530c7..d0b751a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,6 @@ on: push: branches: [develop] pull_request: - branches: [master, develop, next] jobs: test: From cd190d334ba005ba4435a4fab79d7a01eec825b6 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 17 Sep 2023 15:51:29 +0900 Subject: [PATCH 9/9] wip --- .github/workflows/test.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0b751a..ce42c96 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] timeout-minutes: 10 steps: - name: Checkout @@ -27,13 +27,5 @@ jobs: version: 8 run_install: true - - name: Lint - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm lint - - - name: Type check - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm type-check - - name: Test run: pnpm test