From 1df22cf7d6c08720d96520c48115e0d3d2f28bfc Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 9 Feb 2023 08:20:01 +0900 Subject: [PATCH 01/31] wip --- src/loaders.ts | 13 ++- tests/index.ts | 40 ++++----- tests/specs/typescript/cts.ts | 140 +++++++++++++++++++++----------- tests/specs/typescript/index.ts | 12 +-- 4 files changed, 131 insertions(+), 74 deletions(-) diff --git a/src/loaders.ts b/src/loaders.ts index 0a0825a..8f1d22b 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -137,7 +137,18 @@ export const resolve: resolve = async function ( /** * Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions */ - if (tsExtensionsPattern.test(context.parentURL!)) { + if (context.parentURL) { + const filePath = fileURLToPath(context.parentURL!); + console.log({ + filePath, + matches: Boolean(fileMatcher?.(filePath)), + specifier, + }); + } + if ( + context.parentURL + && fileMatcher?.(fileURLToPath(context.parentURL)) + ) { const tsPath = resolveTsPath(specifier); if (tsPath) { diff --git a/tests/index.ts b/tests/index.ts index 657d0ac..8ad8752 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -22,30 +22,30 @@ const nodeVersions = [ describe('Package: module', async ({ runTestSuite }) => { const node = await createNode(nodeVersion, './tests/fixtures/package-module'); - runTestSuite( - import('./specs/javascript'), - node, - ); + // runTestSuite( + // import('./specs/javascript'), + // node, + // ); runTestSuite( import('./specs/typescript'), node, ); - runTestSuite( - import('./specs/json'), - node, - ); - runTestSuite( - import('./specs/wasm'), - node, - ); - runTestSuite( - import('./specs/data'), - node, - ); - runTestSuite( - import('./specs/import-map'), - node, - ); + // runTestSuite( + // import('./specs/json'), + // node, + // ); + // runTestSuite( + // import('./specs/wasm'), + // node, + // ); + // runTestSuite( + // import('./specs/data'), + // node, + // ); + // runTestSuite( + // import('./specs/import-map'), + // node, + // ); }); runTestSuite( diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index 5569a87..48b4d46 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -1,69 +1,115 @@ +import fs from 'fs/promises'; +import path from 'path'; import { testSuite, expect } from 'manten'; +import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../../utils/node-with-loader'; import { assertNotFound } from '../../utils/assertions'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.cts extension', ({ describe }) => { - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-cts/index.cts'; + // describe('full path', ({ test }) => { + // const importPath = './lib/ts-ext-cts/index.cts'; - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.exitCode).toBe(1); + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // expect(nodeProcess.exitCode).toBe(1); - /** - * Since .cts compiles to CJS and can use features like __dirname, - * it must be compiled by the CJS loader - */ - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); - }); + // /** + // * Since .cts compiles to CJS and can use features like __dirname, + // * it must be compiled by the CJS loader + // */ + // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + // }); - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); - }); - }); + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + // }); + // }); - describe('full path via .cjs', ({ test }) => { - const importPath = './lib/ts-ext-cts/index.cjs'; + describe('full path via .cjs', async ({ describe }) => { + const ctsFile = './tests/fixtures/package-module/lib/ts-ext-cts/index.cts'; - test('Load - should not work', async () => { - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); + // describe('with allowJs', async ({ test }) => { + // const fixture = await createFixture({ + // 'index.mts': 'import "./file.cjs";', + // 'file.cts': await fs.readFile(ctsFile, 'utf8'), + // 'tsconfig.json': JSON.stringify({ + // compilerOptions: { + // allowJs: true, + // }, + // }), + // }); + + // test('Load - should not work', async () => { + // const importPath = path.join(fixture.path, 'file.cjs'); + // const nodeProcess = await node.load(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('index.mts', { + // cwd: fixture.path, + // }); + // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + // }); + // }); - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + describe('without allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import "./file.cjs";', + 'file.cts': await fs.readFile(ctsFile, 'utf8'), + // 'tsconfig.json': JSON.stringify({ + // compilerOptions: { + // allowJs: true, + // }, + // }), + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.cjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + // Shouldnt a type script file be able to resolve the cjs file?? + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + console.log(nodeProcess); + expect(nodeProcess.stderr).toMatch(/Cannot find module \'.+\.cjs'/); + }); }); }); - describe('extensionless - should not work', ({ test }) => { - const importPath = './lib/ts-ext-cts/index'; - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); + // describe('extensionless - should not work', ({ test }) => { + // const importPath = './lib/ts-ext-cts/index'; - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); - }); + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); - describe('directory - should not work', ({ test }) => { - const importPath = './lib/ts-ext-cts'; + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); + // }); - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); + // describe('directory - should not work', ({ test }) => { + // const importPath = './lib/ts-ext-cts'; - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); - }); + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); + // }); }); }); diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts index e18bf9f..224ed3e 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -3,12 +3,12 @@ import type { NodeApis } from '../../utils/node-with-loader'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { - runTestSuite(import('./ts'), node); - runTestSuite(import('./tsx'), node); - runTestSuite(import('./jsx'), node); - runTestSuite(import('./mts'), node); + // runTestSuite(import('./ts'), node); + // runTestSuite(import('./tsx'), node); + // runTestSuite(import('./jsx'), node); + // runTestSuite(import('./mts'), node); runTestSuite(import('./cts'), node); - runTestSuite(import('./tsconfig'), node); - runTestSuite(import('./dependencies'), node); + // runTestSuite(import('./tsconfig'), node); + // runTestSuite(import('./dependencies'), node); }); }); From 82a55f534bd8ec3173060f0033c1ea8a48007d99 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 10:57:36 +0900 Subject: [PATCH 02/31] wip --- src/loaders.ts | 8 -- src/utils.ts | 8 +- tests/index.ts | 40 ++++---- tests/specs/typescript/cts.ts | 169 +++++++++++++++++--------------- tests/specs/typescript/index.ts | 12 +-- 5 files changed, 124 insertions(+), 113 deletions(-) diff --git a/src/loaders.ts b/src/loaders.ts index 8f1d22b..1181733 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -137,14 +137,6 @@ export const resolve: resolve = async function ( /** * Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions */ - if (context.parentURL) { - const filePath = fileURLToPath(context.parentURL!); - console.log({ - filePath, - matches: Boolean(fileMatcher?.(filePath)), - specifier, - }); - } if ( context.parentURL && fileMatcher?.(fileURLToPath(context.parentURL)) diff --git a/src/utils.ts b/src/utils.ts index 07dc487..c5331a3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -16,7 +16,13 @@ const tsconfig = ( path: path.resolve(process.env.ESBK_TSCONFIG_PATH), config: parseTsconfig(process.env.ESBK_TSCONFIG_PATH), } - : getTsconfig() + : ( + getTsconfig() + ?? { + path: process.cwd(), + config: {}, + } + ) ); export const fileMatcher = tsconfig && createFilesMatcher(tsconfig); diff --git a/tests/index.ts b/tests/index.ts index 8ad8752..657d0ac 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -22,30 +22,30 @@ const nodeVersions = [ describe('Package: module', async ({ runTestSuite }) => { const node = await createNode(nodeVersion, './tests/fixtures/package-module'); - // runTestSuite( - // import('./specs/javascript'), - // node, - // ); + runTestSuite( + import('./specs/javascript'), + node, + ); runTestSuite( import('./specs/typescript'), node, ); - // runTestSuite( - // import('./specs/json'), - // node, - // ); - // runTestSuite( - // import('./specs/wasm'), - // node, - // ); - // runTestSuite( - // import('./specs/data'), - // node, - // ); - // runTestSuite( - // import('./specs/import-map'), - // node, - // ); + runTestSuite( + import('./specs/json'), + node, + ); + runTestSuite( + import('./specs/wasm'), + node, + ); + runTestSuite( + import('./specs/data'), + node, + ); + runTestSuite( + import('./specs/import-map'), + node, + ); }); runTestSuite( diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index 48b4d46..f3a9abf 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -7,109 +7,122 @@ import { assertNotFound } from '../../utils/assertions'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.cts extension', ({ describe }) => { - // describe('full path', ({ test }) => { - // const importPath = './lib/ts-ext-cts/index.cts'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // expect(nodeProcess.exitCode).toBe(1); - - // /** - // * Since .cts compiles to CJS and can use features like __dirname, - // * it must be compiled by the CJS loader - // */ - // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); - // }); - // }); + describe('full path', ({ test }) => { + const importPath = './lib/ts-ext-cts/index.cts'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + expect(nodeProcess.exitCode).toBe(1); + + /** + * Since .cts compiles to CJS and can use features like __dirname, + * it must be compiled by the CJS loader + */ + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + }); + }); describe('full path via .cjs', async ({ describe }) => { const ctsFile = './tests/fixtures/package-module/lib/ts-ext-cts/index.cts'; - // describe('with allowJs', async ({ test }) => { - // const fixture = await createFixture({ - // 'index.mts': 'import "./file.cjs";', - // 'file.cts': await fs.readFile(ctsFile, 'utf8'), - // 'tsconfig.json': JSON.stringify({ - // compilerOptions: { - // allowJs: true, - // }, - // }), - // }); - - // test('Load - should not work', async () => { - // const importPath = path.join(fixture.path, 'file.cjs'); - // const nodeProcess = await node.load(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('index.mts', { - // cwd: fixture.path, - // }); - // expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); - // }); - // }); - - describe('without allowJs', async ({ test }) => { + describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ 'index.mts': 'import "./file.cjs";', 'file.cts': await fs.readFile(ctsFile, 'utf8'), - // 'tsconfig.json': JSON.stringify({ - // compilerOptions: { - // allowJs: true, - // }, - // }), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), }); - + test('Load - should not work', async () => { const importPath = path.join(fixture.path, 'file.cjs'); const nodeProcess = await node.load(importPath); assertNotFound(nodeProcess.stderr, importPath); }); - + test('Import', async () => { - // Shouldnt a type script file be able to resolve the cjs file?? const nodeProcess = await node.load('index.mts', { cwd: fixture.path, }); - console.log(nodeProcess); - expect(nodeProcess.stderr).toMatch(/Cannot find module \'.+\.cjs'/); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); }); - }); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import "./file.cjs";', + 'file.cts': await fs.readFile(ctsFile, 'utf8'), + 'tsconfig.json': '{}', + }); - // describe('extensionless - should not work', ({ test }) => { - // const importPath = './lib/ts-ext-cts/index'; + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.cjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + }); + }); - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); - // }); + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import "./file.cjs";', + 'file.cts': await fs.readFile(ctsFile, 'utf8'), + }); - // describe('directory - should not work', ({ test }) => { - // const importPath = './lib/ts-ext-cts'; + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.cjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + }); + }); + }); + + describe('extensionless - should not work', ({ test }) => { + const importPath = './lib/ts-ext-cts/index'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + }); + + describe('directory - should not work', ({ test }) => { + const importPath = './lib/ts-ext-cts'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); - // }); + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + }); }); }); diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts index 224ed3e..e18bf9f 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -3,12 +3,12 @@ import type { NodeApis } from '../../utils/node-with-loader'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { - // runTestSuite(import('./ts'), node); - // runTestSuite(import('./tsx'), node); - // runTestSuite(import('./jsx'), node); - // runTestSuite(import('./mts'), node); + runTestSuite(import('./ts'), node); + runTestSuite(import('./tsx'), node); + runTestSuite(import('./jsx'), node); + runTestSuite(import('./mts'), node); runTestSuite(import('./cts'), node); - // runTestSuite(import('./tsconfig'), node); - // runTestSuite(import('./dependencies'), node); + runTestSuite(import('./tsconfig'), node); + runTestSuite(import('./dependencies'), node); }); }); From 12625ecbf65667c1bc1bbde966926664add95a9d Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 11:28:40 +0900 Subject: [PATCH 03/31] wip --- tests/specs/typescript/mts.ts | 79 +++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 7c7900b..1fede68 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -1,4 +1,7 @@ +import fs from 'fs/promises'; +import path from 'path'; import { testSuite, expect } from 'manten'; +import { createFixture } from 'fs-fixture'; import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader'; import nodeSupports from '../../utils/node-supports'; @@ -35,18 +38,76 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('full path via .mjs', ({ test }) => { - const importPath = './lib/ts-ext-mts/index.mjs'; + describe('full path via .mjs', async ({ describe }) => { + const mtsFile = './tests/fixtures/package-module/lib/ts-ext-mts/index.mts'; - test('Load - should not work', async () => { - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)));', + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.mjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)))', + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.mjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)))', + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.mjs'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); }); From b2620621028d374bf821cb05488e022185b9877b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 11:42:12 +0900 Subject: [PATCH 04/31] wip --- tests/specs/typescript/ts.ts | 84 ++++++++++++++++++++++++++++++++---- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 9a9c263..ab0553b 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -1,9 +1,14 @@ +import fs from 'fs/promises'; +import path from 'path'; import { testSuite, expect } from 'manten'; +import { createFixture } from 'fs-fixture'; import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader'; import nodeSupports from '../../utils/node-supports'; import { assertNotFound } from '../../utils/assertions'; +const importAndLog = (specifier: string) => `import("${specifier}").then(m => console.log(JSON.stringify(m)))`; + export default testSuite(async ({ describe }, node: NodeApis) => { describe('.ts extension', ({ describe }) => { function assertResults(stdout: string, filename = 'ts-ext-ts/index.ts') { @@ -45,18 +50,79 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('full path via .js', ({ test }) => { - const importPath = './lib/ts-ext-ts/index.js'; + describe('full path via .js', async ({ describe }) => { + const tsFile = './tests/fixtures/package-module/lib/ts-ext-ts/index.ts'; + + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'index.ts': importAndLog('./file.js'), + 'file.ts': await fs.readFile(tsFile, 'utf8'), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.js'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'index.ts': importAndLog('./file.js'), + 'file.ts': await fs.readFile(tsFile, 'utf8'), + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.js'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'index.ts': importAndLog('./file.js'), + 'file.ts': await fs.readFile(tsFile, 'utf8'), + }); + + test('Load - should not work', async () => { + const importPath = path.join(fixture.path, 'file.js'); + const nodeProcess = await node.load(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); }); From 948c9fb3e3c6aa0a89ad11c7bfee1d1a14996bc8 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 11:47:26 +0900 Subject: [PATCH 05/31] wip --- tests/specs/typescript/cts.ts | 7 ++++--- tests/specs/typescript/mts.ts | 7 ++++--- tests/specs/typescript/ts.ts | 3 +-- tests/utils/fixtures.ts | 1 + 4 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 tests/utils/fixtures.ts diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index f3a9abf..c00735a 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -4,6 +4,7 @@ import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../../utils/node-with-loader'; import { assertNotFound } from '../../utils/assertions'; +import { importAndLog } from '../../utils/fixtures'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.cts extension', ({ describe }) => { @@ -32,7 +33,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import "./file.cjs";', + 'index.mts': importAndLog('./file.cjs'), 'file.cts': await fs.readFile(ctsFile, 'utf8'), 'tsconfig.json': JSON.stringify({ compilerOptions: { @@ -57,7 +58,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import "./file.cjs";', + 'index.mts': importAndLog('./file.cjs'), 'file.cts': await fs.readFile(ctsFile, 'utf8'), 'tsconfig.json': '{}', }); @@ -78,7 +79,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import "./file.cjs";', + 'index.mts': importAndLog('./file.cjs'), 'file.cts': await fs.readFile(ctsFile, 'utf8'), }); diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 1fede68..dc4a2f0 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -6,6 +6,7 @@ import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader'; import nodeSupports from '../../utils/node-supports'; import { assertNotFound } from '../../utils/assertions'; +import { importAndLog } from '../../utils/fixtures'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.mts extension', ({ describe }) => { @@ -43,7 +44,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)));', + 'index.mts': importAndLog('./file.mjs'), 'file.mts': await fs.readFile(mtsFile, 'utf8'), 'tsconfig.json': JSON.stringify({ compilerOptions: { @@ -69,7 +70,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)))', + 'index.mts': importAndLog('./file.mjs'), 'file.mts': await fs.readFile(mtsFile, 'utf8'), 'tsconfig.json': '{}', }); @@ -91,7 +92,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': 'import("./file.mjs").then(m => console.log(JSON.stringify(m)))', + 'index.mts': importAndLog('./file.mjs'), 'file.mts': await fs.readFile(mtsFile, 'utf8'), }); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index ab0553b..a4b7320 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -6,8 +6,7 @@ import semver from 'semver'; import type { NodeApis } from '../../utils/node-with-loader'; import nodeSupports from '../../utils/node-supports'; import { assertNotFound } from '../../utils/assertions'; - -const importAndLog = (specifier: string) => `import("${specifier}").then(m => console.log(JSON.stringify(m)))`; +import { importAndLog } from '../../utils/fixtures'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.ts extension', ({ describe }) => { diff --git a/tests/utils/fixtures.ts b/tests/utils/fixtures.ts new file mode 100644 index 0000000..7ae82ea --- /dev/null +++ b/tests/utils/fixtures.ts @@ -0,0 +1 @@ +export const importAndLog = (specifier: string) => `import("${specifier}").then(m => console.log(JSON.stringify(m)))`; From de68642140b4c252809dda9c4cee7e67594c7f0f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 11:54:36 +0900 Subject: [PATCH 06/31] wip --- tests/specs/typescript/cts.ts | 21 ++++++++++++--------- tests/specs/typescript/mts.ts | 21 ++++++++++++--------- tests/specs/typescript/ts.ts | 21 ++++++++++++--------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index c00735a..ea9ee3f 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -43,9 +43,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.cjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); test('Import', async () => { @@ -64,9 +65,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.cjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); test('Import', async () => { @@ -84,9 +86,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.cjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); test('Import', async () => { diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index dc4a2f0..84d37fb 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -54,9 +54,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.mjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); test('Import', async () => { @@ -76,9 +77,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.mjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); test('Import', async () => { @@ -97,9 +99,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.mjs'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); test('Import', async () => { diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index a4b7320..f70eba8 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -65,9 +65,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.js'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); test('Import', async () => { @@ -88,9 +89,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.js'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); test('Import', async () => { @@ -110,9 +112,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Load - should not work', async () => { - const importPath = path.join(fixture.path, 'file.js'); - const nodeProcess = await node.load(importPath); - assertNotFound(nodeProcess.stderr, importPath); + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); test('Import', async () => { From bac43c98e6cb91bd45743d0fa2d80a0610185ee9 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 12:03:20 +0900 Subject: [PATCH 07/31] wip --- tests/specs/typescript/mts.ts | 172 ++++++++++++++++++++++++---------- 1 file changed, 123 insertions(+), 49 deletions(-) diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 84d37fb..e8ba47b 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -42,75 +42,149 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('full path via .mjs', async ({ describe }) => { const mtsFile = './tests/fixtures/package-module/lib/ts-ext-mts/index.mts'; - describe('with allowJs', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), - 'tsconfig.json': JSON.stringify({ - compilerOptions: { - allowJs: true, - }, - }), - }); + describe('From JavaScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'index.mjs': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('index.mjs', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), - 'tsconfig.json': '{}', - }); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mjs': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); + }); + + test('Import - should not work', async () => { + const nodeProcess = await node.load('index.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mjs': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); + }); + + test('Import - should not work', async () => { + const nodeProcess = await node.load('index.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + describe('From TypeScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'index.mts': importAndLog('./file.mjs'), + 'file.mts': await fs.readFile(mtsFile, 'utf8'), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('index.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); }); From 31311d38ddc222d0b4459c4d7b5a67f079db0c42 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 14:18:41 +0900 Subject: [PATCH 08/31] wip --- tests/specs/typescript/cts.ts | 8 ++++---- tests/specs/typescript/mts.ts | 8 ++++---- tests/specs/typescript/ts.ts | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index ea9ee3f..4c9b23d 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -29,12 +29,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('full path via .cjs', async ({ describe }) => { - const ctsFile = './tests/fixtures/package-module/lib/ts-ext-cts/index.cts'; + const ctsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-cts/index.cts', 'utf8'); describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ 'index.mts': importAndLog('./file.cjs'), - 'file.cts': await fs.readFile(ctsFile, 'utf8'), + 'file.cts': ctsFile, 'tsconfig.json': JSON.stringify({ compilerOptions: { allowJs: true, @@ -60,7 +60,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ 'index.mts': importAndLog('./file.cjs'), - 'file.cts': await fs.readFile(ctsFile, 'utf8'), + 'file.cts': ctsFile, 'tsconfig.json': '{}', }); @@ -82,7 +82,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ 'index.mts': importAndLog('./file.cjs'), - 'file.cts': await fs.readFile(ctsFile, 'utf8'), + 'file.cts': ctsFile, }); test('Load - should not work', async () => { diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index e8ba47b..acba957 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -40,13 +40,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('full path via .mjs', async ({ describe }) => { - const mtsFile = './tests/fixtures/package-module/lib/ts-ext-mts/index.mts'; + const mtsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-mts/index.mts', 'utf8'); describe('From JavaScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ 'index.mjs': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'file.mts': mtsFile, 'tsconfig.json': JSON.stringify({ compilerOptions: { allowJs: true, @@ -73,7 +73,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ 'index.mjs': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'file.mts': mtsFile, 'tsconfig.json': '{}', }); @@ -95,7 +95,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ 'index.mjs': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'file.mts': mtsFile, }); test('Load - should not work', async () => { diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index f70eba8..8d47787 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -50,13 +50,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('full path via .js', async ({ describe }) => { - const tsFile = './tests/fixtures/package-module/lib/ts-ext-ts/index.ts'; + const tsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-ts/index.ts', 'utf8'); describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ 'package.json': JSON.stringify({ type: 'module' }), 'index.ts': importAndLog('./file.js'), - 'file.ts': await fs.readFile(tsFile, 'utf8'), + 'file.ts': tsFile, 'tsconfig.json': JSON.stringify({ compilerOptions: { allowJs: true, @@ -84,7 +84,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'package.json': JSON.stringify({ type: 'module' }), 'index.ts': importAndLog('./file.js'), - 'file.ts': await fs.readFile(tsFile, 'utf8'), + 'file.ts': tsFile, 'tsconfig.json': '{}', }); @@ -108,7 +108,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'package.json': JSON.stringify({ type: 'module' }), 'index.ts': importAndLog('./file.js'), - 'file.ts': await fs.readFile(tsFile, 'utf8'), + 'file.ts': tsFile, }); test('Load - should not work', async () => { From 292ae99828bc430b839e4a319948539bc72403bc Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 12 Feb 2023 17:03:48 +0900 Subject: [PATCH 09/31] wip --- tests/specs/typescript/cts.ts | 165 ++++++++++++++++++++++--------- tests/specs/typescript/mts.ts | 30 +++--- tests/specs/typescript/ts.ts | 181 ++++++++++++++++++++++++---------- 3 files changed, 263 insertions(+), 113 deletions(-) diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index 4c9b23d..02aa430 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -31,72 +31,145 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('full path via .cjs', async ({ describe }) => { const ctsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-cts/index.cts', 'utf8'); - describe('with allowJs', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - 'tsconfig.json': JSON.stringify({ - compilerOptions: { - allowJs: true, - }, - }), - }); + describe('From JavaScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'index.mts': importAndLog('./file.cjs'), - 'file.cts': ctsFile, + describe('From TypeScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); + }); }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.mts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); }); }); diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index acba957..15eac0b 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -45,7 +45,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('From JavaScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'index.mjs': importAndLog('./file.mjs'), + 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, 'tsconfig.json': JSON.stringify({ compilerOptions: { @@ -62,7 +62,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import', async () => { - const nodeProcess = await node.load('index.mjs', { + const nodeProcess = await node.load('import.mjs', { cwd: fixture.path, }); assertResults(nodeProcess.stdout); @@ -72,7 +72,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mjs': importAndLog('./file.mjs'), + 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, 'tsconfig.json': '{}', }); @@ -85,7 +85,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import - should not work', async () => { - const nodeProcess = await node.load('index.mjs', { + const nodeProcess = await node.load('import.mjs', { cwd: fixture.path, }); assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); @@ -94,7 +94,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mjs': importAndLog('./file.mjs'), + 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, }); @@ -106,7 +106,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import - should not work', async () => { - const nodeProcess = await node.load('index.mjs', { + const nodeProcess = await node.load('import.mjs', { cwd: fixture.path, }); assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); @@ -117,8 +117,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('From TypeScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'import.mts': importAndLog('./file.mjs'), + 'file.mts': mtsFile, 'tsconfig.json': JSON.stringify({ compilerOptions: { allowJs: true, @@ -134,7 +134,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import', async () => { - const nodeProcess = await node.load('index.mts', { + const nodeProcess = await node.load('import.mts', { cwd: fixture.path, }); assertResults(nodeProcess.stdout); @@ -144,8 +144,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'import.mts': importAndLog('./file.mjs'), + 'file.mts': mtsFile, 'tsconfig.json': '{}', }); @@ -157,7 +157,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import', async () => { - const nodeProcess = await node.load('index.mts', { + const nodeProcess = await node.load('import.mts', { cwd: fixture.path, }); assertResults(nodeProcess.stdout); @@ -167,8 +167,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs - no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'index.mts': importAndLog('./file.mjs'), - 'file.mts': await fs.readFile(mtsFile, 'utf8'), + 'import.mts': importAndLog('./file.mjs'), + 'file.mts': mtsFile, }); test('Load - should not work', async () => { @@ -179,7 +179,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); test('Import', async () => { - const nodeProcess = await node.load('index.mts', { + const nodeProcess = await node.load('import.mts', { cwd: fixture.path, }); assertResults(nodeProcess.stdout); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 8d47787..38e4fe5 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -52,78 +52,155 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('full path via .js', async ({ describe }) => { const tsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-ts/index.ts', 'utf8'); - describe('with allowJs', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'index.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': JSON.stringify({ - compilerOptions: { - allowJs: true, - }, - }), - }); + describe('From JavaScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - test('Import', async () => { - const nodeProcess = await node.load('index.ts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'index.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.ts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'index.ts': importAndLog('./file.js'), - 'file.ts': tsFile, + describe('From TypeScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - test('Import', async () => { - const nodeProcess = await node.load('index.ts', { - cwd: fixture.path, + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); }); From cfb1a3fb261e741e7e086656f90d3fae77de12b1 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 17 Jul 2023 22:15:50 +0900 Subject: [PATCH 10/31] wip --- tests/index.ts | 73 +++--- tests/specs/typescript/index.ts | 12 +- tests/specs/typescript/ts.ts | 434 ++++++++++++++++---------------- 3 files changed, 260 insertions(+), 259 deletions(-) diff --git a/tests/index.ts b/tests/index.ts index 0943dc5..70bd26b 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,18 +2,19 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - '12.20.0', // CJS named export detection added - '12.22.11', - ...( - process.env.CI - ? [ - '14.21.1', - '16.18.1', - '17.9.1', - '18.12.1', - ] - : [] - ), + '18.12.1', + // '12.20.0', // CJS named export detection added + // '12.22.11', + // ...( + // process.env.CI + // ? [ + // '14.21.1', + // '16.18.1', + // '17.9.1', + // '18.12.1', + // ] + // : [] + // ), ]; (async () => { @@ -22,36 +23,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/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/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/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/typescript/index.ts b/tests/specs/typescript/index.ts index 104e1a8..af13d97 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -4,11 +4,11 @@ import type { NodeApis } from '../../utils/node-with-loader.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { runTestSuite(import('./ts.js'), node); - runTestSuite(import('./tsx.js'), node); - runTestSuite(import('./jsx.js'), node); - runTestSuite(import('./mts.js'), node); - runTestSuite(import('./cts.js'), node); - runTestSuite(import('./tsconfig.js'), node); - runTestSuite(import('./dependencies.js'), node); + // runTestSuite(import('./tsx.js'), node); + // runTestSuite(import('./jsx.js'), node); + // runTestSuite(import('./mts.js'), node); + // runTestSuite(import('./cts.js'), node); + // runTestSuite(import('./tsconfig.js'), node); + // runTestSuite(import('./dependencies.js'), node); }); }); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 55e2b31..98fe4ce 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -25,107 +25,107 @@ export default testSuite(async ({ describe }, node: NodeApis) => { ); } - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-ts/index.ts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess.stdout); - }); - - if (semver.satisfies(node.version, nodeSupports.nodePrefixRequire)) { - test('Disables native source map if Error.prepareStackTrace is customized', async () => { - const nodeProcess = await node.load(importPath, { - nodeOptions: ['-r', 'source-map-support/register'], - }); - assertResults(nodeProcess.stdout); - }); - } - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); + // describe('full path', ({ test }) => { + // const importPath = './lib/ts-ext-ts/index.ts'; + + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertResults(nodeProcess.stdout); + // }); + + // if (semver.satisfies(node.version, nodeSupports.nodePrefixRequire)) { + // test('Disables native source map if Error.prepareStackTrace is customized', async () => { + // const nodeProcess = await node.load(importPath, { + // nodeOptions: ['-r', 'source-map-support/register'], + // }); + // assertResults(nodeProcess.stdout); + // }); + // } + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); describe('full path via .js', async ({ describe }) => { const tsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-ts/index.ts', 'utf8'); - describe('From JavaScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.js': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': JSON.stringify({ - compilerOptions: { - allowJs: true, - }, - }), - }); - - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - - test('Import', async () => { - const nodeProcess = await node.load('import.js', { - cwd: fixture.path, - }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.js': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': '{}', - }); - - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - - test('Import', async () => { - const nodeProcess = await node.load('import.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - }); - - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.js': importAndLog('./file.js'), - 'file.ts': tsFile, - }); - - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - - test('Import', async () => { - const nodeProcess = await node.load('import.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - }); - }); + // describe('From JavaScript file', ({ describe }) => { + // describe('with allowJs', async ({ test }) => { + // const fixture = await createFixture({ + // 'package.json': JSON.stringify({ type: 'module' }), + // 'import.js': importAndLog('./file.js'), + // 'file.ts': tsFile, + // 'tsconfig.json': JSON.stringify({ + // compilerOptions: { + // allowJs: true, + // }, + // }), + // }); + + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('import.js', { + // cwd: fixture.path, + // }); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('without allowJs - empty tsconfig.json', async ({ test }) => { + // const fixture = await createFixture({ + // 'package.json': JSON.stringify({ type: 'module' }), + // 'import.js': importAndLog('./file.js'), + // 'file.ts': tsFile, + // 'tsconfig.json': '{}', + // }); + + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('import.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + // }); + + // describe('without allowJs - no tsconfig.json', async ({ test }) => { + // const fixture = await createFixture({ + // 'package.json': JSON.stringify({ type: 'module' }), + // 'import.js': importAndLog('./file.js'), + // 'file.ts': tsFile, + // }); + + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('import.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + // }); + // }); describe('From TypeScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { @@ -140,59 +140,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - - test('Import', async () => { - const nodeProcess = await node.load('import.ts', { - cwd: fixture.path, - }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': '{}', - }); - - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - - test('Import', async () => { - const nodeProcess = await node.load('import.ts', { - cwd: fixture.path, - }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - }); - - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, - }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); test('Import', async () => { const nodeProcess = await node.load('import.ts', { @@ -202,76 +155,123 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); - }); - }); - - describe('extensionless', ({ test }) => { - const importPath = './lib/ts-ext-ts/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess.stdout); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('extensionless with subextension', ({ test }) => { - const importPath = './lib/ts-ext-ts/index.tsx'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/ts-ext-ts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess.stdout); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('empty directory should fallback to file', ({ test }) => { - const importPath = './lib/ts-ext-ts/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess.stdout); - }); - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // describe('without allowJs - empty tsconfig.json', async ({ test }) => { + // const fixture = await createFixture({ + // 'package.json': JSON.stringify({ type: 'module' }), + // 'import.ts': importAndLog('./file.js'), + // 'file.ts': tsFile, + // 'tsconfig.json': '{}', + // }); + + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('import.ts', { + // cwd: fixture.path, + // }); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('without allowJs - no tsconfig.json', async ({ test }) => { + // const fixture = await createFixture({ + // 'package.json': JSON.stringify({ type: 'module' }), + // 'import.ts': importAndLog('./file.js'), + // 'file.ts': tsFile, + // }); + + // test('Load - should not work', async () => { + // const nodeProcess = await node.load('./file.js', { + // cwd: fixture.path, + // }); + // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.load('import.ts', { + // cwd: fixture.path, + // }); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); }); }); - describe('empty but explicit directory should not fallback to file', ({ test }) => { - const importPath = './lib/ts-ext-ts/index/'; - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertNotFound(nodeProcess.stderr, importPath); - }); - }); + // describe('extensionless', ({ test }) => { + // const importPath = './lib/ts-ext-ts/index'; + + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertResults(nodeProcess.stdout); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('extensionless with subextension', ({ test }) => { + // const importPath = './lib/ts-ext-ts/index.tsx'; + + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('directory', ({ test }) => { + // const importPath = './lib/ts-ext-ts'; + + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertResults(nodeProcess.stdout); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('empty directory should fallback to file', ({ test }) => { + // const importPath = './lib/ts-ext-ts/index'; + + // test('Load', async () => { + // const nodeProcess = await node.load(importPath); + // assertResults(nodeProcess.stdout); + // }); + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertResults(nodeProcess.stdout); + // expect(nodeProcess.stdout).toMatch('{"default":1234}'); + // }); + // }); + + // describe('empty but explicit directory should not fallback to file', ({ test }) => { + // const importPath = './lib/ts-ext-ts/index/'; + + // test('Import', async () => { + // const nodeProcess = await node.import(importPath); + // assertNotFound(nodeProcess.stderr, importPath); + // }); + // }); }); }); From 5bff63b9f363d12cfcbb0c2572e79ef5c8f3fb72 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 17 Jul 2023 22:16:07 +0900 Subject: [PATCH 11/31] wip --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64530c7..2522e55 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] timeout-minutes: 10 steps: - name: Checkout From 0791bde5c8d92b7b13efd4faa15b290bd32180aa Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 08:29:26 +0900 Subject: [PATCH 12/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 2 ++ tests/specs/typescript/ts.ts | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index d2077e0..dd5a851 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -33,6 +33,8 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; + console.log(stack); + console.log(import.meta.url); let { pathname } = new URL(import.meta.url); if (process.platform === 'win32') { pathname = pathname.slice(1); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 98fe4ce..2153e90 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -147,10 +147,13 @@ export default testSuite(async ({ describe }, node: NodeApis) => { // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); // }); - test('Import', async () => { + test('Import', async ({ onTestFail }) => { const nodeProcess = await node.load('import.ts', { cwd: fixture.path, }); + onTestFail(() => { + console.log(nodeProcess.stdout); + }); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); From 5cc0a47a8a70478768e83259f8df9f021847c16f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 08:39:02 +0900 Subject: [PATCH 13/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index dd5a851..1a9541a 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -33,12 +33,13 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; - console.log(stack); - console.log(import.meta.url); + console.log(1, stack); let { pathname } = new URL(import.meta.url); if (process.platform === 'win32') { pathname = pathname.slice(1); } + console.log('searching', pathname); + let pathIndex = stack.indexOf(`${pathname}:35:`); if (pathIndex === -1) { pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); From f504e6380731ca672365f316cb07656bc1dafe78 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 08:49:22 +0900 Subject: [PATCH 14/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index 1a9541a..17afcbb 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -33,6 +33,7 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; + const errorPosition = ':35:'; console.log(1, stack); let { pathname } = new URL(import.meta.url); if (process.platform === 'win32') { @@ -40,12 +41,16 @@ test( } console.log('searching', pathname); - let pathIndex = stack.indexOf(`${pathname}:35:`); + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); + const a = `${pathname.toLowerCase()}${errorPosition}`; + console.log('searching 2', a); + pathIndex = stack.indexOf(a); } if (pathIndex === -1) { - pathIndex = stack.indexOf(`${fileURLToPath(import.meta.url).toLowerCase()}:35:`); + const a = `${fileURLToPath(import.meta.url).toLowerCase()}${errorPosition}`; + console.log('searching 3', a); + pathIndex = stack.indexOf(a); } const previousCharacter = stack[pathIndex - 1]; return pathIndex > -1 && previousCharacter !== ':'; From e368abb8235ec0b20c51a59afe0c4f78bafac2e2 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 08:57:12 +0900 Subject: [PATCH 15/31] wip --- .../package-module/lib/ts-ext-ts/index.ts | 6 ++++- tests/index.ts | 25 +++++++++---------- tests/specs/typescript/ts.ts | 6 ++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index 17afcbb..62ec4f8 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -39,19 +39,23 @@ test( if (process.platform === 'win32') { pathname = pathname.slice(1); } + console.log('path', fileURLToPath(import.meta.url)); console.log('searching', pathname); let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if (pathIndex === -1) { const a = `${pathname.toLowerCase()}${errorPosition}`; console.log('searching 2', a); pathIndex = stack.indexOf(a); } + if (pathIndex === -1) { - const a = `${fileURLToPath(import.meta.url).toLowerCase()}${errorPosition}`; + const a = `${fileURLToPath(import.meta.url)}${errorPosition}`; console.log('searching 3', a); pathIndex = stack.indexOf(a); } + const previousCharacter = stack[pathIndex - 1]; return pathIndex > -1 && previousCharacter !== ':'; }, diff --git a/tests/index.ts b/tests/index.ts index 70bd26b..a89279b 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,19 +2,18 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - '18.12.1', - // '12.20.0', // CJS named export detection added - // '12.22.11', - // ...( - // process.env.CI - // ? [ - // '14.21.1', - // '16.18.1', - // '17.9.1', - // '18.12.1', - // ] - // : [] - // ), + '12.20.0', // CJS named export detection added + '12.22.11', + ...( + process.env.CI + ? [ + '14.21.1', + '16.18.1', + '17.9.1', + '18.12.1', + ] + : [] + ), ]; (async () => { diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 2153e90..06da4e9 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -147,13 +147,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); // }); - test('Import', async ({ onTestFail }) => { + test('Import', async () => { const nodeProcess = await node.load('import.ts', { cwd: fixture.path, }); - onTestFail(() => { - console.log(nodeProcess.stdout); - }); + console.log(nodeProcess.stdout); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); From 2c4490367f67fcbf96d75235e642f85767334cd4 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:06:05 +0900 Subject: [PATCH 16/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index 62ec4f8..4b2db45 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -35,15 +35,20 @@ test( const stack = (new Error()).stack!; const errorPosition = ':35:'; console.log(1, stack); - let { pathname } = new URL(import.meta.url); + let pathname = fileURLToPath(import.meta.url); if (process.platform === 'win32') { - pathname = pathname.slice(1); + pathname = pathname.slice(2); } - console.log('path', fileURLToPath(import.meta.url)); console.log('searching', pathname); let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if (pathIndex === -1) { + pathname = pathname.replace(/\\/g, '/'); + console.log('searching', pathname); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + } + if (pathIndex === -1) { const a = `${pathname.toLowerCase()}${errorPosition}`; console.log('searching 2', a); From 8194b5e99ed4668021ee21cefb039c64aec62a90 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:11:27 +0900 Subject: [PATCH 17/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index 4b2db45..deda4f0 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -62,7 +62,7 @@ test( } const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + return pathIndex > -1;// && previousCharacter !== ':'; }, ); From b2f335d0b4d2845cd09a65e350a3984d60e3b03e Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:14:40 +0900 Subject: [PATCH 18/31] wip --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2522e55..64530c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest] + os: [ubuntu-latest, windows-latest] timeout-minutes: 10 steps: - name: Checkout From 6bbc406636a2c1bc0e5e6adabd7358c0de77c53f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:17:30 +0900 Subject: [PATCH 19/31] wip --- .../fixtures/package-module/lib/ts-ext-ts/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index deda4f0..c4463b3 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -35,18 +35,24 @@ test( const stack = (new Error()).stack!; const errorPosition = ':35:'; console.log(1, stack); + + const isWindows = process.platform === 'win32'; let pathname = fileURLToPath(import.meta.url); - if (process.platform === 'win32') { + if (isWindows) { pathname = pathname.slice(2); } console.log('searching', pathname); let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); - if (pathIndex === -1) { + if ( + pathIndex === -1 + && isWindows + ) { pathname = pathname.replace(/\\/g, '/'); - console.log('searching', pathname); - pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + const a = `${pathname}${errorPosition}`; + console.log('searching 1', a); + pathIndex = stack.indexOf(a); } if (pathIndex === -1) { From a89cf29f5823442a5a34c88a5352da12026fad37 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:17:59 +0900 Subject: [PATCH 20/31] wip --- tests/fixtures/package-module/lib/ts-ext-ts/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index c4463b3..1e36f66 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -41,9 +41,11 @@ test( if (isWindows) { pathname = pathname.slice(2); } - console.log('searching', pathname); - let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + const a = `${pathname}${errorPosition}`; + console.log('searching', a); + + let pathIndex = stack.indexOf(a); if ( pathIndex === -1 From 1a2c42cfba1981afcafe0d87d665b08254436725 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:19:06 +0900 Subject: [PATCH 21/31] wip --- .github/workflows/test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64530c7..dcff923 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,13 +28,13 @@ jobs: version: 8 run_install: true - - name: Lint - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm lint + # - name: Lint + # if: ${{ matrix.os == 'ubuntu-latest' }} + # run: pnpm lint - - name: Type check - if: ${{ matrix.os == 'ubuntu-latest' }} - run: pnpm type-check + # - name: Type check + # if: ${{ matrix.os == 'ubuntu-latest' }} + # run: pnpm type-check - name: Test run: pnpm test From 67fb65cb4fb57ea42185d4039e943fb6b53a5cd9 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:50:36 +0900 Subject: [PATCH 22/31] wip --- .../package-module/lib/cjs-ext-cjs/index.cjs | 22 +- .../package-module/lib/cjs-ext-js/index.js | 27 +- .../package-module/lib/esm-ext-js/index.js | 27 +- .../package-module/lib/esm-ext-mjs/index.mjs | 27 +- .../package-module/lib/ts-ext-cts/index.cts | 24 +- .../package-module/lib/ts-ext-jsx/index.jsx | 28 +- .../package-module/lib/ts-ext-mts/index.mts | 28 +- .../package-module/lib/ts-ext-ts/index.ts | 31 +- .../package-module/lib/ts-ext-ts/index.tsx.ts | 28 +- .../package-module/lib/ts-ext-tsx/index.tsx | 28 +- tests/index.ts | 48 +- tests/specs/javascript/cjs.ts | 10 +- tests/specs/typescript/index.ts | 12 +- tests/specs/typescript/ts.ts | 435 +++++++++--------- 14 files changed, 426 insertions(+), 349 deletions(-) diff --git a/tests/fixtures/package-module/lib/cjs-ext-cjs/index.cjs b/tests/fixtures/package-module/lib/cjs-ext-cjs/index.cjs index 95d7ee0..1b9d890 100644 --- a/tests/fixtures/package-module/lib/cjs-ext-cjs/index.cjs +++ b/tests/fixtures/package-module/lib/cjs-ext-cjs/index.cjs @@ -31,9 +31,25 @@ test( 'sourcemaps', () => { const { stack } = new Error(); - const pathIndex = stack.indexOf(__filename + ':33:'); - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + const errorPosition = ':33:'; + const isWindows = process.platform === 'win32'; + let pathname = __filename; + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); + } + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + } + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/cjs-ext-js/index.js b/tests/fixtures/package-module/lib/cjs-ext-js/index.js index f70040d..ba668c6 100644 --- a/tests/fixtures/package-module/lib/cjs-ext-js/index.js +++ b/tests/fixtures/package-module/lib/cjs-ext-js/index.js @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'node:url'; + async function test(description, testFunction) { try { const result = await testFunction(); @@ -31,16 +33,25 @@ test( 'sourcemaps', () => { const { stack } = new Error(); - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:33:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:33:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/esm-ext-js/index.js b/tests/fixtures/package-module/lib/esm-ext-js/index.js index 985123d..d7844be 100644 --- a/tests/fixtures/package-module/lib/esm-ext-js/index.js +++ b/tests/fixtures/package-module/lib/esm-ext-js/index.js @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'node:url'; + async function test(description, testFunction) { try { const result = await testFunction(); @@ -31,16 +33,25 @@ test( 'sourcemaps', () => { const { stack } = new Error(); - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:33:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:33:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/esm-ext-mjs/index.mjs b/tests/fixtures/package-module/lib/esm-ext-mjs/index.mjs index bf0a6b5..b2c8a0f 100644 --- a/tests/fixtures/package-module/lib/esm-ext-mjs/index.mjs +++ b/tests/fixtures/package-module/lib/esm-ext-mjs/index.mjs @@ -1,3 +1,5 @@ +import { fileURLToPath } from 'node:url'; + async function test(description, testFunction) { try { const result = await testFunction(); @@ -31,16 +33,25 @@ test( 'sourcemaps', () => { const { stack } = new Error(); - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(pathname + ':33:'); - if (pathIndex === -1) { - pathIndex = stack.indexOf(pathname.toLowerCase() + ':33:'); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-cts/index.cts b/tests/fixtures/package-module/lib/ts-ext-cts/index.cts index 2dfd1fb..b75f9ab 100644 --- a/tests/fixtures/package-module/lib/ts-ext-cts/index.cts +++ b/tests/fixtures/package-module/lib/ts-ext-cts/index.cts @@ -1,3 +1,5 @@ +const { fileURLToPath } = require('node:url'); + async function test(description: string, testFunction: () => any | Promise) { try { const result = await testFunction(); @@ -31,9 +33,25 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; - const pathIndex = stack.indexOf(`${__filename}:33:`); - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); + } + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + } + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-jsx/index.jsx b/tests/fixtures/package-module/lib/ts-ext-jsx/index.jsx index 00a98c3..dd25728 100644 --- a/tests/fixtures/package-module/lib/ts-ext-jsx/index.jsx +++ b/tests/fixtures/package-module/lib/ts-ext-jsx/index.jsx @@ -33,19 +33,25 @@ test( 'sourcemaps', () => { const { stack } = new Error(); - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:35:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); - } - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${fileURLToPath(import.meta.url).toLowerCase()}:35:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-mts/index.mts b/tests/fixtures/package-module/lib/ts-ext-mts/index.mts index 1ada674..3c1b8ec 100644 --- a/tests/fixtures/package-module/lib/ts-ext-mts/index.mts +++ b/tests/fixtures/package-module/lib/ts-ext-mts/index.mts @@ -33,19 +33,25 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:35:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); - } - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${fileURLToPath(import.meta.url).toLowerCase()}:35:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts index 1e36f66..d052019 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.ts @@ -34,43 +34,24 @@ test( () => { const stack = (new Error()).stack!; const errorPosition = ':35:'; - console.log(1, stack); - const isWindows = process.platform === 'win32'; let pathname = fileURLToPath(import.meta.url); if (isWindows) { + // Remove drive letter pathname = pathname.slice(2); } - const a = `${pathname}${errorPosition}`; - console.log('searching', a); - - let pathIndex = stack.indexOf(a); - + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); if ( pathIndex === -1 - && isWindows + && isWindows ) { + // Convert backslash to slash pathname = pathname.replace(/\\/g, '/'); - const a = `${pathname}${errorPosition}`; - console.log('searching 1', a); - pathIndex = stack.indexOf(a); - } - - if (pathIndex === -1) { - const a = `${pathname.toLowerCase()}${errorPosition}`; - console.log('searching 2', a); - pathIndex = stack.indexOf(a); - } - - if (pathIndex === -1) { - const a = `${fileURLToPath(import.meta.url)}${errorPosition}`; - console.log('searching 3', a); - pathIndex = stack.indexOf(a); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1;// && previousCharacter !== ':'; + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-ts/index.tsx.ts b/tests/fixtures/package-module/lib/ts-ext-ts/index.tsx.ts index 4f9f752..f0baf47 100644 --- a/tests/fixtures/package-module/lib/ts-ext-ts/index.tsx.ts +++ b/tests/fixtures/package-module/lib/ts-ext-ts/index.tsx.ts @@ -33,19 +33,25 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:35:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); - } - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${fileURLToPath(import.meta.url).toLowerCase()}:35:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/fixtures/package-module/lib/ts-ext-tsx/index.tsx b/tests/fixtures/package-module/lib/ts-ext-tsx/index.tsx index 07b9e64..4121325 100644 --- a/tests/fixtures/package-module/lib/ts-ext-tsx/index.tsx +++ b/tests/fixtures/package-module/lib/ts-ext-tsx/index.tsx @@ -33,19 +33,25 @@ test( 'sourcemaps', () => { const stack = (new Error()).stack!; - let { pathname } = new URL(import.meta.url); - if (process.platform === 'win32') { - pathname = pathname.slice(1); + const errorPosition = ':35:'; + const isWindows = process.platform === 'win32'; + let pathname = fileURLToPath(import.meta.url); + if (isWindows) { + // Remove drive letter + pathname = pathname.slice(2); } - let pathIndex = stack.indexOf(`${pathname}:35:`); - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${pathname.toLowerCase()}:35:`); - } - if (pathIndex === -1) { - pathIndex = stack.indexOf(`${fileURLToPath(import.meta.url).toLowerCase()}:35:`); + + let pathIndex = stack.indexOf(`${pathname}${errorPosition}`); + if ( + pathIndex === -1 + && isWindows + ) { + // Convert backslash to slash + pathname = pathname.replace(/\\/g, '/'); + pathIndex = stack.indexOf(`${pathname}${errorPosition}`); } - const previousCharacter = stack[pathIndex - 1]; - return pathIndex > -1 && previousCharacter !== ':'; + + return pathIndex > -1; }, ); diff --git a/tests/index.ts b/tests/index.ts index a89279b..0943dc5 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -22,36 +22,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/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/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/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/javascript/cjs.ts b/tests/specs/javascript/cjs.ts index a799cff..12daae5 100644 --- a/tests/specs/javascript/cjs.ts +++ b/tests/specs/javascript/cjs.ts @@ -34,14 +34,20 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); }); - test('Import', async () => { + test('Import', async ({ onTestFail }) => { const nodeProcess = await node.import(importPath); + onTestFail(() => { + console.log(nodeProcess); + }); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - test('TypeScript Import', async () => { + test('TypeScript Import', async ({ onTestFail }) => { const nodeProcess = await node.import(importPath, { typescript: true }); + onTestFail(() => { + console.log(nodeProcess); + }); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts index af13d97..104e1a8 100644 --- a/tests/specs/typescript/index.ts +++ b/tests/specs/typescript/index.ts @@ -4,11 +4,11 @@ import type { NodeApis } from '../../utils/node-with-loader.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('TypeScript', async ({ runTestSuite }) => { runTestSuite(import('./ts.js'), node); - // runTestSuite(import('./tsx.js'), node); - // runTestSuite(import('./jsx.js'), node); - // runTestSuite(import('./mts.js'), node); - // runTestSuite(import('./cts.js'), node); - // runTestSuite(import('./tsconfig.js'), node); - // runTestSuite(import('./dependencies.js'), node); + runTestSuite(import('./tsx.js'), node); + runTestSuite(import('./jsx.js'), node); + runTestSuite(import('./mts.js'), node); + runTestSuite(import('./cts.js'), node); + runTestSuite(import('./tsconfig.js'), node); + runTestSuite(import('./dependencies.js'), node); }); }); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 06da4e9..55e2b31 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -25,107 +25,107 @@ export default testSuite(async ({ describe }, node: NodeApis) => { ); } - // describe('full path', ({ test }) => { - // const importPath = './lib/ts-ext-ts/index.ts'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertResults(nodeProcess.stdout); - // }); - - // if (semver.satisfies(node.version, nodeSupports.nodePrefixRequire)) { - // test('Disables native source map if Error.prepareStackTrace is customized', async () => { - // const nodeProcess = await node.load(importPath, { - // nodeOptions: ['-r', 'source-map-support/register'], - // }); - // assertResults(nodeProcess.stdout); - // }); - // } - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); + describe('full path', ({ test }) => { + const importPath = './lib/ts-ext-ts/index.ts'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertResults(nodeProcess.stdout); + }); + + if (semver.satisfies(node.version, nodeSupports.nodePrefixRequire)) { + test('Disables native source map if Error.prepareStackTrace is customized', async () => { + const nodeProcess = await node.load(importPath, { + nodeOptions: ['-r', 'source-map-support/register'], + }); + assertResults(nodeProcess.stdout); + }); + } + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); describe('full path via .js', async ({ describe }) => { const tsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-ts/index.ts', 'utf8'); - // describe('From JavaScript file', ({ describe }) => { - // describe('with allowJs', async ({ test }) => { - // const fixture = await createFixture({ - // 'package.json': JSON.stringify({ type: 'module' }), - // 'import.js': importAndLog('./file.js'), - // 'file.ts': tsFile, - // 'tsconfig.json': JSON.stringify({ - // compilerOptions: { - // allowJs: true, - // }, - // }), - // }); - - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('import.js', { - // cwd: fixture.path, - // }); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('without allowJs - empty tsconfig.json', async ({ test }) => { - // const fixture = await createFixture({ - // 'package.json': JSON.stringify({ type: 'module' }), - // 'import.js': importAndLog('./file.js'), - // 'file.ts': tsFile, - // 'tsconfig.json': '{}', - // }); - - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('import.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - // }); - - // describe('without allowJs - no tsconfig.json', async ({ test }) => { - // const fixture = await createFixture({ - // 'package.json': JSON.stringify({ type: 'module' }), - // 'import.js': importAndLog('./file.js'), - // 'file.ts': tsFile, - // }); - - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('import.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - // }); - // }); + describe('From JavaScript file', ({ describe }) => { + describe('with allowJs', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + allowJs: true, + }, + }), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + }); + + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + }); + }); describe('From TypeScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { @@ -140,139 +140,138 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('without allowJs - empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('without allowJs - no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); test('Import', async () => { const nodeProcess = await node.load('import.ts', { cwd: fixture.path, }); - console.log(nodeProcess.stdout); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); + }); + }); + + describe('extensionless', ({ test }) => { + const importPath = './lib/ts-ext-ts/index'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertResults(nodeProcess.stdout); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('extensionless with subextension', ({ test }) => { + const importPath = './lib/ts-ext-ts/index.tsx'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('directory', ({ test }) => { + const importPath = './lib/ts-ext-ts'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertResults(nodeProcess.stdout); + }); + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + + describe('empty directory should fallback to file', ({ test }) => { + const importPath = './lib/ts-ext-ts/index'; + + test('Load', async () => { + const nodeProcess = await node.load(importPath); + assertResults(nodeProcess.stdout); + }); - // describe('without allowJs - empty tsconfig.json', async ({ test }) => { - // const fixture = await createFixture({ - // 'package.json': JSON.stringify({ type: 'module' }), - // 'import.ts': importAndLog('./file.js'), - // 'file.ts': tsFile, - // 'tsconfig.json': '{}', - // }); - - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('import.ts', { - // cwd: fixture.path, - // }); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('without allowJs - no tsconfig.json', async ({ test }) => { - // const fixture = await createFixture({ - // 'package.json': JSON.stringify({ type: 'module' }), - // 'import.ts': importAndLog('./file.js'), - // 'file.ts': tsFile, - // }); - - // test('Load - should not work', async () => { - // const nodeProcess = await node.load('./file.js', { - // cwd: fixture.path, - // }); - // assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.load('import.ts', { - // cwd: fixture.path, - // }); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); - // describe('extensionless', ({ test }) => { - // const importPath = './lib/ts-ext-ts/index'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertResults(nodeProcess.stdout); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('extensionless with subextension', ({ test }) => { - // const importPath = './lib/ts-ext-ts/index.tsx'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertResults(nodeProcess.stdout, 'ts-ext-ts/index.tsx.ts'); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('directory', ({ test }) => { - // const importPath = './lib/ts-ext-ts'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertResults(nodeProcess.stdout); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('empty directory should fallback to file', ({ test }) => { - // const importPath = './lib/ts-ext-ts/index'; - - // test('Load', async () => { - // const nodeProcess = await node.load(importPath); - // assertResults(nodeProcess.stdout); - // }); - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertResults(nodeProcess.stdout); - // expect(nodeProcess.stdout).toMatch('{"default":1234}'); - // }); - // }); - - // describe('empty but explicit directory should not fallback to file', ({ test }) => { - // const importPath = './lib/ts-ext-ts/index/'; - - // test('Import', async () => { - // const nodeProcess = await node.import(importPath); - // assertNotFound(nodeProcess.stderr, importPath); - // }); - // }); + describe('empty but explicit directory should not fallback to file', ({ test }) => { + const importPath = './lib/ts-ext-ts/index/'; + + test('Import', async () => { + const nodeProcess = await node.import(importPath); + assertNotFound(nodeProcess.stderr, importPath); + }); + }); }); }); From b77ba28728baedcc89e64ed32f5c1b5a803fa99c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 09:55:19 +0900 Subject: [PATCH 23/31] wip --- .github/workflows/test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dcff923..64530c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,13 +28,13 @@ jobs: version: 8 run_install: true - # - name: Lint - # if: ${{ matrix.os == 'ubuntu-latest' }} - # run: pnpm lint + - name: Lint + if: ${{ matrix.os == 'ubuntu-latest' }} + run: pnpm lint - # - name: Type check - # if: ${{ matrix.os == 'ubuntu-latest' }} - # run: pnpm type-check + - name: Type check + if: ${{ matrix.os == 'ubuntu-latest' }} + run: pnpm type-check - name: Test run: pnpm test From ffd46622c81e8a1c9bde90a5dc1300e7bf744cd7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 10:47:46 +0900 Subject: [PATCH 24/31] wip --- tests/specs/javascript/cjs.ts | 10 +-- tests/specs/typescript/cts.ts | 124 ++++++++++++++++--------------- tests/specs/typescript/mts.ts | 128 ++++++++++++++++---------------- tests/specs/typescript/ts.ts | 136 +++++++++++++++++----------------- 4 files changed, 202 insertions(+), 196 deletions(-) diff --git a/tests/specs/javascript/cjs.ts b/tests/specs/javascript/cjs.ts index 12daae5..a799cff 100644 --- a/tests/specs/javascript/cjs.ts +++ b/tests/specs/javascript/cjs.ts @@ -34,20 +34,14 @@ export default testSuite(async ({ describe }, node: NodeApis) => { assertResults(nodeProcess.stdout); }); - test('Import', async ({ onTestFail }) => { + test('Import', async () => { const nodeProcess = await node.import(importPath); - onTestFail(() => { - console.log(nodeProcess); - }); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - test('TypeScript Import', async ({ onTestFail }) => { + test('TypeScript Import', async () => { const nodeProcess = await node.import(importPath, { typescript: true }); - onTestFail(() => { - console.log(nodeProcess); - }); assertResults(nodeProcess.stdout); expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index 442c42b..91afe21 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -58,46 +58,48 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mjs': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mjs', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mjs': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mjs', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); }); }); @@ -129,46 +131,48 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mts': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mts': importAndLog('./file.cjs'), - 'file.cts': ctsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.cjs'), + 'file.cts': ctsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.cjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.cjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.cjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); - expect(nodeProcess.stderr).toMatch('SyntaxError: Unexpected token \':\''); }); }); }); diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 38d5132..cdec3e6 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -70,46 +70,48 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mjs': importAndLog('./file.mjs'), - 'file.mts': mtsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.mjs'), + 'file.mts': mtsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); - }); - test('Import - should not work', async () => { - const nodeProcess = await node.load('import.mjs', { - cwd: fixture.path, + test('Import - should not work', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mjs': importAndLog('./file.mjs'), - 'file.mts': mtsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mjs': importAndLog('./file.mjs'), + 'file.mts': mtsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); - }); - test('Import - should not work', async () => { - const nodeProcess = await node.load('import.mjs', { - cwd: fixture.path, + test('Import - should not work', async () => { + const nodeProcess = await node.load('import.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); }); }); @@ -142,48 +144,50 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mts': importAndLog('./file.mjs'), - 'file.mts': mtsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.mjs'), + 'file.mts': mtsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'import.mts': importAndLog('./file.mjs'), - 'file.mts': mtsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'import.mts': importAndLog('./file.mjs'), + 'file.mts': mtsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.mjs', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.mjs', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.mjs')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.mts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.mts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); }); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 55e2b31..7e26436 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -81,48 +81,50 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.js': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.js', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.js': importAndLog('./file.js'), - 'file.ts': tsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.js': importAndLog('./file.js'), + 'file.ts': tsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.js', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); }); }); @@ -156,50 +158,52 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('without allowJs - empty tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - 'tsconfig.json': '{}', - }); + describe('without allowJs', ({ describe }) => { + describe('empty tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': '{}', + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.ts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - }); - describe('without allowJs - no tsconfig.json', async ({ test }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), - 'import.ts': importAndLog('./file.js'), - 'file.ts': tsFile, - }); + describe('no tsconfig.json', async ({ test }) => { + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + }); - test('Load - should not work', async () => { - const nodeProcess = await node.load('./file.js', { - cwd: fixture.path, + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); }); - assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); - }); - test('Import', async () => { - const nodeProcess = await node.load('import.ts', { - cwd: fixture.path, + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); - assertResults(nodeProcess.stdout); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); }); }); }); From 68c4083b7fae3a0f17c2b2e5192033aae37c4e93 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 11:05:43 +0900 Subject: [PATCH 25/31] wip --- tests/specs/json.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/specs/json.ts b/tests/specs/json.ts index 2c3f2a3..9db10fb 100644 --- a/tests/specs/json.ts +++ b/tests/specs/json.ts @@ -27,8 +27,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { expect(nodeProcess.stdout).toBe(''); }); - test('Import', async () => { + test('Import', async ({ onTestFail }) => { const nodeProcess = await node.import(importPath); + onTestFail(() => { + console.log(nodeProcess); + }); expect(nodeProcess.stdout).toMatch('{"default":{"loaded":"json"},"loaded":"json"}'); }); }); @@ -36,8 +39,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('directory', ({ test }) => { const importPath = './lib/json'; - test('Load', async () => { + test('Load', async ({ onTestFail }) => { const nodeProcess = await node.load(importPath); + onTestFail(() => { + console.log(nodeProcess); + }); expect(nodeProcess.exitCode).toBe(0); expect(nodeProcess.stdout).toBe(''); }); From acdd2f0064c7d9813e239382fdf4aeed690c9a88 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 11:30:34 +0900 Subject: [PATCH 26/31] wip --- tests/utils/assertions.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/assertions.ts b/tests/utils/assertions.ts index 4d1d698..9b1e96a 100644 --- a/tests/utils/assertions.ts +++ b/tests/utils/assertions.ts @@ -1,9 +1,9 @@ import { expect } from 'manten'; -const isWin = process.platform === 'win32'; +const isWindows = process.platform === 'win32'; const agnosticPath = (path: string) => ( - isWin + isWindows ? path.replace(/\//g, '\\') : path ); From 74876c8c1078703791e0ea12672f2f8844309e49 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 13:36:22 +0900 Subject: [PATCH 27/31] wip --- src/loaders-deprecated.ts | 1 + src/loaders.ts | 7 ++++++- src/utils.ts | 12 +++++++++--- tests/specs/typescript/ts.ts | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/loaders-deprecated.ts b/src/loaders-deprecated.ts index 0b9fe9c..535d2c9 100644 --- a/src/loaders-deprecated.ts +++ b/src/loaders-deprecated.ts @@ -80,6 +80,7 @@ const _transformSource: transformSource = async function ( if ( url.endsWith('.json') + || url.endsWith('.jsx') || tsExtensionsPattern.test(url) ) { const transformed = await transform( diff --git a/src/loaders.ts b/src/loaders.ts index 76d138c..6d1faa8 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -139,7 +139,11 @@ export const resolve: resolve = async function ( */ if ( context.parentURL - && fileMatcher?.(fileURLToPath(context.parentURL)) + && ( + // TODO: should not include jsx + tsExtensionsPattern.test(context.parentURL) + || fileMatcher?.(fileURLToPath(context.parentURL)) + ) ) { const tsPath = resolveTsPath(specifier); @@ -239,6 +243,7 @@ export const load: load = async function ( if ( loaded.format === 'json' + || url.endsWith('.jsx') || tsExtensionsPattern.test(url) ) { const transformed = await transform( diff --git a/src/utils.ts b/src/utils.ts index 0d086a5..dc5eddf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -30,7 +30,7 @@ export const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig); export const fileProtocol = 'file://'; -export const tsExtensionsPattern = /\.([cm]?ts|[tj]sx)$/; +export const tsExtensionsPattern = /\.([cm]?ts|tsx)$/; const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => { const extension = path.extname(fileUrl); @@ -48,6 +48,8 @@ const getFormatFromExtension = (fileUrl: string): ModuleFormat | undefined => { } }; +export const knownExtensions = /\.[tj]sx?$/; + export const getFormatFromFileUrl = (fileUrl: string) => { const format = getFormatFromExtension(fileUrl); @@ -55,8 +57,12 @@ export const getFormatFromFileUrl = (fileUrl: string) => { return format; } - // ts, tsx, jsx - if (tsExtensionsPattern.test(fileUrl)) { + /** + * Since this is only called when Node.js can't figure + * out the type, we only need to implement it for the + * extensions it can't handle (e.g. ts, tsx, jsx) + */ + if (knownExtensions.test(fileUrl)) { return getPackageType(fileUrl); } }; diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 7e26436..0b86134 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -159,6 +159,42 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { + describe('excluded by tsconfig.json', async ({ test }) => { + /** + * file.ts is technically excluded from tsconfig.json, but it should work + * becaue it's clearly from a TypeScript file + * + * In the future, we'll probably want to lookup a matching tsconfig for each file + * and not just pick one in cwd + */ + const fixture = await createFixture({ + 'package.json': JSON.stringify({ type: 'module' }), + 'import.ts': importAndLog('./file.js'), + 'file.ts': tsFile, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + // TODO: add some configs that shouldnt get applied + }, + exclude: ['*.ts'], + }), + }); + + test('Load - should not work', async () => { + const nodeProcess = await node.load('./file.js', { + cwd: fixture.path, + }); + assertNotFound(nodeProcess.stderr, path.join(fixture.path, 'file.js')); + }); + + test('Import', async () => { + const nodeProcess = await node.load('import.ts', { + cwd: fixture.path, + }); + assertResults(nodeProcess.stdout); + expect(nodeProcess.stdout).toMatch('{"default":1234}'); + }); + }); + describe('empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ 'package.json': JSON.stringify({ type: 'module' }), From 7153606a85a6ff3d2ef8ff34b9890d6c1ea0e6d0 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 13:42:56 +0900 Subject: [PATCH 28/31] wip --- tests/specs/typescript/cts.ts | 6 +++--- tests/specs/typescript/mts.ts | 6 +++--- tests/specs/typescript/ts.ts | 26 +++++++++++++------------- tests/specs/typescript/tsconfig.ts | 9 +++++---- tests/utils/fixtures.ts | 14 +++++++++++++- 5 files changed, 37 insertions(+), 24 deletions(-) diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index 91afe21..c40fbe6 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -4,7 +4,7 @@ import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; import type { NodeApis } from '../../utils/node-with-loader.js'; import { assertNotFound } from '../../utils/assertions.js'; -import { importAndLog } from '../../utils/fixtures.js'; +import { importAndLog, tsconfigJson } from '../../utils/fixtures.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.cts extension', ({ describe }) => { @@ -36,7 +36,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.cjs'), 'file.cts': ctsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, @@ -109,7 +109,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.cjs'), 'file.cts': ctsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index cdec3e6..8dbce72 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -6,7 +6,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 { importAndLog } from '../../utils/fixtures.js'; +import { importAndLog, tsconfigJson } from '../../utils/fixtures.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.mts extension', ({ describe }) => { @@ -47,7 +47,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, @@ -121,7 +121,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.mjs'), 'file.mts': mtsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 0b86134..2b9668c 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -6,7 +6,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 { importAndLog } from '../../utils/fixtures.js'; +import { importAndLog, packageJson, tsconfigJson } from '../../utils/fixtures.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('.ts extension', ({ describe }) => { @@ -55,10 +55,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('From JavaScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), 'file.ts': tsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, @@ -84,10 +84,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('without allowJs', ({ describe }) => { describe('empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), 'file.ts': tsFile, - 'tsconfig.json': '{}', + 'tsconfig.json': tsconfigJson({}), }); test('Load - should not work', async () => { @@ -107,7 +107,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), 'file.ts': tsFile, }); @@ -132,10 +132,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('From TypeScript file', ({ describe }) => { describe('with allowJs', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), 'file.ts': tsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, }, @@ -168,10 +168,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { * and not just pick one in cwd */ const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), 'file.ts': tsFile, - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { // TODO: add some configs that shouldnt get applied }, @@ -197,10 +197,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('empty tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), 'file.ts': tsFile, - 'tsconfig.json': '{}', + 'tsconfig.json': tsconfigJson({}), }); test('Load - should not work', async () => { @@ -221,7 +221,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('no tsconfig.json', async ({ test }) => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ type: 'module' }), + 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), 'file.ts': tsFile, }); diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 0d26c7c..6bb36de 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.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 { packageJson, tsconfigJson } from '../../utils/fixtures.js'; export default testSuite(async ({ describe }, node: NodeApis) => { describe('tsconfig', ({ test, describe }) => { @@ -16,10 +17,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { test('does not apply tsconfig to excluded', async () => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ + 'package.json': packageJson({ type: 'module', }), - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { jsxFactory: 'console.log', }, @@ -58,10 +59,10 @@ export default testSuite(async ({ describe }, node: NodeApis) => { test('allowJs', async () => { const fixture = await createFixture({ - 'package.json': JSON.stringify({ + 'package.json': packageJson({ type: 'module', }), - 'tsconfig.json': JSON.stringify({ + 'tsconfig.json': tsconfigJson({ compilerOptions: { allowJs: true, jsxFactory: 'console.log', diff --git a/tests/utils/fixtures.ts b/tests/utils/fixtures.ts index 7ae82ea..5d6370c 100644 --- a/tests/utils/fixtures.ts +++ b/tests/utils/fixtures.ts @@ -1 +1,13 @@ -export const importAndLog = (specifier: string) => `import("${specifier}").then(m => console.log(JSON.stringify(m)))`; +import type { PackageJson, TsConfigJson } from 'type-fest'; + +export const importAndLog = ( + specifier: string, +) => `import("${specifier}").then(m => console.log(JSON.stringify(m)))`; + +export const packageJson = ( + packageJsonObject: PackageJson, +) => JSON.stringify(packageJsonObject); + +export const tsconfigJson = ( + tsconfigJsonObject: TsConfigJson, +) => JSON.stringify(tsconfigJsonObject); From 11d988bdfaaf0b8d1ef76f14c2e53f1e952be499 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 18 Jul 2023 13:45:05 +0900 Subject: [PATCH 29/31] wip --- src/loaders.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/loaders.ts b/src/loaders.ts index 6d1faa8..385a06e 100644 --- a/src/loaders.ts +++ b/src/loaders.ts @@ -140,7 +140,6 @@ export const resolve: resolve = async function ( if ( context.parentURL && ( - // TODO: should not include jsx tsExtensionsPattern.test(context.parentURL) || fileMatcher?.(fileURLToPath(context.parentURL)) ) From 06923214dbaa777be9bd82ab08dcbd15afa5124f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 28 Aug 2023 10:34:21 +0900 Subject: [PATCH 30/31] cleanup fixtures --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- tests/index.ts | 5 +++-- tests/specs/typescript/cts.ts | 24 ++++++++++++++++++------ tests/specs/typescript/mts.ts | 24 ++++++++++++++++++------ tests/specs/typescript/ts.ts | 28 +++++++++++++++++++++------- tests/specs/typescript/tsconfig.ts | 12 ++++++------ 7 files changed, 71 insertions(+), 32 deletions(-) diff --git a/package.json b/package.json index 595bf53..ed976af 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "execa": "^7.0.0", "fs-fixture": "^1.2.0", "get-node": "^14.2.1", - "manten": "^1.0.0", + "manten": "^1.1.0", "pkgroll": "^1.9.0", "semver": "^7.3.8", "source-map-support": "^0.5.21", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ef0dbe3..e194441 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,8 +44,8 @@ devDependencies: specifier: ^14.2.1 version: 14.2.1 manten: - specifier: ^1.0.0 - version: 1.0.0 + specifier: ^1.1.0 + version: 1.1.0 pkgroll: specifier: ^1.9.0 version: 1.9.0(typescript@4.9.5) @@ -2602,8 +2602,8 @@ packages: '@jridgewell/sourcemap-codec': 1.4.14 dev: true - /manten@1.0.0: - resolution: {integrity: sha512-TQzGMEFtwooIQbg+xnJbPHjYRRoDRgjpBJ9XtLgt00nr7byRnw8I0dEOztyErXKZO5IbavcoljmmZalkf1xk4A==} + /manten@1.1.0: + resolution: {integrity: sha512-DyEpskY9RzqXWO3IZqH8SKxsYHdKyN+k+cLtLoTTg82/DGKbKZuHs6nBV17xchnBVFxibAWGhNSXo7h1EHO0jw==} dependencies: expect: 29.6.4 dev: true diff --git a/tests/index.ts b/tests/index.ts index 7ae03c6..226362b 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,8 +2,9 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - '12.20.0', // CJS named export detection added - '12', + // '12.20.0', // CJS named export detection added + // '12', + '18', ...( process.env.CI ? [ diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts index c40fbe6..0fc825a 100644 --- a/tests/specs/typescript/cts.ts +++ b/tests/specs/typescript/cts.ts @@ -32,7 +32,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const ctsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-cts/index.cts', 'utf8'); describe('From JavaScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.cjs'), 'file.cts': ctsFile, @@ -43,6 +43,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, @@ -59,13 +61,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.cjs'), 'file.cts': ctsFile, 'tsconfig.json': '{}', }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, @@ -81,12 +85,14 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.cjs'), 'file.cts': ctsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, @@ -105,7 +111,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('From TypeScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.cjs'), 'file.cts': ctsFile, @@ -116,6 +122,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, @@ -132,13 +140,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.cjs'), 'file.cts': ctsFile, 'tsconfig.json': '{}', }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, @@ -154,12 +164,14 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.cjs'), 'file.cts': ctsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.cjs', { cwd: fixture.path, diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts index 8dbce72..4863bcc 100644 --- a/tests/specs/typescript/mts.ts +++ b/tests/specs/typescript/mts.ts @@ -43,7 +43,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const mtsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-mts/index.mts', 'utf8'); describe('From JavaScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, @@ -54,6 +54,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, @@ -71,13 +73,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, 'tsconfig.json': '{}', }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, @@ -93,12 +97,14 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mjs': importAndLog('./file.mjs'), 'file.mts': mtsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, @@ -117,7 +123,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('From TypeScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.mjs'), 'file.mts': mtsFile, @@ -128,6 +134,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, @@ -145,13 +153,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.mjs'), 'file.mts': mtsFile, 'tsconfig.json': '{}', }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, @@ -168,12 +178,14 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'import.mts': importAndLog('./file.mjs'), 'file.mts': mtsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.mjs', { cwd: fixture.path, diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts index 2b9668c..49f5734 100644 --- a/tests/specs/typescript/ts.ts +++ b/tests/specs/typescript/ts.ts @@ -53,7 +53,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { const tsFile = await fs.readFile('./tests/fixtures/package-module/lib/ts-ext-ts/index.ts', 'utf8'); describe('From JavaScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), @@ -65,6 +65,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -82,7 +84,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), @@ -90,6 +92,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { 'tsconfig.json': tsconfigJson({}), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -105,13 +109,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.js': importAndLog('./file.js'), 'file.ts': tsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -130,7 +136,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('From TypeScript file', ({ describe }) => { - describe('with allowJs', async ({ test }) => { + describe('with allowJs', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), @@ -142,6 +148,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -159,7 +167,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); describe('without allowJs', ({ describe }) => { - describe('excluded by tsconfig.json', async ({ test }) => { + describe('excluded by tsconfig.json', async ({ test, onFinish }) => { /** * file.ts is technically excluded from tsconfig.json, but it should work * becaue it's clearly from a TypeScript file @@ -179,6 +187,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -195,7 +205,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('empty tsconfig.json', async ({ test }) => { + describe('empty tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), @@ -203,6 +213,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { 'tsconfig.json': tsconfigJson({}), }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, @@ -219,13 +231,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }); }); - describe('no tsconfig.json', async ({ test }) => { + describe('no tsconfig.json', async ({ test, onFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module' }), 'import.ts': importAndLog('./file.js'), 'file.ts': tsFile, }); + onFinish(async () => await fixture.rm()); + test('Load - should not work', async () => { const nodeProcess = await node.load('./file.js', { cwd: fixture.path, diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts index 6bb36de..2ae6e9c 100644 --- a/tests/specs/typescript/tsconfig.ts +++ b/tests/specs/typescript/tsconfig.ts @@ -15,7 +15,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { describe('scope', ({ test }) => { const checkJsx = 'export default (
)'; - test('does not apply tsconfig to excluded', async () => { + test('does not apply tsconfig to excluded', async ({ onTestFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module', @@ -37,6 +37,8 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }, }); + onTestFinish(async () => await fixture.rm()); + // Strict mode is not tested because ESM is strict by default const includedJsxTs = await node.load('./included/tsx.tsx', { @@ -53,11 +55,9 @@ export default testSuite(async ({ describe }, node: NodeApis) => { cwd: fixture.path, }); expect(excludedJsxTs.stderr).toMatch('ReferenceError: React is not defined'); - - await fixture.rm(); }); - test('allowJs', async () => { + test('allowJs', async ({ onTestFinish }) => { const fixture = await createFixture({ 'package.json': packageJson({ type: 'module', @@ -71,12 +71,12 @@ export default testSuite(async ({ describe }, node: NodeApis) => { 'src/jsx.jsx': checkJsx, }); + onTestFinish(async () => await fixture.rm()); + const jsxJs = await node.load('./src/jsx.jsx', { cwd: fixture.path, }); expect(jsxJs.stdout).toBe('div null'); - - await fixture.rm(); }); }); From 99a7d25db17475badb86338877d5bb027bcacf62 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 28 Aug 2023 10:37:49 +0900 Subject: [PATCH 31/31] wip --- tests/index.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/index.ts b/tests/index.ts index 226362b..7ae03c6 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -2,9 +2,8 @@ import { describe } from 'manten'; import { createNode } from './utils/node-with-loader.js'; const nodeVersions = [ - // '12.20.0', // CJS named export detection added - // '12', - '18', + '12.20.0', // CJS named export detection added + '12', ...( process.env.CI ? [