From 4103b7113795fbc3de6c21498914043a88c82813 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 26 Sep 2023 00:56:09 +0900 Subject: [PATCH 01/58] test: remove old node versions --- tests/utils/node-versions.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/utils/node-versions.ts b/tests/utils/node-versions.ts index 707b8aac3..0d757a8b2 100644 --- a/tests/utils/node-versions.ts +++ b/tests/utils/node-versions.ts @@ -1,5 +1,4 @@ export const nodeVersions = [ - '18', '20', ...( ( @@ -7,11 +6,7 @@ export const nodeVersions = [ && process.platform !== 'win32' ) ? [ - '12.20.0', // CJS named export detection added - '12', - '14', - '16', - '17', + '18', ] as const : [] as const ), From 189e684c6438ad4bca4c5b1b9335aec042dfbf45 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 26 Sep 2023 00:57:41 +0900 Subject: [PATCH 02/58] delete deprecated loader code --- src/esm/index.ts | 312 +++++++++++++++++++++++++++++++++- src/esm/loaders-deprecated.ts | 115 ------------- src/esm/loaders.ts | 310 --------------------------------- 3 files changed, 310 insertions(+), 427 deletions(-) delete mode 100644 src/esm/loaders-deprecated.ts delete mode 100644 src/esm/loaders.ts diff --git a/src/esm/index.ts b/src/esm/index.ts index 60a755b73..872db0792 100644 --- a/src/esm/index.ts +++ b/src/esm/index.ts @@ -1,2 +1,310 @@ -export * from './loaders.js'; -export * from './loaders-deprecated.js'; +import type { MessagePort } from 'node:worker_threads'; +import path from 'path'; +import { pathToFileURL, fileURLToPath } from 'url'; +import type { + ResolveFnOutput, ResolveHookContext, LoadHook, GlobalPreloadHook, +} from 'module'; +import type { TransformOptions } from 'esbuild'; +import { compareNodeVersion } from '../utils/compare-node-version'; +import { transform, transformDynamicImport } from '../utils/transform'; +import { resolveTsPath } from '../utils/resolve-ts-path'; +import { + applySourceMap, + tsconfigPathsMatcher, + fileMatcher, + tsExtensionsPattern, + isJsonPattern, + getFormatFromFileUrl, + fileProtocol, + type MaybePromise, + type NodeError, +} from './utils.js'; + +const isDirectoryPattern = /\/(?:$|\?)/; + +type NextResolve = ( + specifier: string, + context?: ResolveHookContext, +) => MaybePromise; + +type resolve = ( + specifier: string, + context: ResolveHookContext, + nextResolve: NextResolve, + recursiveCall?: boolean, +) => MaybePromise; + +const isolatedLoader = compareNodeVersion([20, 0, 0]) >= 0; + +type SendToParent = (data: { + type: 'dependency'; + path: string; +}) => void; + +let sendToParent: SendToParent | undefined = process.send ? process.send.bind(process) : undefined; + +/** + * Technically globalPreload is deprecated so it should be in loaders-deprecated + * but it shares a closure with the new load hook + */ +let mainThreadPort: MessagePort | undefined; +const _globalPreload: GlobalPreloadHook = ({ port }) => { + mainThreadPort = port; + sendToParent = port.postMessage.bind(port); + + return ` + const require = getBuiltin('module').createRequire("${import.meta.url}"); + require('tsx/source-map').installSourceMapSupport(port); + if (process.send) { + port.addListener('message', (message) => { + if (message.type === 'dependency') { + process.send(message); + } + }); + } + port.unref(); // Allows process to exit without waiting for port to close + `; +}; + +export const globalPreload = isolatedLoader ? _globalPreload : undefined; + +const resolveExplicitPath = async ( + defaultResolve: NextResolve, + specifier: string, + context: ResolveHookContext, +) => { + const resolved = await defaultResolve(specifier, context); + + if ( + !resolved.format + && resolved.url.startsWith(fileProtocol) + ) { + resolved.format = await getFormatFromFileUrl(resolved.url); + } + + return resolved; +}; + +const extensions = ['.js', '.json', '.ts', '.tsx', '.jsx'] as const; + +async function tryExtensions( + specifier: string, + context: ResolveHookContext, + defaultResolve: NextResolve, +) { + const [specifierWithoutQuery, query] = specifier.split('?'); + let throwError: Error | undefined; + for (const extension of extensions) { + try { + return await resolveExplicitPath( + defaultResolve, + specifierWithoutQuery + extension + (query ? `?${query}` : ''), + context, + ); + } catch (_error) { + if ( + throwError === undefined + && _error instanceof Error + ) { + const { message } = _error; + _error.message = _error.message.replace(`${extension}'`, "'"); + _error.stack = _error.stack!.replace(message, _error.message); + throwError = _error; + } + } + } + + throw throwError; +} + +async function tryDirectory( + specifier: string, + context: ResolveHookContext, + defaultResolve: NextResolve, +) { + const isExplicitDirectory = isDirectoryPattern.test(specifier); + const appendIndex = isExplicitDirectory ? 'index' : '/index'; + const [specifierWithoutQuery, query] = specifier.split('?'); + + try { + return await tryExtensions( + specifierWithoutQuery + appendIndex + (query ? `?${query}` : ''), + context, + defaultResolve, + ); + } catch (_error) { + if (!isExplicitDirectory) { + try { + return await tryExtensions(specifier, context, defaultResolve); + } catch {} + } + + const error = _error as Error; + const { message } = error; + error.message = error.message.replace(`${appendIndex.replace('/', path.sep)}'`, "'"); + error.stack = error.stack!.replace(message, error.message); + throw error; + } +} + +const isRelativePathPattern = /^\.{1,2}\//; + +const supportsNodePrefix = ( + compareNodeVersion([14, 13, 1]) >= 0 + || compareNodeVersion([12, 20, 0]) >= 0 +); + +export const resolve: resolve = async function ( + specifier, + context, + defaultResolve, + recursiveCall, +) { + // Added in v12.20.0 + // https://nodejs.org/api/esm.html#esm_node_imports + if (!supportsNodePrefix && specifier.startsWith('node:')) { + specifier = specifier.slice(5); + } + + // If directory, can be index.js, index.ts, etc. + if (isDirectoryPattern.test(specifier)) { + return await tryDirectory(specifier, context, defaultResolve); + } + + const isPath = ( + specifier.startsWith(fileProtocol) + || isRelativePathPattern.test(specifier) + ); + + if ( + tsconfigPathsMatcher + && !isPath // bare specifier + && !context.parentURL?.includes('/node_modules/') + ) { + const possiblePaths = tsconfigPathsMatcher(specifier); + for (const possiblePath of possiblePaths) { + try { + return await resolve( + pathToFileURL(possiblePath).toString(), + context, + defaultResolve, + ); + } catch {} + } + } + + /** + * Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions + */ + if ( + // !recursiveCall && + tsExtensionsPattern.test(context.parentURL!) + ) { + const tsPaths = resolveTsPath(specifier); + if (tsPaths) { + for (const tsPath of tsPaths) { + try { + return await resolveExplicitPath(defaultResolve, tsPath, context); + // return await resolve(tsPath, context, defaultResolve, true); + } catch (error) { + const { code } = error as NodeError; + if ( + code !== 'ERR_MODULE_NOT_FOUND' + && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' + ) { + throw error; + } + } + } + } + } + + try { + return await resolveExplicitPath(defaultResolve, specifier, context); + } catch (error) { + if ( + error instanceof Error + && !recursiveCall + ) { + const { code } = error as NodeError; + if (code === 'ERR_UNSUPPORTED_DIR_IMPORT') { + try { + return await tryDirectory(specifier, context, defaultResolve); + } catch (error_) { + if ((error_ as NodeError).code !== 'ERR_PACKAGE_IMPORT_NOT_DEFINED') { + throw error_; + } + } + } + + if (code === 'ERR_MODULE_NOT_FOUND') { + try { + return await tryExtensions(specifier, context, defaultResolve); + } catch {} + } + } + + throw error; + } +}; + +export const load: LoadHook = async function ( + url, + context, + defaultLoad, +) { + if (sendToParent) { + sendToParent({ + type: 'dependency', + path: url, + }); + } + + if (isJsonPattern.test(url)) { + if (!context.importAssertions) { + context.importAssertions = {}; + } + context.importAssertions.type = 'json'; + } + + const loaded = await defaultLoad(url, context); + + if (!loaded.source) { + return loaded; + } + + const filePath = url.startsWith('file://') ? fileURLToPath(url) : url; + const code = loaded.source.toString(); + + if ( + // Support named imports in JSON modules + loaded.format === 'json' + || tsExtensionsPattern.test(url) + ) { + const transformed = await transform( + code, + filePath, + { + tsconfigRaw: fileMatcher?.(filePath) as TransformOptions['tsconfigRaw'], + }, + ); + + return { + format: 'module', + source: applySourceMap(transformed, url, mainThreadPort), + }; + } + + if (loaded.format === 'module') { + const dynamicImportTransformed = transformDynamicImport(filePath, code); + if (dynamicImportTransformed) { + loaded.source = applySourceMap( + dynamicImportTransformed, + url, + mainThreadPort, + ); + } + } + + return loaded; +}; diff --git a/src/esm/loaders-deprecated.ts b/src/esm/loaders-deprecated.ts deleted file mode 100644 index 641b38b90..000000000 --- a/src/esm/loaders-deprecated.ts +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Deprecated ESM loaders used in Node v12 & 14 - * https://nodejs.org/docs/latest-v12.x/api/esm.html#esm_hooks - * https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_hooks - */ -import { fileURLToPath } from 'url'; -import type { ModuleFormat } from 'module'; -import type { TransformOptions } from 'esbuild'; -import { transform, transformDynamicImport } from '../utils/transform'; -import { compareNodeVersion } from '../utils/compare-node-version'; -import { - applySourceMap, - fileMatcher, - tsExtensionsPattern, - getFormatFromFileUrl, - fileProtocol, - isJsonPattern, - type MaybePromise, - type NodeError, -} from './utils.js'; - -type getFormat = ( - url: string, - context: Record, - defaultGetFormat: getFormat, -) => MaybePromise<{ format: ModuleFormat }>; - -const _getFormat: getFormat = async function ( - url, - context, - defaultGetFormat, -) { - if (isJsonPattern.test(url)) { - return { format: 'module' }; - } - - try { - return await defaultGetFormat(url, context, defaultGetFormat); - } catch (error) { - if ( - (error as NodeError).code === 'ERR_UNKNOWN_FILE_EXTENSION' - && url.startsWith(fileProtocol) - ) { - const format = await getFormatFromFileUrl(url); - if (format) { - return { format }; - } - } - - throw error; - } -}; - -type Source = string | SharedArrayBuffer | Uint8Array; - -type transformSource = ( - source: Source, - context: { - url: string; - format: ModuleFormat; - }, - defaultTransformSource: transformSource, -) => MaybePromise<{ source: Source }> - -const _transformSource: transformSource = async function ( - source, - context, - defaultTransformSource, -) { - const { url } = context; - const filePath = url.startsWith('file://') ? fileURLToPath(url) : url; - - if (process.send) { - process.send({ - type: 'dependency', - path: url, - }); - } - - if ( - isJsonPattern.test(url) - || tsExtensionsPattern.test(url) - ) { - const transformed = await transform( - source.toString(), - filePath, - { - tsconfigRaw: fileMatcher?.(filePath) as TransformOptions['tsconfigRaw'], - }, - ); - - return { - source: applySourceMap(transformed, url), - }; - } - - const result = await defaultTransformSource(source, context, defaultTransformSource); - - if (context.format === 'module') { - const dynamicImportTransformed = transformDynamicImport(filePath, result.source.toString()); - if (dynamicImportTransformed) { - result.source = applySourceMap( - dynamicImportTransformed, - url, - ); - } - } - - return result; -}; - -const nodeSupportsDeprecatedLoaders = compareNodeVersion([16, 12, 0]) < 0; - -export const getFormat = nodeSupportsDeprecatedLoaders ? _getFormat : undefined; -export const transformSource = nodeSupportsDeprecatedLoaders ? _transformSource : undefined; diff --git a/src/esm/loaders.ts b/src/esm/loaders.ts deleted file mode 100644 index 872db0792..000000000 --- a/src/esm/loaders.ts +++ /dev/null @@ -1,310 +0,0 @@ -import type { MessagePort } from 'node:worker_threads'; -import path from 'path'; -import { pathToFileURL, fileURLToPath } from 'url'; -import type { - ResolveFnOutput, ResolveHookContext, LoadHook, GlobalPreloadHook, -} from 'module'; -import type { TransformOptions } from 'esbuild'; -import { compareNodeVersion } from '../utils/compare-node-version'; -import { transform, transformDynamicImport } from '../utils/transform'; -import { resolveTsPath } from '../utils/resolve-ts-path'; -import { - applySourceMap, - tsconfigPathsMatcher, - fileMatcher, - tsExtensionsPattern, - isJsonPattern, - getFormatFromFileUrl, - fileProtocol, - type MaybePromise, - type NodeError, -} from './utils.js'; - -const isDirectoryPattern = /\/(?:$|\?)/; - -type NextResolve = ( - specifier: string, - context?: ResolveHookContext, -) => MaybePromise; - -type resolve = ( - specifier: string, - context: ResolveHookContext, - nextResolve: NextResolve, - recursiveCall?: boolean, -) => MaybePromise; - -const isolatedLoader = compareNodeVersion([20, 0, 0]) >= 0; - -type SendToParent = (data: { - type: 'dependency'; - path: string; -}) => void; - -let sendToParent: SendToParent | undefined = process.send ? process.send.bind(process) : undefined; - -/** - * Technically globalPreload is deprecated so it should be in loaders-deprecated - * but it shares a closure with the new load hook - */ -let mainThreadPort: MessagePort | undefined; -const _globalPreload: GlobalPreloadHook = ({ port }) => { - mainThreadPort = port; - sendToParent = port.postMessage.bind(port); - - return ` - const require = getBuiltin('module').createRequire("${import.meta.url}"); - require('tsx/source-map').installSourceMapSupport(port); - if (process.send) { - port.addListener('message', (message) => { - if (message.type === 'dependency') { - process.send(message); - } - }); - } - port.unref(); // Allows process to exit without waiting for port to close - `; -}; - -export const globalPreload = isolatedLoader ? _globalPreload : undefined; - -const resolveExplicitPath = async ( - defaultResolve: NextResolve, - specifier: string, - context: ResolveHookContext, -) => { - const resolved = await defaultResolve(specifier, context); - - if ( - !resolved.format - && resolved.url.startsWith(fileProtocol) - ) { - resolved.format = await getFormatFromFileUrl(resolved.url); - } - - return resolved; -}; - -const extensions = ['.js', '.json', '.ts', '.tsx', '.jsx'] as const; - -async function tryExtensions( - specifier: string, - context: ResolveHookContext, - defaultResolve: NextResolve, -) { - const [specifierWithoutQuery, query] = specifier.split('?'); - let throwError: Error | undefined; - for (const extension of extensions) { - try { - return await resolveExplicitPath( - defaultResolve, - specifierWithoutQuery + extension + (query ? `?${query}` : ''), - context, - ); - } catch (_error) { - if ( - throwError === undefined - && _error instanceof Error - ) { - const { message } = _error; - _error.message = _error.message.replace(`${extension}'`, "'"); - _error.stack = _error.stack!.replace(message, _error.message); - throwError = _error; - } - } - } - - throw throwError; -} - -async function tryDirectory( - specifier: string, - context: ResolveHookContext, - defaultResolve: NextResolve, -) { - const isExplicitDirectory = isDirectoryPattern.test(specifier); - const appendIndex = isExplicitDirectory ? 'index' : '/index'; - const [specifierWithoutQuery, query] = specifier.split('?'); - - try { - return await tryExtensions( - specifierWithoutQuery + appendIndex + (query ? `?${query}` : ''), - context, - defaultResolve, - ); - } catch (_error) { - if (!isExplicitDirectory) { - try { - return await tryExtensions(specifier, context, defaultResolve); - } catch {} - } - - const error = _error as Error; - const { message } = error; - error.message = error.message.replace(`${appendIndex.replace('/', path.sep)}'`, "'"); - error.stack = error.stack!.replace(message, error.message); - throw error; - } -} - -const isRelativePathPattern = /^\.{1,2}\//; - -const supportsNodePrefix = ( - compareNodeVersion([14, 13, 1]) >= 0 - || compareNodeVersion([12, 20, 0]) >= 0 -); - -export const resolve: resolve = async function ( - specifier, - context, - defaultResolve, - recursiveCall, -) { - // Added in v12.20.0 - // https://nodejs.org/api/esm.html#esm_node_imports - if (!supportsNodePrefix && specifier.startsWith('node:')) { - specifier = specifier.slice(5); - } - - // If directory, can be index.js, index.ts, etc. - if (isDirectoryPattern.test(specifier)) { - return await tryDirectory(specifier, context, defaultResolve); - } - - const isPath = ( - specifier.startsWith(fileProtocol) - || isRelativePathPattern.test(specifier) - ); - - if ( - tsconfigPathsMatcher - && !isPath // bare specifier - && !context.parentURL?.includes('/node_modules/') - ) { - const possiblePaths = tsconfigPathsMatcher(specifier); - for (const possiblePath of possiblePaths) { - try { - return await resolve( - pathToFileURL(possiblePath).toString(), - context, - defaultResolve, - ); - } catch {} - } - } - - /** - * Typescript gives .ts, .cts, or .mts priority over actual .js, .cjs, or .mjs extensions - */ - if ( - // !recursiveCall && - tsExtensionsPattern.test(context.parentURL!) - ) { - const tsPaths = resolveTsPath(specifier); - if (tsPaths) { - for (const tsPath of tsPaths) { - try { - return await resolveExplicitPath(defaultResolve, tsPath, context); - // return await resolve(tsPath, context, defaultResolve, true); - } catch (error) { - const { code } = error as NodeError; - if ( - code !== 'ERR_MODULE_NOT_FOUND' - && code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED' - ) { - throw error; - } - } - } - } - } - - try { - return await resolveExplicitPath(defaultResolve, specifier, context); - } catch (error) { - if ( - error instanceof Error - && !recursiveCall - ) { - const { code } = error as NodeError; - if (code === 'ERR_UNSUPPORTED_DIR_IMPORT') { - try { - return await tryDirectory(specifier, context, defaultResolve); - } catch (error_) { - if ((error_ as NodeError).code !== 'ERR_PACKAGE_IMPORT_NOT_DEFINED') { - throw error_; - } - } - } - - if (code === 'ERR_MODULE_NOT_FOUND') { - try { - return await tryExtensions(specifier, context, defaultResolve); - } catch {} - } - } - - throw error; - } -}; - -export const load: LoadHook = async function ( - url, - context, - defaultLoad, -) { - if (sendToParent) { - sendToParent({ - type: 'dependency', - path: url, - }); - } - - if (isJsonPattern.test(url)) { - if (!context.importAssertions) { - context.importAssertions = {}; - } - context.importAssertions.type = 'json'; - } - - const loaded = await defaultLoad(url, context); - - if (!loaded.source) { - return loaded; - } - - const filePath = url.startsWith('file://') ? fileURLToPath(url) : url; - const code = loaded.source.toString(); - - if ( - // Support named imports in JSON modules - loaded.format === 'json' - || tsExtensionsPattern.test(url) - ) { - const transformed = await transform( - code, - filePath, - { - tsconfigRaw: fileMatcher?.(filePath) as TransformOptions['tsconfigRaw'], - }, - ); - - return { - format: 'module', - source: applySourceMap(transformed, url, mainThreadPort), - }; - } - - if (loaded.format === 'module') { - const dynamicImportTransformed = transformDynamicImport(filePath, code); - if (dynamicImportTransformed) { - loaded.source = applySourceMap( - dynamicImportTransformed, - url, - mainThreadPort, - ); - } - } - - return loaded; -}; From 6ac8076f1b43b505b0f757b4b0f5d5ebd08f2482 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 26 Sep 2023 01:14:11 +0900 Subject: [PATCH 03/58] wip --- README.md | 4 +--- src/cjs/index.ts | 12 ------------ src/esm/index.ts | 11 ----------- 3 files changed, 1 insertion(+), 26 deletions(-) diff --git a/README.md b/README.md index b7ae8aad2..ae04d44ad 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,9 @@ - Blazing fast on-demand TypeScript & ESM compilation - Works in both [CommonJS and ESM packages](https://nodejs.org/api/packages.html#type) - Supports next-gen TypeScript extensions (`.cts` & `.mts`) -- Supports `node:` import prefixes - Hides experimental feature warnings - TypeScript REPL - Resolves `tsconfig.json` [`paths`](https://www.typescriptlang.org/tsconfig#paths) -- Tested on Linux & Windows with Node.js v12~20 > **💡 Protip: Looking to bundle your TypeScript project?** > @@ -45,7 +43,7 @@ How does it compare to [ts-node](https://github.com/TypeStrong/ts-node)? Checkou tsx strives to: 1. Enhance Node.js with TypeScript compatibility 2. Improve ESM <-> CJS interoperability -3. Support the latest major version of Node.js v12 and up _(likely to change in the future)_ +3. Support the [LTS versions of Node.js](https://endoflife.date/nodejs) ## Install diff --git a/src/cjs/index.ts b/src/cjs/index.ts index f778cfa74..0116fe3c1 100644 --- a/src/cjs/index.ts +++ b/src/cjs/index.ts @@ -137,20 +137,8 @@ Object.defineProperty(extensions, '.mjs', { enumerable: false, }); -const supportsNodePrefix = ( - compareNodeVersion([16, 0, 0]) >= 0 - || compareNodeVersion([14, 18, 0]) >= 0 -); - -// Add support for "node:" protocol const defaultResolveFilename = Module._resolveFilename.bind(Module); Module._resolveFilename = (request, parent, isMain, options) => { - // Added in v12.20.0 - // https://nodejs.org/api/esm.html#esm_node_imports - if (!supportsNodePrefix && request.startsWith('node:')) { - request = request.slice(5); - } - if ( tsconfigPathsMatcher diff --git a/src/esm/index.ts b/src/esm/index.ts index 872db0792..59200d647 100644 --- a/src/esm/index.ts +++ b/src/esm/index.ts @@ -149,23 +149,12 @@ async function tryDirectory( const isRelativePathPattern = /^\.{1,2}\//; -const supportsNodePrefix = ( - compareNodeVersion([14, 13, 1]) >= 0 - || compareNodeVersion([12, 20, 0]) >= 0 -); - export const resolve: resolve = async function ( specifier, context, defaultResolve, recursiveCall, ) { - // Added in v12.20.0 - // https://nodejs.org/api/esm.html#esm_node_imports - if (!supportsNodePrefix && specifier.startsWith('node:')) { - specifier = specifier.slice(5); - } - // If directory, can be index.js, index.ts, etc. if (isDirectoryPattern.test(specifier)) { return await tryDirectory(specifier, context, defaultResolve); From dd73218070fb344899bdce4710e67fc46ca4bdaa Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 26 Sep 2023 01:21:58 +0900 Subject: [PATCH 04/58] wip --- src/cjs/index.ts | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/cjs/index.ts b/src/cjs/index.ts index 0116fe3c1..b351c2d26 100644 --- a/src/cjs/index.ts +++ b/src/cjs/index.ts @@ -11,7 +11,6 @@ import type { TransformOptions } from 'esbuild'; import { installSourceMapSupport } from '../source-map'; import { transformSync, transformDynamicImport } from '../utils/transform'; import { resolveTsPath } from '../utils/resolve-ts-path'; -import { compareNodeVersion } from '../utils/compare-node-version'; const isRelativePathPattern = /^\.{1,2}\//; const isTsFilePatten = /\.[cm]?tsx?$/; @@ -31,17 +30,6 @@ const tsconfigPathsMatcher = tsconfig && createPathsMatcher(tsconfig); const applySourceMap = installSourceMapSupport(); -const nodeSupportsImport = ( - // v13.2.0 and higher - compareNodeVersion([13, 2, 0]) >= 0 - - // 12.20.0 ~ 13.0.0 - || ( - compareNodeVersion([12, 20, 0]) >= 0 - && compareNodeVersion([13, 0, 0]) < 0 - ) -); - const extensions = Module._extensions; const defaultLoader = extensions['.js']; @@ -77,7 +65,7 @@ const transformer = ( let code = fs.readFileSync(filePath, 'utf8'); - if (filePath.endsWith('.cjs') && nodeSupportsImport) { + if (filePath.endsWith('.cjs')) { const transformed = transformDynamicImport(filePath, code); if (transformed) { code = applySourceMap(transformed, filePath); From 33cb8bf1714a50dc9333f165d164eaddc6de4053 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 30 Oct 2023 22:13:28 +0900 Subject: [PATCH 05/58] wip --- tests/index.ts | 62 +--- tests/specs/cli.ts | 259 +++++++++------- tests/specs/smoke.ts | 574 +++++++++++++++++++++++++++++++++++ tests/specs/watch.ts | 16 +- tests/utils/node-versions.ts | 2 +- tests/utils/tsx.ts | 131 +------- 6 files changed, 768 insertions(+), 276 deletions(-) create mode 100644 tests/specs/smoke.ts diff --git a/tests/index.ts b/tests/index.ts index c5e014756..9a332b53f 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -1,63 +1,21 @@ import { describe } from 'manten'; -import { createFixture } from 'fs-fixture'; import { createNode } from './utils/tsx'; import { nodeVersions } from './utils/node-versions'; -const packageTypes = [ - 'commonjs', - 'module', -] as const; - (async () => { - for (const packageType of packageTypes) { - await describe(`Package type: ${packageType}`, async ({ describe, onFinish }) => { - const fixture = await createFixture('./tests/fixtures/'); - - onFinish(async () => await fixture.rm()); + await describe('tsx', async ({ runTestSuite, describe }) => { + runTestSuite(import('./specs/cli')); + runTestSuite(import('./specs/watch')); - await fixture.writeJson('package.json', { - type: packageType, - }); + for (const nodeVersion of nodeVersions) { + const node = await createNode(nodeVersion); - await describe('tsx', ({ runTestSuite }) => { - runTestSuite( - import('./specs/cli'), - fixture.path, - ); + await describe(`Node ${node.version}`, ({ runTestSuite }) => { runTestSuite( - import('./specs/watch'), - fixture.path, + import('./specs/smoke'), + node, ); }); - - for (const nodeVersion of nodeVersions) { - const node = await createNode(nodeVersion, fixture.path); - - node.packageType = packageType; - - await describe(`Node ${node.version}`, ({ runTestSuite }) => { - runTestSuite( - import('./specs/repl'), - node, - ); - runTestSuite( - import('./specs/javascript'), - node, - ); - runTestSuite( - import('./specs/typescript'), - node, - ); - runTestSuite( - import('./specs/json'), - node, - ); - runTestSuite( - import('./specs/wasm'), - node, - ); - }); - } - }); - } + } + }); })(); diff --git a/tests/specs/cli.ts b/tests/specs/cli.ts index 65c32d8e6..149188f55 100644 --- a/tests/specs/cli.ts +++ b/tests/specs/cli.ts @@ -1,69 +1,90 @@ import path from 'path'; import { testSuite, expect } from 'manten'; +import { createFixture } from 'fs-fixture'; import packageJson from '../../package.json'; import { tsx, tsxPath } from '../utils/tsx'; import { ptyShell, isWindows } from '../utils/pty-shell'; -export default testSuite(({ describe }, fixturePath: string) => { +export default testSuite(({ describe }) => { describe('CLI', ({ describe, test }) => { - describe('version', ({ test }) => { - test('shows version', async () => { - const tsxProcess = await tsx({ - args: ['--version'], - }); - - expect(tsxProcess.exitCode).toBe(0); - expect(tsxProcess.stdout).toBe(`tsx v${packageJson.version}\nnode ${process.version}`); - expect(tsxProcess.stderr).toBe(''); + describe('argv', async ({ describe, onFinish }) => { + const fixture = await createFixture({ + // Unnecessary TS to test syntax + 'log-argv.ts': 'console.log(JSON.stringify(process.argv) as string)', }); + onFinish(async () => await fixture.rm()); - test('doesn\'t show version with file', async () => { - const tsxProcess = await tsx({ - args: [ - path.join(fixturePath, 'log-argv.ts'), - '--version', - ], + describe('version', ({ test }) => { + test('shows version', async () => { + const tsxProcess = await tsx({ + args: ['--version'], + }); + + expect(tsxProcess.exitCode).toBe(0); + expect(tsxProcess.stdout).toBe(`tsx v${packageJson.version}\nnode ${process.version}`); + expect(tsxProcess.stderr).toBe(''); }); - expect(tsxProcess.exitCode).toBe(0); - expect(tsxProcess.stdout).toMatch('"--version"'); - expect(tsxProcess.stdout).not.toMatch(packageJson.version); - expect(tsxProcess.stderr).toBe(''); - }); - }); + test('doesn\'t show version with file', async () => { + const tsxProcess = await tsx({ + args: [ + path.join(fixture.path, 'log-argv.ts'), + '--version', + ], + }); - describe('help', ({ test }) => { - test('shows help', async () => { - const tsxProcess = await tsx({ - args: ['--help'], + expect(tsxProcess.exitCode).toBe(0); + expect(tsxProcess.stdout).toMatch('"--version"'); + expect(tsxProcess.stdout).not.toMatch(packageJson.version); + expect(tsxProcess.stderr).toBe(''); }); - - expect(tsxProcess.exitCode).toBe(0); - expect(tsxProcess.stdout).toMatch('Node.js runtime enhanced with esbuild for loading TypeScript & ESM'); - expect(tsxProcess.stdout).toMatch('Usage: node [options] [ script.js ] [arguments]'); - expect(tsxProcess.stderr).toBe(''); }); - test('doesn\'t show help with file', async () => { - const tsxProcess = await tsx({ - args: [ - path.join(fixturePath, 'log-argv.ts'), - '--help', - ], + describe('help', ({ test }) => { + test('shows help', async () => { + const tsxProcess = await tsx({ + args: ['--help'], + }); + + expect(tsxProcess.exitCode).toBe(0); + expect(tsxProcess.stdout).toMatch('Node.js runtime enhanced with esbuild for loading TypeScript & ESM'); + expect(tsxProcess.stdout).toMatch('Usage: node [options] [ script.js ] [arguments]'); + expect(tsxProcess.stderr).toBe(''); }); - expect(tsxProcess.exitCode).toBe(0); - expect(tsxProcess.stdout).toMatch('"--help"'); - expect(tsxProcess.stdout).not.toMatch('tsx'); - expect(tsxProcess.stderr).toBe(''); + test('doesn\'t show help with file', async () => { + const tsxProcess = await tsx({ + args: [ + path.join(fixture.path, 'log-argv.ts'), + '--help', + ], + }); + + expect(tsxProcess.exitCode).toBe(0); + expect(tsxProcess.stdout).toMatch('"--help"'); + expect(tsxProcess.stdout).not.toMatch('tsx'); + expect(tsxProcess.stderr).toBe(''); + }); }); }); - test('Node.js test runner', async () => { + test('Node.js test runner', async ({ onTestFinish }) => { + const fixture = await createFixture({ + 'test.ts': ` + import { test } from 'node:test'; + import assert from 'assert'; + + test('passing test', () => { + assert.strictEqual(1, 1); + }); + `, + }); + onTestFinish(async () => await fixture.rm()); + const tsxProcess = await tsx({ args: [ '--test', - path.join(fixturePath, 'test-runner-file.ts'), + path.join(fixture.path, 'test.ts'), ], }); @@ -71,71 +92,105 @@ export default testSuite(({ describe }, fixturePath: string) => { expect(tsxProcess.exitCode).toBe(0); }, 10_000); - describe('Relays kill signal', ({ test }) => { - const signals = ['SIGINT', 'SIGTERM']; - - for (const signal of signals) { - test(signal, async () => { - const tsxProcess = tsx({ - args: [ - path.join(fixturePath, 'catch-signals.js'), - ], + describe('Signals', async ({ describe, onFinish }) => { + const fixture = await createFixture({ + 'catch-signals.js': ` + const signals = [ + 'SIGINT', + 'SIGTERM', + ]; + + for (const name of signals) { + process.on(name, () => { + console.log(name); + + setTimeout(() => { + console.log(name, 'HANDLER COMPLETED'); + process.exit(200); + }, 100); }); + } + + setTimeout(() => {}, 1e5); + console.log('READY'); + `, + 'keep-alive.js': ` + setTimeout(() => {}, 1e5); + console.log('READY'); + `, + }); + onFinish(async () => await fixture.rm()); - tsxProcess.stdout!.once('data', () => { - tsxProcess.kill(signal, { - forceKillAfterTimeout: false, + describe('Relays kill signal', ({ test }) => { + const signals = ['SIGINT', 'SIGTERM']; + + for (const signal of signals) { + test(signal, async ({ onTestFail }) => { + const tsxProcess = tsx({ + args: [ + path.join(fixture.path, 'catch-signals.js'), + ], }); - }); - const tsxProcessResolved = await tsxProcess; - - if (process.platform === 'win32') { - /** - * Windows doesn't support sending signals to processes. - * https://nodejs.org/api/process.html#signal-events - * - * Sending SIGINT, SIGTERM, and SIGKILL will cause the unconditional termination - * of the target process, and afterwards, subprocess will report that the process - * was terminated by signal. - */ - expect(tsxProcessResolved.stdout).toBe('READY'); - } else { - expect(tsxProcessResolved.exitCode).toBe(200); - expect(tsxProcessResolved.stdout).toBe(`READY\n${signal}\n${signal} HANDLER COMPLETED`); - } + tsxProcess.stdout!.once('data', () => { + tsxProcess.kill(signal, { + forceKillAfterTimeout: false, + }); + }); + + const tsxProcessResolved = await tsxProcess; + + onTestFail(() => { + console.log(tsxProcessResolved); + }); + + if (process.platform === 'win32') { + /** + * Windows doesn't support sending signals to processes. + * https://nodejs.org/api/process.html#signal-events + * + * Sending SIGINT, SIGTERM, and SIGKILL will cause the unconditional termination + * of the target process, and afterwards, subprocess will report that the process + * was terminated by signal. + */ + expect(tsxProcessResolved.stdout).toBe('READY'); + } else { + expect(tsxProcessResolved.exitCode).toBe(200); + expect(tsxProcessResolved.stdout).toBe(`READY\n${signal}\n${signal} HANDLER COMPLETED`); + } + }, 10_000); + } + }); + + describe('Ctrl + C', ({ test }) => { + test('Exit code', async () => { + const output = await ptyShell( + [ + `${process.execPath} ${tsxPath} ${path.join(fixture.path, 'keep-alive.js')}\r`, + stdout => stdout.includes('READY') && '\u0003', + `echo EXIT_CODE: ${isWindows ? '$LastExitCode' : '$?'}\r`, + ], + ); + expect(output).toMatch(/EXIT_CODE:\s+130/); }, 10_000); - } - }); - describe('Ctrl + C', ({ test }) => { - test('Exit code', async () => { - const output = await ptyShell( - [ - `${process.execPath} ${tsxPath} ./tests/fixtures/keep-alive.js\r`, - stdout => stdout.includes('READY') && '\u0003', - `echo EXIT_CODE: ${isWindows ? '$LastExitCode' : '$?'}\r`, - ], - ); - expect(output).toMatch(/EXIT_CODE:\s+130/); - }, 10_000); - - test('Catchable', async () => { - const output = await ptyShell( - [ - `${process.execPath} ${tsxPath} ./tests/fixtures/catch-signals.js\r`, - stdout => stdout.includes('READY') && '\u0003', - `echo EXIT_CODE: ${isWindows ? '$LastExitCode' : '$?'}\r`, - ], - ); - - expect(output).toMatch( - process.platform === 'win32' - ? 'READY\r\nSIGINT\r\nSIGINT HANDLER COMPLETED\r\n' - : 'READY\r\n^CSIGINT\r\nSIGINT HANDLER COMPLETED\r\n', - ); - expect(output).toMatch(/EXIT_CODE:\s+200/); - }, 10_000); + test('Catchable', async () => { + const output = await ptyShell( + [ + `${process.execPath} ${tsxPath} ${path.join(fixture.path, 'catch-signals.js')}\r`, + stdout => stdout.includes('READY') && '\u0003', + `echo EXIT_CODE: ${isWindows ? '$LastExitCode' : '$?'}\r`, + ], + ); + + expect(output).toMatch( + process.platform === 'win32' + ? 'READY\r\nSIGINT\r\nSIGINT HANDLER COMPLETED\r\n' + : 'READY\r\n^CSIGINT\r\nSIGINT HANDLER COMPLETED\r\n', + ); + expect(output).toMatch(/EXIT_CODE:\s+200/); + }, 10_000); + }); }); }); }); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts new file mode 100644 index 000000000..c8734d754 --- /dev/null +++ b/tests/specs/smoke.ts @@ -0,0 +1,574 @@ +import path from 'path'; +import { testSuite, expect } from 'manten'; +import { createFixture } from 'fs-fixture'; +import type { NodeApis } from '../utils/tsx'; + +const cjsContextCheck = 'typeof module !== \'undefined\''; +const tsCheck = '1 as number'; + +const declareReact = ` +const React = { + createElement: (...args) => Array.from(args), +}; +`; +const jsxCheck = '<>
JSX
'; + +const nameInError = ` +let nameInError; +try { + nameInError(); +} catch (error) { + assert(error.message.includes('nameInError'), 'Name should be in error'); +} +`; + +const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); + +const syntaxLowering = ` +// es2016 - Exponentiation operator +10 ** 4; + +// es2017 - Async functions +(async () => {}); + +// es2018 - Spread properties +({...Object}); + +// es2018 - Rest properties +const {...x} = Object; + +// es2019 - Optional catch binding +try {} catch {} + +// es2020 - Optional chaining +Object?.keys; + +// es2020 - Nullish coalescing +Object ?? true + +// es2020 - import.meta +// import.meta + +// es2021 - Logical assignment operators +let a = false; a ??= true; a ||= true; a &&= true; + +// es2022 - Class instance fields +(class { x }); + +// es2022 - Static class fields +(class { static x }); + +// es2022 - Private instance methods +(class { #x() {} }); + +// es2022 - Private instance fields +(class { #x }); + +// es2022 - Private static methods +(class { static #x() {} }); + +// es2022 - Private static fields +(class { static #x }); + +// es2022 - Class static blocks +(class { static {} }); + +export const esmNamedExport = 123; +`; + +const sourcemap = { + test: 'const { stack } = new Error(); assert(stack.includes(\':SOURCEMAP_LINE\'), \'Expected SOURCEMAP_LINE in stack:\' + stack)', + tag: ( + strings: TemplateStringsArray, + ...values: string[] + ) => { + const finalString = String.raw({ raw: strings }, ...values); + const line = finalString.split('\n').findIndex(line => line.includes('SOURCEMAP_LINE')) + 1; + return finalString.replaceAll('SOURCEMAP_LINE', line.toString()); + }, +}; + +const files = { + 'js/index.js': ` + import assert from 'assert'; + ${syntaxLowering} + ${nameInError} + export const cjsContext = ${cjsContextCheck}; + `, + + 'json/index.json': JSON.stringify({ loaded: 'json' }), + + 'cjs/index.cjs': sourcemap.tag` + const assert = require('node:assert'); + assert(${cjsContextCheck}, 'Should have CJS context'); + ${nameInError} + ${sourcemap.test} + exports.named = 'named'; + `, + + 'mjs/index.mjs': ` + export const mjsHasCjsContext = ${cjsContextCheck}; + `, + + 'ts/index.ts': sourcemap.tag` + import assert from 'assert'; + import type {Type} from 'resolved-by-tsc' + + interface Foo {} + + type Foo = number + + declare module 'foo' {} + + enum BasicEnum { + Left, + Right, + } + + enum NamedEnum { + SomeEnum = 'some-value', + } + + export const a = BasicEnum.Left; + + export const b = NamedEnum.SomeEnum; + + export default function foo(): string { + return 'foo' + } + + // For "ts as tsx" test + const bar = (value: T) => fn(); + + ${nameInError} + ${sourcemap.test} + export const cjsContext = ${cjsContextCheck}; + ${tsCheck}; + `, + + // TODO: test resolution priority for files 'index.tsx` & 'index.tsx.ts` via 'index.tsx' + + 'jsx/index.jsx': sourcemap.tag` + import assert from 'assert'; + export const cjsContext = ${cjsContextCheck}; + ${declareReact} + export const jsx = ${jsxCheck}; + ${nameInError} + ${sourcemap.test} + `, + + 'tsx/index.tsx': sourcemap.tag` + import assert from 'assert'; + export const cjsContext = ${cjsContextCheck}; + ${tsCheck}; + ${declareReact} + export const jsx = ${jsxCheck}; + ${nameInError} + ${sourcemap.test} + `, + + 'mts/index.mts': sourcemap.tag` + import assert from 'assert'; + export const mjsHasCjsContext = ${cjsContextCheck}; + ${tsCheck}; + ${nameInError} + ${sourcemap.test} + `, + + 'cts/index.cts': sourcemap.tag` + const assert = require('assert'); + assert(${cjsContextCheck}, 'Should have CJS context'); + ${tsCheck}; + ${nameInError} + ${sourcemap.test} + `, + + 'expect-errors.js': ` + export const expectErrors = async (...assertions) => { + let errors = await Promise.all( + assertions.map(async ([fn, expectedError]) => { + let thrown; + try { + await fn(); + } catch (error) { + thrown = error; + } + + if (!thrown) { + return new Error('No error thrown'); + } else if (!thrown.message.includes(expectedError)) { + return new Error(\`Message \${JSON.stringify(expectedError)} not found in \${JSON.stringify(thrown.message)}\`); + } + }), + ); + + errors = errors.filter(Boolean); + + if (errors.length > 0) { + throw new AggregateError(errors); + } + }; + `, + + 'file.txt': 'hello', + + 'node_modules/dep': { + 'package.json': '{}', + 'index.js': syntaxLowering, + }, + + tsconfig: { + 'file.ts': '', + + 'jsx.jsx': ` + // tsconfig not applied to jsx because allowJs is not set + import { expectErrors } from '../expect-errors'; + expectErrors( + [() => ${jsxCheck}, 'React is not defined'], + + // These should throw unless allowJs is set + // [() => import('prefix/file'), "Cannot find package 'prefix'"], + // [() => import('paths-exact-match'), "Cannot find package 'paths-exact-match'"], + // [() => import('file'), "Cannot find package 'file'"], + ); + `, + + 'node_modules/tsconfig-should-not-apply': { + 'package.json': JSON.stringify({ + exports: { + import: './index.mjs', + default: './index.cjs', + }, + }), + 'index.mjs': ` + import { expectErrors } from '../../../expect-errors'; + expectErrors( + [() => import('prefix/file'), "Cannot find package 'prefix'"], + [() => import('paths-exact-match'), "Cannot find package 'paths-exact-match'"], + [() => import('file'), "Cannot find package 'file'"], + ); + `, + 'index.cjs': ` + const { expectErrors } = require('../../../expect-errors'); + expectErrors( + [() => require('prefix/file'), "Cannot find module"], + [() => require('paths-exact-match'), "Cannot find module"], + [() => require('file'), "Cannot find module"], + ); + `, + }, + + 'index.tsx': ` + ${jsxCheck}; + + import './jsx'; + + // Resolves relative to baseUrl + import 'file'; + + // Resolves paths - exact match + import 'paths-exact-match'; + + // Resolves paths - prefix match + import 'prefix/file'; + + // Resolves paths - suffix match + import 'file/suffix'; + + // tsconfig should not apply to dependency + import "tsconfig-should-not-apply"; + `, + + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + jsxFactory: 'Array', + jsxFragmentFactory: 'null', + baseUrl: '.', + paths: { + 'paths-exact-match': ['file'], + 'prefix/*': ['*'], + '*/suffix': ['*'], + }, + }, + }), + + 'tsconfig-allowJs.json': JSON.stringify({ + extends: './tsconfig.json', + compilerOptions: { + allowJs: true, + }, + }), + }, +}; + +export default testSuite(async ({ describe }, { tsx }: NodeApis) => { + describe('Smoke', ({ describe }) => { + for (const packageType of ['module', 'commonjs']) { + const isCommonJs = packageType === 'commonjs'; + + describe(packageType, ({ test }) => { + test('from .js', async ({ onTestFinish, onTestFail }) => { + const fixture = await createFixture({ + ...files, + 'package.json': JSON.stringify({ type: packageType }), + 'import-from-js.js': ` + import { expectErrors } from './expect-errors'; + + // node: prefix + import 'node:fs'; + + import 'dep'; + + // .js + import * as js from './js/index.js'; + import './js/index'; + import './js/'; + + // .json + import * as json from './json/index.json'; + import './json/index'; + import './json/'; + + // .cjs + import * as cjs from './cjs/index.cjs'; + expectErrors( + [() => import('./cjs/index'), 'Cannot find module'], + [() => import('./cjs/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./cjs/index'), 'Cannot find module'], + [() => require('./cjs/'), 'Cannot find module'], + ` + : '' + } + ); + + // .mjs + import * as mjs from './mjs/index.mjs'; + expectErrors( + [() => import('./mjs/index'), 'Cannot find module'], + [() => import('./mjs/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./mjs/index'), 'Cannot find module'], + [() => require('./mjs/'), 'Cannot find module'], + ` + : '' + } + ); + + // Is TS loadable here? + // Import jsx? + + // Unsupported files + expectErrors( + [() => import('./file.txt'), 'Unknown file extension'], + [() => import('${wasmPath}'), 'Unknown file extension'], + ${ + isCommonJs + ? ` + [() => require('./file.txt'), 'hello is not defined'], + [() => require('${wasmPath}'), 'Invalid or unexpected token'], + ` + : '' + } + ); + + console.log(JSON.stringify({ + js, + json, + cjs, + mjs, + })); + + // Could .js import TS files? + `, + }); + + onTestFinish(async () => await fixture.rm()); + + const p = await tsx(['import-from-js.js'], fixture.path); + onTestFail(() => { + console.log(p); + }); + expect(p.failed).toBe(false); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); + expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); + expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); + + // By "require()"ing an ESM file, it forces it to be compiled in a CJS context + expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); + + expect(p.stderr).toBe(''); + }); + + test('from .ts', async ({ onTestFinish, onTestFail }) => { + const fixture = await createFixture({ + ...files, + 'package.json': JSON.stringify({ type: packageType }), + + 'import-from-ts.ts': ` + import { expectErrors } from './expect-errors'; + + // node: prefix + import 'node:fs'; + + import 'dep'; + + // .js + import * as js from './js/index.js'; + import './js/index'; + import './js/'; + + // .json + import * as json from './json/index.json'; + import './json/index'; + import './json/'; + + // .cjs + import * as cjs from './cjs/index.cjs'; + expectErrors( + [() => import('./cjs/index'), 'Cannot find module'], + [() => import('./cjs/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./cjs/index'), 'Cannot find module'], + [() => require('./cjs/'), 'Cannot find module'], + ` + : '' + } + ); + + // .mjs + import * as mjs from './mjs/index.mjs'; + expectErrors( + [() => import('./mjs/index'), 'Cannot find module'], + [() => import('./mjs/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./mjs/index'), 'Cannot find module'], + [() => require('./mjs/'), 'Cannot find module'], + ` + : '' + } + ); + + // .ts + import './ts/index.ts'; + import './ts/index.js'; + // import './ts/index.jsx'; + import './ts/index'; + import './ts/'; + + // .jsx + import * as jsx from './jsx/index.jsx'; + // import './jsx/index.js'; + import './jsx/index'; + import './jsx/'; + + // .tsx + import './tsx/index.tsx'; + // import './tsx/index.js'; + import './tsx/index.jsx'; + import './tsx/index'; + import './tsx/'; + + // .cts + import './cts/index.cjs'; + expectErrors( + // [() => import('./cts/index.cts'), 'Cannot find module'], + [() => import('./cts/index'), 'Cannot find module'], + [() => import('./cts/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./cts/index'), 'Cannot find module'], + [() => require('./cts/'), 'Cannot find module'], + ` + : '' + } + ); + // Loading via Node arg should not work via .cjs but with .cts + + // .mts + import './mts/index.mjs'; + expectErrors( + // [() => import('./mts/index.mts'), 'Cannot find module'], + [() => import('./mts/index'), 'Cannot find module'], + [() => import('./mts/'), 'Cannot find module'], + ${ + isCommonJs + ? ` + [() => require('./mts/index'), 'Cannot find module'], + [() => require('./mts/'), 'Cannot find module'], + ` + : '' + } + ); + // Loading via Node arg should not work via .mjs but with .mts + + // Unsupported files + expectErrors( + [() => import('./file.txt'), 'Unknown file extension'], + [() => import('${wasmPath}'), 'Unknown file extension'], + ${ + isCommonJs + ? ` + [() => require('./file.txt'), 'hello is not defined'], + [() => require('${wasmPath}'), 'Invalid or unexpected token'], + ` + : '' + } + ); + + console.log(JSON.stringify({ + js, + json, + jsx, + cjs, + mjs, + })); + `, + }); + + onTestFinish(async () => await fixture.rm()); + + const p = await tsx(['import-from-ts.ts'], fixture.path); + onTestFail(() => { + console.log(p); + }); + expect(p.failed).toBe(false); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); + expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); + expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); + expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); + + // By "require()"ing an ESM file, it forces it to be compiled in a CJS context + expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); + expect(p.stderr).toBe(''); + // console.log(p); + + const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); + onTestFail(() => { + console.log(pTsconfig); + }); + expect(pTsconfig.failed).toBe(false); + expect(pTsconfig.stderr).toBe(''); + expect(pTsconfig.stdout).toBe(''); + + const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); + onTestFail(() => { + console.log(pTsconfigAllowJs); + }); + expect(pTsconfigAllowJs.failed).toBe(true); + expect(pTsconfigAllowJs.stderr).toMatch('Error: No error thrown'); + expect(pTsconfigAllowJs.stdout).toBe(''); + }); + }); + } + }); +}); diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 3ce64dffa..622289c13 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -27,8 +27,14 @@ const interact = async ( return Buffer.concat(buffers).toString(); }; -export default testSuite(async ({ describe }, fixturePath: string) => { - describe('watch', ({ test, describe }) => { +export default testSuite(async ({ describe }) => { + describe('watch', async ({ test, describe, onFinish }) => { + const fixture = await createFixture({ + // Unnecessary TS to test syntax + 'log-argv.ts': 'console.log(JSON.stringify(process.argv) as string)', + }); + onFinish(async () => await fixture.rm()); + test('require file path', async () => { const tsxProcess = await tsx({ args: ['watch'], @@ -81,7 +87,7 @@ export default testSuite(async ({ describe }, fixturePath: string) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixturePath, 'log-argv.ts'), + path.join(fixture.path, 'log-argv.ts'), ], }); @@ -109,7 +115,7 @@ export default testSuite(async ({ describe }, fixturePath: string) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixturePath, 'log-argv.ts'), + path.join(fixture.path, 'log-argv.ts'), '--some-flag', ], }); @@ -183,7 +189,7 @@ export default testSuite(async ({ describe }, fixturePath: string) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixturePath, 'log-argv.ts'), + path.join(fixture.path, 'log-argv.ts'), '--help', ], }); diff --git a/tests/utils/node-versions.ts b/tests/utils/node-versions.ts index 707b8aac3..5bb0ca58b 100644 --- a/tests/utils/node-versions.ts +++ b/tests/utils/node-versions.ts @@ -1,5 +1,5 @@ export const nodeVersions = [ - '18', + // '18', '20', ...( ( diff --git a/tests/utils/tsx.ts b/tests/utils/tsx.ts index 00152509f..57e117cba 100644 --- a/tests/utils/tsx.ts +++ b/tests/utils/tsx.ts @@ -1,5 +1,4 @@ import path from 'path'; -import fs from 'fs/promises'; import { fileURLToPath } from 'url'; import { execaNode } from 'execa'; import getNode from 'get-node'; @@ -30,10 +29,9 @@ export const tsx = ( }, ); -export async function createNode( +export const createNode = async ( nodeVersion: string, - fixturePath: string, -) { +) => { console.log('Getting node', nodeVersion); const startTime = Date.now(); const node = await getNode(nodeVersion, { @@ -43,125 +41,26 @@ export async function createNode( return { version: node.version, - packageType: '', - get isCJS() { - return this.packageType === 'commonjs'; - }, tsx( - options: Options, - ) { - return tsx({ - ...options, - nodePath: node.path, - }); - }, - load( - filePath: string, - options?: { - cwd?: string; - args?: string[]; - }, - ) { - return this.tsx( - { - args: [ - ...(options?.args ?? []), - filePath, - ], - cwd: path.join(fixturePath, options?.cwd ?? ''), - }, - ); - }, - import( - filePath: string, - options?: { - typescript?: boolean; - }, - ) { - return this.tsx({ - args: [ - `./import-file${options?.typescript ? '.ts' : '.js'}`, - filePath, - ], - cwd: fixturePath, - }); - }, - require( - filePath: string, - options?: { - typescript?: boolean; - }, - ) { - return this.tsx({ - args: [ - `./require-file${options?.typescript ? '.cts' : '.cjs'}`, - filePath, - ], - cwd: fixturePath, - }); - }, - requireFlag( - filePath: string, - ) { - return this.tsx({ - args: [ - '--eval', - 'null', - '--require', - filePath, - ], - cwd: fixturePath, - }); - }, - - loadFile( - cwd: string, - filePath: string, - options?: { - args?: string[]; - }, + args: string[], + cwd?: string, ) { - return this.tsx( + return execaNode( + tsxPath, + args, { - args: [ - ...(options?.args ?? []), - filePath, - ], cwd, + env: { + ESBK_DISABLE_CACHE: '1', + }, + nodePath: node.path, + nodeOptions: [], + reject: false, + all: true, }, ); }, - - async importFile( - cwd: string, - importFrom: string, - fileExtension = '.mjs', - ) { - const fileName = `_${Math.random().toString(36).slice(2)}${fileExtension}`; - const filePath = path.resolve(cwd, fileName); - await fs.writeFile(filePath, `import * as _ from '${importFrom}';console.log(_)`); - try { - return await this.loadFile(cwd, filePath); - } finally { - await fs.rm(filePath); - } - }, - - async requireFile( - cwd: string, - requireFrom: string, - fileExtension = '.cjs', - ) { - const fileName = `_${Math.random().toString(36).slice(2)}${fileExtension}`; - const filePath = path.resolve(cwd, fileName); - await fs.writeFile(filePath, `const _ = require('${requireFrom}');console.log(_)`); - try { - return await this.loadFile(cwd, filePath); - } finally { - await fs.rm(filePath); - } - }, }; -} +}; export type NodeApis = Awaited>; From f0376ca8d6c26c7149380843c5869d9255ee35c9 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 15:33:38 +0900 Subject: [PATCH 06/58] wip --- tests/specs/smoke.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index c8734d754..77f84b477 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -205,7 +205,8 @@ const files = { errors = errors.filter(Boolean); if (errors.length > 0) { - throw new AggregateError(errors); + console.error(errors); + process.exitCode = 1; } }; `, @@ -561,7 +562,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(pTsconfig.stdout).toBe(''); const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); - onTestFail(() => { + onTestFail((error) => { + console.log(error); console.log(pTsconfigAllowJs); }); expect(pTsconfigAllowJs.failed).toBe(true); From bd4d4f8f5540e9dc1ecde95d0e6eae39f463fd09 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:21:03 +0900 Subject: [PATCH 07/58] wip --- src/utils/transform/index.ts | 1 + tests/specs/smoke.ts | 11 +++++++---- tests/utils/node-versions.ts | 10 +++++----- tests/utils/tsx.ts | 30 ++++++++++++++---------------- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index 06a52ba21..f2af855f6 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -81,6 +81,7 @@ export async function transform( filePath: string, extendOptions?: TransformOptions, ): Promise { + console.log({ filePath }); const esbuildOptions = getEsbuildOptions({ format: 'esm', sourcefile: filePath, diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 77f84b477..46f6a567d 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -391,7 +391,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { onTestFinish(async () => await fixture.rm()); const p = await tsx(['import-from-js.js'], fixture.path); - onTestFail(() => { + onTestFail((error) => { + console.error(error); console.log(p); }); expect(p.failed).toBe(false); @@ -539,7 +540,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { onTestFinish(async () => await fixture.rm()); const p = await tsx(['import-from-ts.ts'], fixture.path); - onTestFail(() => { + onTestFail((error) => { + console.error(error); console.log(p); }); expect(p.failed).toBe(false); @@ -554,7 +556,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // console.log(p); const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); - onTestFail(() => { + onTestFail((error) => { + console.error(error); console.log(pTsconfig); }); expect(pTsconfig.failed).toBe(false); @@ -563,7 +566,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); onTestFail((error) => { - console.log(error); + console.error(error); console.log(pTsconfigAllowJs); }); expect(pTsconfigAllowJs.failed).toBe(true); diff --git a/tests/utils/node-versions.ts b/tests/utils/node-versions.ts index 5bb0ca58b..38e65a569 100644 --- a/tests/utils/node-versions.ts +++ b/tests/utils/node-versions.ts @@ -1,17 +1,17 @@ export const nodeVersions = [ // '18', - '20', + // '20', ...( ( process.env.CI && process.platform !== 'win32' ) ? [ - '12.20.0', // CJS named export detection added - '12', + // '12.20.0', // CJS named export detection added + // '12', '14', - '16', - '17', + // '16', + // '17', ] as const : [] as const ), diff --git a/tests/utils/tsx.ts b/tests/utils/tsx.ts index 57e117cba..f7639db61 100644 --- a/tests/utils/tsx.ts +++ b/tests/utils/tsx.ts @@ -41,25 +41,23 @@ export const createNode = async ( return { version: node.version, - tsx( + tsx: ( args: string[], cwd?: string, - ) { - return execaNode( - tsxPath, - args, - { - cwd, - env: { - ESBK_DISABLE_CACHE: '1', - }, - nodePath: node.path, - nodeOptions: [], - reject: false, - all: true, + ) => execaNode( + tsxPath, + args, + { + cwd, + env: { + ESBK_DISABLE_CACHE: '1', }, - ); - }, + nodePath: node.path, + nodeOptions: [], + reject: false, + all: true, + }, + ), }; }; From c018bf1d8a7e9795c4bfa7f2343951a8c3e61b05 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:35:15 +0900 Subject: [PATCH 08/58] wip --- src/utils/transform/index.ts | 1 - tests/specs/smoke.ts | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index f2af855f6..06a52ba21 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -81,7 +81,6 @@ export async function transform( filePath: string, extendOptions?: TransformOptions, ): Promise { - console.log({ filePath }); const esbuildOptions = getEsbuildOptions({ format: 'esm', sourcefile: filePath, diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 46f6a567d..b42ef6d1b 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -411,7 +411,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { ...files, 'package.json': JSON.stringify({ type: packageType }), - 'import-from-ts.ts': ` + '_import-from-ts.ts': ` import { expectErrors } from './expect-errors'; // node: prefix @@ -535,6 +535,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { mjs, })); `, + 'import-from-ts.ts': `let a = false; a ??= true; a ||= true; a &&= true;`, }); onTestFinish(async () => await fixture.rm()); From 343ea81cb5d8156ab6d2b912e0fe50228b218256 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:40:20 +0900 Subject: [PATCH 09/58] wip --- src/utils/transform/index.ts | 1 + tests/specs/smoke.ts | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index 06a52ba21..ea94c3358 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -81,6 +81,7 @@ export async function transform( filePath: string, extendOptions?: TransformOptions, ): Promise { + console.log({ filePath, code }); const esbuildOptions = getEsbuildOptions({ format: 'esm', sourcefile: filePath, diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index b42ef6d1b..46f6a567d 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -411,7 +411,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { ...files, 'package.json': JSON.stringify({ type: packageType }), - '_import-from-ts.ts': ` + 'import-from-ts.ts': ` import { expectErrors } from './expect-errors'; // node: prefix @@ -535,7 +535,6 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { mjs, })); `, - 'import-from-ts.ts': `let a = false; a ??= true; a ||= true; a &&= true;`, }); onTestFinish(async () => await fixture.rm()); From a77c204dd7fe8b73abc6d2fff918678c3e300020 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:41:06 +0900 Subject: [PATCH 10/58] wip --- tests/specs/smoke.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 46f6a567d..aa3db896b 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -302,9 +302,11 @@ const files = { }, }; +const packageTypes = ['module', 'commonjs'] as const; + export default testSuite(async ({ describe }, { tsx }: NodeApis) => { describe('Smoke', ({ describe }) => { - for (const packageType of ['module', 'commonjs']) { + for (const packageType of packageTypes) { const isCommonJs = packageType === 'commonjs'; describe(packageType, ({ test }) => { From 80d0825a75e38d4b1586a059eb43224c8820e9e7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:43:25 +0900 Subject: [PATCH 11/58] wip --- src/utils/transform/index.ts | 5 ++++- tests/specs/smoke.ts | 7 +++++-- tests/utils/tsx.ts | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index ea94c3358..c9d07c48d 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -81,7 +81,10 @@ export async function transform( filePath: string, extendOptions?: TransformOptions, ): Promise { - console.log({ filePath, code }); + if (process.env.DEBUG) { + console.log({ filePath, code }); + } + const esbuildOptions = getEsbuildOptions({ format: 'esm', sourcefile: filePath, diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index aa3db896b..5a484f262 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -302,12 +302,15 @@ const files = { }, }; -const packageTypes = ['module', 'commonjs'] as const; +const packageTypes = [ + 'module', + // 'commonjs', +] as const; export default testSuite(async ({ describe }, { tsx }: NodeApis) => { describe('Smoke', ({ describe }) => { for (const packageType of packageTypes) { - const isCommonJs = packageType === 'commonjs'; + const isCommonJs = false; //packageType === 'commonjs'; describe(packageType, ({ test }) => { test('from .js', async ({ onTestFinish, onTestFail }) => { diff --git a/tests/utils/tsx.ts b/tests/utils/tsx.ts index f7639db61..ea82587f0 100644 --- a/tests/utils/tsx.ts +++ b/tests/utils/tsx.ts @@ -20,6 +20,7 @@ export const tsx = ( { env: { ESBK_DISABLE_CACHE: '1', + DEBUG: '1', }, nodePath: options.nodePath, nodeOptions: [], @@ -51,6 +52,7 @@ export const createNode = async ( cwd, env: { ESBK_DISABLE_CACHE: '1', + DEBUG: '1', }, nodePath: node.path, nodeOptions: [], From 78c488bb5be40f02fcea8996138cd9e31bf22d17 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:45:43 +0900 Subject: [PATCH 12/58] wip --- tests/index.ts | 4 +- tests/specs/smoke.ts | 330 +++++++++++++++++++++---------------------- 2 files changed, 167 insertions(+), 167 deletions(-) diff --git a/tests/index.ts b/tests/index.ts index 9a332b53f..c8b036fe6 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -4,8 +4,8 @@ import { nodeVersions } from './utils/node-versions'; (async () => { await describe('tsx', async ({ runTestSuite, describe }) => { - runTestSuite(import('./specs/cli')); - runTestSuite(import('./specs/watch')); + // runTestSuite(import('./specs/cli')); + // runTestSuite(import('./specs/watch')); for (const nodeVersion of nodeVersions) { const node = await createNode(nodeVersion); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 5a484f262..701ace0a0 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -411,173 +411,173 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(p.stderr).toBe(''); }); - test('from .ts', async ({ onTestFinish, onTestFail }) => { - const fixture = await createFixture({ - ...files, - 'package.json': JSON.stringify({ type: packageType }), - - 'import-from-ts.ts': ` - import { expectErrors } from './expect-errors'; - - // node: prefix - import 'node:fs'; - - import 'dep'; - - // .js - import * as js from './js/index.js'; - import './js/index'; - import './js/'; - - // .json - import * as json from './json/index.json'; - import './json/index'; - import './json/'; - - // .cjs - import * as cjs from './cjs/index.cjs'; - expectErrors( - [() => import('./cjs/index'), 'Cannot find module'], - [() => import('./cjs/'), 'Cannot find module'], - ${ - isCommonJs - ? ` - [() => require('./cjs/index'), 'Cannot find module'], - [() => require('./cjs/'), 'Cannot find module'], - ` - : '' - } - ); - - // .mjs - import * as mjs from './mjs/index.mjs'; - expectErrors( - [() => import('./mjs/index'), 'Cannot find module'], - [() => import('./mjs/'), 'Cannot find module'], - ${ - isCommonJs - ? ` - [() => require('./mjs/index'), 'Cannot find module'], - [() => require('./mjs/'), 'Cannot find module'], - ` - : '' - } - ); + // test('from .ts', async ({ onTestFinish, onTestFail }) => { + // const fixture = await createFixture({ + // ...files, + // 'package.json': JSON.stringify({ type: packageType }), + + // 'import-from-ts.ts': ` + // import { expectErrors } from './expect-errors'; + + // // node: prefix + // import 'node:fs'; + + // import 'dep'; + + // // .js + // import * as js from './js/index.js'; + // import './js/index'; + // import './js/'; + + // // .json + // import * as json from './json/index.json'; + // import './json/index'; + // import './json/'; + + // // .cjs + // import * as cjs from './cjs/index.cjs'; + // expectErrors( + // [() => import('./cjs/index'), 'Cannot find module'], + // [() => import('./cjs/'), 'Cannot find module'], + // ${ + // isCommonJs + // ? ` + // [() => require('./cjs/index'), 'Cannot find module'], + // [() => require('./cjs/'), 'Cannot find module'], + // ` + // : '' + // } + // ); + + // // .mjs + // import * as mjs from './mjs/index.mjs'; + // expectErrors( + // [() => import('./mjs/index'), 'Cannot find module'], + // [() => import('./mjs/'), 'Cannot find module'], + // ${ + // isCommonJs + // ? ` + // [() => require('./mjs/index'), 'Cannot find module'], + // [() => require('./mjs/'), 'Cannot find module'], + // ` + // : '' + // } + // ); - // .ts - import './ts/index.ts'; - import './ts/index.js'; - // import './ts/index.jsx'; - import './ts/index'; - import './ts/'; + // // .ts + // import './ts/index.ts'; + // import './ts/index.js'; + // // import './ts/index.jsx'; + // import './ts/index'; + // import './ts/'; - // .jsx - import * as jsx from './jsx/index.jsx'; - // import './jsx/index.js'; - import './jsx/index'; - import './jsx/'; - - // .tsx - import './tsx/index.tsx'; - // import './tsx/index.js'; - import './tsx/index.jsx'; - import './tsx/index'; - import './tsx/'; - - // .cts - import './cts/index.cjs'; - expectErrors( - // [() => import('./cts/index.cts'), 'Cannot find module'], - [() => import('./cts/index'), 'Cannot find module'], - [() => import('./cts/'), 'Cannot find module'], - ${ - isCommonJs - ? ` - [() => require('./cts/index'), 'Cannot find module'], - [() => require('./cts/'), 'Cannot find module'], - ` - : '' - } - ); - // Loading via Node arg should not work via .cjs but with .cts - - // .mts - import './mts/index.mjs'; - expectErrors( - // [() => import('./mts/index.mts'), 'Cannot find module'], - [() => import('./mts/index'), 'Cannot find module'], - [() => import('./mts/'), 'Cannot find module'], - ${ - isCommonJs - ? ` - [() => require('./mts/index'), 'Cannot find module'], - [() => require('./mts/'), 'Cannot find module'], - ` - : '' - } - ); - // Loading via Node arg should not work via .mjs but with .mts - - // Unsupported files - expectErrors( - [() => import('./file.txt'), 'Unknown file extension'], - [() => import('${wasmPath}'), 'Unknown file extension'], - ${ - isCommonJs - ? ` - [() => require('./file.txt'), 'hello is not defined'], - [() => require('${wasmPath}'), 'Invalid or unexpected token'], - ` - : '' - } - ); - - console.log(JSON.stringify({ - js, - json, - jsx, - cjs, - mjs, - })); - `, - }); - - onTestFinish(async () => await fixture.rm()); - - const p = await tsx(['import-from-ts.ts'], fixture.path); - onTestFail((error) => { - console.error(error); - console.log(p); - }); - expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); - expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); - expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); - expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); - expect(p.stderr).toBe(''); - // console.log(p); - - const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); - onTestFail((error) => { - console.error(error); - console.log(pTsconfig); - }); - expect(pTsconfig.failed).toBe(false); - expect(pTsconfig.stderr).toBe(''); - expect(pTsconfig.stdout).toBe(''); - - const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); - onTestFail((error) => { - console.error(error); - console.log(pTsconfigAllowJs); - }); - expect(pTsconfigAllowJs.failed).toBe(true); - expect(pTsconfigAllowJs.stderr).toMatch('Error: No error thrown'); - expect(pTsconfigAllowJs.stdout).toBe(''); - }); + // // .jsx + // import * as jsx from './jsx/index.jsx'; + // // import './jsx/index.js'; + // import './jsx/index'; + // import './jsx/'; + + // // .tsx + // import './tsx/index.tsx'; + // // import './tsx/index.js'; + // import './tsx/index.jsx'; + // import './tsx/index'; + // import './tsx/'; + + // // .cts + // import './cts/index.cjs'; + // expectErrors( + // // [() => import('./cts/index.cts'), 'Cannot find module'], + // [() => import('./cts/index'), 'Cannot find module'], + // [() => import('./cts/'), 'Cannot find module'], + // ${ + // isCommonJs + // ? ` + // [() => require('./cts/index'), 'Cannot find module'], + // [() => require('./cts/'), 'Cannot find module'], + // ` + // : '' + // } + // ); + // // Loading via Node arg should not work via .cjs but with .cts + + // // .mts + // import './mts/index.mjs'; + // expectErrors( + // // [() => import('./mts/index.mts'), 'Cannot find module'], + // [() => import('./mts/index'), 'Cannot find module'], + // [() => import('./mts/'), 'Cannot find module'], + // ${ + // isCommonJs + // ? ` + // [() => require('./mts/index'), 'Cannot find module'], + // [() => require('./mts/'), 'Cannot find module'], + // ` + // : '' + // } + // ); + // // Loading via Node arg should not work via .mjs but with .mts + + // // Unsupported files + // expectErrors( + // [() => import('./file.txt'), 'Unknown file extension'], + // [() => import('${wasmPath}'), 'Unknown file extension'], + // ${ + // isCommonJs + // ? ` + // [() => require('./file.txt'), 'hello is not defined'], + // [() => require('${wasmPath}'), 'Invalid or unexpected token'], + // ` + // : '' + // } + // ); + + // console.log(JSON.stringify({ + // js, + // json, + // jsx, + // cjs, + // mjs, + // })); + // `, + // }); + + // onTestFinish(async () => await fixture.rm()); + + // const p = await tsx(['import-from-ts.ts'], fixture.path); + // onTestFail((error) => { + // console.error(error); + // console.log(p); + // }); + // expect(p.failed).toBe(false); + // expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); + // expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); + // expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); + // expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); + + // // By "require()"ing an ESM file, it forces it to be compiled in a CJS context + // expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); + // expect(p.stderr).toBe(''); + // // console.log(p); + + // const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); + // onTestFail((error) => { + // console.error(error); + // console.log(pTsconfig); + // }); + // expect(pTsconfig.failed).toBe(false); + // expect(pTsconfig.stderr).toBe(''); + // expect(pTsconfig.stdout).toBe(''); + + // const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); + // onTestFail((error) => { + // console.error(error); + // console.log(pTsconfigAllowJs); + // }); + // expect(pTsconfigAllowJs.failed).toBe(true); + // expect(pTsconfigAllowJs.stderr).toMatch('Error: No error thrown'); + // expect(pTsconfigAllowJs.stdout).toBe(''); + // }); }); } }); From 45cedfde798eca18999bb4c1308a266441836b98 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:55:22 +0900 Subject: [PATCH 13/58] wip --- src/utils/transform/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index c9d07c48d..47fa795bd 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -115,6 +115,10 @@ export async function transform( ] as const, ); + console.log({ + transformed, + }); + cache.set(hash, transformed); } From c5520455f9628114252f92d0c573b5481bb48905 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:55:34 +0900 Subject: [PATCH 14/58] wip --- src/utils/transform/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index 47fa795bd..602da5700 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -115,9 +115,11 @@ export async function transform( ] as const, ); - console.log({ - transformed, - }); + if (process.env.DEBUG) { + console.log({ + transformed, + }); + } cache.set(hash, transformed); } From 5da4098279619f55f2d326473fe9c9a48a8b2369 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 17:59:37 +0900 Subject: [PATCH 15/58] wip --- tests/specs/smoke.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 701ace0a0..2bb39aa8d 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -50,7 +50,7 @@ Object ?? true // import.meta // es2021 - Logical assignment operators -let a = false; a ??= true; a ||= true; a &&= true; +// let a = false; a ??= true; a ||= true; a &&= true; // es2022 - Class instance fields (class { x }); From 391dae424268be2de8d86c9ef7484a4abf6d5d0b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:31:40 +0900 Subject: [PATCH 16/58] wip --- src/esm/loaders.ts | 9 --------- src/utils/node-features.ts | 18 ------------------ 2 files changed, 27 deletions(-) diff --git a/src/esm/loaders.ts b/src/esm/loaders.ts index 4f105e88e..6bde3ea38 100644 --- a/src/esm/loaders.ts +++ b/src/esm/loaders.ts @@ -7,9 +7,6 @@ import type { import type { TransformOptions } from 'esbuild'; import { transform, transformDynamicImport } from '../utils/transform'; import { resolveTsPath } from '../utils/resolve-ts-path'; -import { - supportsNodePrefix, -} from '../utils/node-features'; import { applySourceMap, tsconfigPathsMatcher, @@ -164,12 +161,6 @@ export const resolve: resolve = async function ( defaultResolve, recursiveCall, ) { - // Added in v12.20.0 - // https://nodejs.org/api/esm.html#esm_node_imports - if (!supportsNodePrefix && specifier.startsWith('node:')) { - specifier = specifier.slice(5); - } - // If directory, can be index.js, index.ts, etc. if (isDirectoryPattern.test(specifier)) { return await tryDirectory(specifier, context, defaultResolve); diff --git a/src/utils/node-features.ts b/src/utils/node-features.ts index d9c23b14d..825017182 100644 --- a/src/utils/node-features.ts +++ b/src/utils/node-features.ts @@ -8,24 +8,6 @@ const compareNodeVersion = (version: Version) => ( || nodeVersion[2] - version[2] ); -export const nodeSupportsImport = ( - // v13.2.0 and higher - compareNodeVersion([13, 2, 0]) >= 0 - - // 12.20.0 ~ 13.0.0 - || ( - compareNodeVersion([12, 20, 0]) >= 0 - && compareNodeVersion([13, 0, 0]) < 0 - ) -); - -export const supportsNodePrefix = ( - compareNodeVersion([16, 0, 0]) >= 0 - || compareNodeVersion([14, 18, 0]) >= 0 -); - -export const nodeSupportsDeprecatedLoaders = compareNodeVersion([16, 12, 0]) < 0; - /** * Node.js loaders are isolated from v20 * https://github.com/nodejs/node/issues/49455#issuecomment-1703812193 From f6b2473f9b774738d2fd35b2c3388ed7a44ad772 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:42:06 +0900 Subject: [PATCH 17/58] wip --- src/utils/transform/index.ts | 1 + tests/specs/watch.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/transform/index.ts b/src/utils/transform/index.ts index 520b53a2f..06a52ba21 100644 --- a/src/utils/transform/index.ts +++ b/src/utils/transform/index.ts @@ -110,6 +110,7 @@ export async function transform( transformDynamicImport, ] as const, ); + cache.set(hash, transformed); } diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 622289c13..35868adbe 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -185,7 +185,7 @@ export default testSuite(async ({ describe }) => { expect(tsxProcess.stderr).toBe(''); }); - test('passes down --help to file', async () => { + test('passes down --help to file', async ({ onTestFail }) => { const tsxProcess = tsx({ args: [ 'watch', @@ -202,8 +202,12 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); const { all } = await tsxProcess; + onTestFail(() => { + console.log(all); + }); + expect(all).toMatch('"--help"'); - }, 5000); + }, 10_000); }); describe('ignore', ({ test }) => { From 09db06f4138fbbf36047751b18f47e7386ff783c Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:45:03 +0900 Subject: [PATCH 18/58] wip From b0a16efe73feef816863247a66262991dacd1fc0 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:45:56 +0900 Subject: [PATCH 19/58] wip --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a0f26735..5e1af12b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,6 @@ on: push: branches: [develop] pull_request: - branches: [master, develop, next] jobs: test: name: Test From 2d27fbd78f1ae6c91d17f3bcfbac664bbcd91bb2 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:52:21 +0900 Subject: [PATCH 20/58] wip --- tests/specs/smoke.ts | 12 ++++++------ tests/specs/watch.ts | 30 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index c3e0cb55b..e30b991ec 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -83,8 +83,8 @@ const sourcemap = { ...values: string[] ) => { const finalString = String.raw({ raw: strings }, ...values); - const line = finalString.split('\n').findIndex(line => line.includes('SOURCEMAP_LINE')) + 1; - return finalString.replaceAll('SOURCEMAP_LINE', line.toString()); + const lineNumber = finalString.split('\n').findIndex(line => line.includes('SOURCEMAP_LINE')) + 1; + return finalString.replaceAll('SOURCEMAP_LINE', lineNumber.toString()); }, }; @@ -304,13 +304,13 @@ const files = { const packageTypes = [ 'module', - // 'commonjs', + 'commonjs', ] as const; export default testSuite(async ({ describe }, { tsx }: NodeApis) => { describe('Smoke', ({ describe }) => { for (const packageType of packageTypes) { - const isCommonJs = false; //packageType === 'commonjs'; + const isCommonJs = packageType === 'commonjs'; describe(packageType, ({ test }) => { test('from .js', async ({ onTestFinish, onTestFail }) => { @@ -401,7 +401,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { console.log(p); }); expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); @@ -550,7 +550,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { console.log(p); }); expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},\"esmNamedExport\":123}`); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 35868adbe..7b9519e1e 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -45,7 +45,7 @@ export default testSuite(async ({ describe }) => { test('watch files for changes', async ({ onTestFinish }) => { let initialValue = Date.now(); - const fixture = await createFixture({ + const fixtureWatch = await createFixture({ 'package.json': JSON.stringify({ type: 'module', }), @@ -55,12 +55,12 @@ export default testSuite(async ({ describe }) => { `, 'value.js': `export const value = ${initialValue};`, }); - onTestFinish(async () => await fixture.rm()); + onTestFinish(async () => await fixtureWatch.rm()); const tsxProcess = tsx({ args: [ 'watch', - path.join(fixture.path, 'index.js'), + path.join(fixtureWatch.path, 'index.js'), ], }); @@ -70,7 +70,7 @@ export default testSuite(async ({ describe }) => { async (data) => { if (data.includes(`${initialValue}\n`)) { initialValue = Date.now(); - await fixture.writeFile('value.js', `export const value = ${initialValue};`); + await fixtureWatch.writeFile('value.js', `export const value = ${initialValue};`); return true; } }, @@ -132,7 +132,7 @@ export default testSuite(async ({ describe }) => { }, 10_000); test('wait for exit', async ({ onTestFinish }) => { - const fixture = await createFixture({ + const fixtureExit = await createFixture({ 'index.js': ` console.log('start'); const sleepSync = (delay) => { @@ -146,12 +146,12 @@ export default testSuite(async ({ describe }) => { `, }); - onTestFinish(async () => await fixture.rm()); + onTestFinish(async () => await fixtureExit.rm()); const tsxProcess = tsx({ args: [ 'watch', - path.join(fixture.path, 'index.js'), + path.join(fixtureExit.path, 'index.js'), ], }); @@ -217,7 +217,7 @@ export default testSuite(async ({ describe }) => { const fileB = 'directory/file-b.js'; const depA = 'node_modules/a/index.js'; - const fixture = await createFixture({ + const fixtureGlob = await createFixture({ [fileA]: 'export default "logA"', [fileB]: 'export default "logB"', [depA]: 'export default "logC"', @@ -229,15 +229,15 @@ export default testSuite(async ({ describe }) => { `.trim(), }); - onTestFinish(async () => await fixture.rm()); + onTestFinish(async () => await fixtureGlob.rm()); const tsxProcess = tsx({ - cwd: fixture.path, + cwd: fixtureGlob.path, args: [ 'watch', '--clear-screen=false', `--ignore=${fileA}`, - `--ignore=${path.join(fixture.path, 'directory/*')}`, + `--ignore=${path.join(fixtureGlob.path, 'directory/*')}`, entryFile, ], }); @@ -254,13 +254,13 @@ export default testSuite(async ({ describe }) => { if (data === 'logA logB logC\n') { // These changes should not trigger a re-run await Promise.all([ - fixture.writeFile(fileA, `export default ${negativeSignal}`), - fixture.writeFile(fileB, `export default ${negativeSignal}`), - fixture.writeFile(depA, `export default ${negativeSignal}`), + fixtureGlob.writeFile(fileA, `export default ${negativeSignal}`), + fixtureGlob.writeFile(fileB, `export default ${negativeSignal}`), + fixtureGlob.writeFile(depA, `export default ${negativeSignal}`), ]); await setTimeout(1500); - await fixture.writeFile(entryFile, 'console.log("TERMINATE")'); + await fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")'); return true; } }, From daf427484f659b7416150bafb679f42e35c6bcbc Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:54:58 +0900 Subject: [PATCH 21/58] wip --- tests/specs/watch.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 7b9519e1e..468bde337 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -60,8 +60,9 @@ export default testSuite(async ({ describe }) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixtureWatch.path, 'index.js'), + 'index.js', ], + cwd: fixtureWatch.path, }); await interact( @@ -87,8 +88,9 @@ export default testSuite(async ({ describe }) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixture.path, 'log-argv.ts'), + 'log-argv.ts', ], + cwd: fixture.path, }); await interact( @@ -115,9 +117,10 @@ export default testSuite(async ({ describe }) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixture.path, 'log-argv.ts'), + 'log-argv.ts', '--some-flag', ], + cwd: fixture.path, }); await interact( @@ -151,8 +154,9 @@ export default testSuite(async ({ describe }) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixtureExit.path, 'index.js'), + 'index.js', ], + cwd: fixtureExit.path, }); await interact( @@ -189,9 +193,10 @@ export default testSuite(async ({ describe }) => { const tsxProcess = tsx({ args: [ 'watch', - path.join(fixture.path, 'log-argv.ts'), + 'log-argv.ts', '--help', ], + cwd: fixture.path, }); await interact( From 081dcac6d5d97d9003bc106dd9873ba04eb8437a Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 31 Oct 2023 18:58:15 +0900 Subject: [PATCH 22/58] 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 5e1af12b3..a83133fa6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, windows-latest] timeout-minutes: 15 steps: From d909d54e2e4c9cd1cdd68244d606faa64f0839af Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 10:19:29 +0900 Subject: [PATCH 23/58] wip --- .github/workflows/test.yml | 2 +- tests/index.ts | 4 +-- tests/specs/smoke.ts | 74 +++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a83133fa6..13d9acd10 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] timeout-minutes: 15 steps: diff --git a/tests/index.ts b/tests/index.ts index 9a332b53f..c8b036fe6 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -4,8 +4,8 @@ import { nodeVersions } from './utils/node-versions'; (async () => { await describe('tsx', async ({ runTestSuite, describe }) => { - runTestSuite(import('./specs/cli')); - runTestSuite(import('./specs/watch')); + // runTestSuite(import('./specs/cli')); + // runTestSuite(import('./specs/watch')); for (const nodeVersion of nodeVersions) { const node = await createNode(nodeVersion); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index e30b991ec..6130894d3 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -312,7 +312,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { for (const packageType of packageTypes) { const isCommonJs = packageType === 'commonjs'; - describe(packageType, ({ test }) => { + describe(packageType, ({ test, describe }) => { test('from .js', async ({ onTestFinish, onTestFail }) => { const fixture = await createFixture({ ...files, @@ -393,6 +393,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { `, }); + console.log('from .js', packageType, fixture.path); + onTestFinish(async () => await fixture.rm()); const p = await tsx(['import-from-js.js'], fixture.path); @@ -411,7 +413,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(p.stderr).toBe(''); }); - test('from .ts', async ({ onTestFinish, onTestFail }) => { + describe('from .ts', async ({ test, onFinish }) => { const fixture = await createFixture({ ...files, 'package.json': JSON.stringify({ type: packageType }), @@ -541,42 +543,48 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { })); `, }); - - onTestFinish(async () => await fixture.rm()); - - const p = await tsx(['import-from-ts.ts'], fixture.path); - onTestFail((error) => { - console.error(error); - console.log(p); + console.log('from .ts', packageType, fixture.path); + onFinish(async () => await fixture.rm()); + + test('import all', async ({ onTestFail }) => { + const p = await tsx(['import-from-ts.ts'], fixture.path); + onTestFail((error) => { + console.error(error); + console.log(p); + }); + expect(p.failed).toBe(false); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); + expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); + expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); + expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); + + // By "require()"ing an ESM file, it forces it to be compiled in a CJS context + expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); + expect(p.stderr).toBe(''); + // console.log(p); }); - expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); - expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); - expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); - expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); - expect(p.stderr).toBe(''); - // console.log(p); - const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); - onTestFail((error) => { - console.error(error); - console.log(pTsconfig); + test('tsconfig', async ({ onTestFail }) => { + const pTsconfig = await tsx(['index.tsx'], path.join(fixture.path, 'tsconfig')); + onTestFail((error) => { + console.error(error); + console.log(pTsconfig); + }); + expect(pTsconfig.failed).toBe(false); + expect(pTsconfig.stderr).toBe(''); + expect(pTsconfig.stdout).toBe(''); }); - expect(pTsconfig.failed).toBe(false); - expect(pTsconfig.stderr).toBe(''); - expect(pTsconfig.stdout).toBe(''); - const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); - onTestFail((error) => { - console.error(error); - console.log(pTsconfigAllowJs); + test('custom tsconfig', async ({ onTestFail }) => { + const pTsconfigAllowJs = await tsx(['--tsconfig', 'tsconfig-allowJs.json', 'jsx.jsx'], path.join(fixture.path, 'tsconfig')); + onTestFail((error) => { + console.error(error); + console.log(pTsconfigAllowJs); + }); + expect(pTsconfigAllowJs.failed).toBe(true); + expect(pTsconfigAllowJs.stderr).toMatch('Error: No error thrown'); + expect(pTsconfigAllowJs.stdout).toBe(''); }); - expect(pTsconfigAllowJs.failed).toBe(true); - expect(pTsconfigAllowJs.stderr).toMatch('Error: No error thrown'); - expect(pTsconfigAllowJs.stdout).toBe(''); }); }); } From 0a8a9dd1f9687d0db07bcc5af53f7ae08b938878 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 10:57:37 +0900 Subject: [PATCH 24/58] wip --- tests/specs/smoke.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 6130894d3..e0c3ab936 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -1,6 +1,7 @@ import path from 'path'; import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; +import { pathToFileURL } from 'url'; import type { NodeApis } from '../utils/tsx'; const cjsContextCheck = 'typeof module !== \'undefined\''; @@ -23,6 +24,7 @@ try { `; const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); +const wasmPathUrl = pathToFileURL(wasmPath).toString(); const syntaxLowering = ` // es2016 - Exponentiation operator @@ -371,7 +373,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Unsupported files expectErrors( [() => import('./file.txt'), 'Unknown file extension'], - [() => import('${wasmPath}'), 'Unknown file extension'], + [() => import('${wasmPathUrl}'), 'Unknown file extension'], ${ isCommonJs ? ` @@ -523,7 +525,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Unsupported files expectErrors( [() => import('./file.txt'), 'Unknown file extension'], - [() => import('${wasmPath}'), 'Unknown file extension'], + [() => import('${wasmPathUrl}'), 'Unknown file extension'], ${ isCommonJs ? ` From b61792e6ba8198e6af1389efee6e96ff29ee0ffb Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 11:15:09 +0900 Subject: [PATCH 25/58] wip --- tests/specs/smoke.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index e0c3ab936..9cddcf5ca 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -26,6 +26,11 @@ try { const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); const wasmPathUrl = pathToFileURL(wasmPath).toString(); +console.log({ + wasmPath, + wasmPathUrl, +}); + const syntaxLowering = ` // es2016 - Exponentiation operator 10 ** 4; From faef28a93e60552444a5073b6142994e9aa94e0b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 11:22:45 +0900 Subject: [PATCH 26/58] wip --- tests/specs/smoke.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 9cddcf5ca..2be32d66b 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -378,12 +378,12 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Unsupported files expectErrors( [() => import('./file.txt'), 'Unknown file extension'], - [() => import('${wasmPathUrl}'), 'Unknown file extension'], + [() => import(${JSON.stringify(wasmPathUrl)}), 'Unknown file extension'], ${ isCommonJs ? ` [() => require('./file.txt'), 'hello is not defined'], - [() => require('${wasmPath}'), 'Invalid or unexpected token'], + [() => require(${JSON.stringify(wasmPath)}), 'Invalid or unexpected token'], ` : '' } @@ -530,12 +530,12 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Unsupported files expectErrors( [() => import('./file.txt'), 'Unknown file extension'], - [() => import('${wasmPathUrl}'), 'Unknown file extension'], + [() => import(${JSON.stringify(wasmPathUrl)}), 'Unknown file extension'], ${ isCommonJs ? ` [() => require('./file.txt'), 'hello is not defined'], - [() => require('${wasmPath}'), 'Invalid or unexpected token'], + [() => require(${JSON.stringify(wasmPath)}), 'Invalid or unexpected token'], ` : '' } From 53f13fdab7a08897e445eff4828209342883da10 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 11:27:47 +0900 Subject: [PATCH 27/58] wip --- .github/workflows/test.yml | 2 +- tests/index.ts | 4 ++-- tests/specs/smoke.ts | 9 --------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 13d9acd10..a83133fa6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [windows-latest] + os: [ubuntu-latest, windows-latest] timeout-minutes: 15 steps: diff --git a/tests/index.ts b/tests/index.ts index c8b036fe6..9a332b53f 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -4,8 +4,8 @@ import { nodeVersions } from './utils/node-versions'; (async () => { await describe('tsx', async ({ runTestSuite, describe }) => { - // runTestSuite(import('./specs/cli')); - // runTestSuite(import('./specs/watch')); + runTestSuite(import('./specs/cli')); + runTestSuite(import('./specs/watch')); for (const nodeVersion of nodeVersions) { const node = await createNode(nodeVersion); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 2be32d66b..680e71541 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -26,11 +26,6 @@ try { const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); const wasmPathUrl = pathToFileURL(wasmPath).toString(); -console.log({ - wasmPath, - wasmPathUrl, -}); - const syntaxLowering = ` // es2016 - Exponentiation operator 10 ** 4; @@ -399,9 +394,6 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Could .js import TS files? `, }); - - console.log('from .js', packageType, fixture.path); - onTestFinish(async () => await fixture.rm()); const p = await tsx(['import-from-js.js'], fixture.path); @@ -550,7 +542,6 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { })); `, }); - console.log('from .ts', packageType, fixture.path); onFinish(async () => await fixture.rm()); test('import all', async ({ onTestFail }) => { From 64d32c3b0e8fd787a240ee38df9db2883870ce8a Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 11:30:12 +0900 Subject: [PATCH 28/58] wip --- tests/specs/smoke.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 680e71541..f71149b59 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -1,7 +1,7 @@ import path from 'path'; +import { pathToFileURL } from 'url'; import { testSuite, expect } from 'manten'; import { createFixture } from 'fs-fixture'; -import { pathToFileURL } from 'url'; import type { NodeApis } from '../utils/tsx'; const cjsContextCheck = 'typeof module !== \'undefined\''; @@ -555,11 +555,11 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); - + // By "require()"ing an ESM file, it forces it to be compiled in a CJS context expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); expect(p.stderr).toBe(''); - // console.log(p); + // console.log(p); }); test('tsconfig', async ({ onTestFail }) => { @@ -570,7 +570,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { }); expect(pTsconfig.failed).toBe(false); expect(pTsconfig.stderr).toBe(''); - expect(pTsconfig.stdout).toBe(''); + expect(pTsconfig.stdout).toBe(''); }); test('custom tsconfig', async ({ onTestFail }) => { From 55652100bfd47b0baa3371b9a88ba33be0c66459 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 11:41:15 +0900 Subject: [PATCH 29/58] 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 a83133fa6..1972ad4b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - timeout-minutes: 15 + timeout-minutes: 5 steps: - name: Checkout From e87614f50e55570dcb453fec5483033384ca8107 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 13:26:23 +0900 Subject: [PATCH 30/58] wip --- tests/specs/smoke.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index f71149b59..5491cf00e 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -14,13 +14,11 @@ const React = { `; const jsxCheck = '<>
JSX
'; -const nameInError = ` -let nameInError; -try { - nameInError(); -} catch (error) { - assert(error.message.includes('nameInError'), 'Name should be in error'); -} +const preserveName = ` +assert( + (function functionName() {}).name === 'functionName', + 'Name should be preserved' +); `; const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); @@ -94,7 +92,7 @@ const files = { 'js/index.js': ` import assert from 'assert'; ${syntaxLowering} - ${nameInError} + ${preserveName} export const cjsContext = ${cjsContextCheck}; `, @@ -103,7 +101,7 @@ const files = { 'cjs/index.cjs': sourcemap.tag` const assert = require('node:assert'); assert(${cjsContextCheck}, 'Should have CJS context'); - ${nameInError} + ${preserveName} ${sourcemap.test} exports.named = 'named'; `, @@ -142,7 +140,7 @@ const files = { // For "ts as tsx" test const bar = (value: T) => fn(); - ${nameInError} + ${preserveName} ${sourcemap.test} export const cjsContext = ${cjsContextCheck}; ${tsCheck}; @@ -155,7 +153,7 @@ const files = { export const cjsContext = ${cjsContextCheck}; ${declareReact} export const jsx = ${jsxCheck}; - ${nameInError} + ${preserveName} ${sourcemap.test} `, @@ -165,7 +163,7 @@ const files = { ${tsCheck}; ${declareReact} export const jsx = ${jsxCheck}; - ${nameInError} + ${preserveName} ${sourcemap.test} `, @@ -173,7 +171,7 @@ const files = { import assert from 'assert'; export const mjsHasCjsContext = ${cjsContextCheck}; ${tsCheck}; - ${nameInError} + ${preserveName} ${sourcemap.test} `, @@ -181,7 +179,7 @@ const files = { const assert = require('assert'); assert(${cjsContextCheck}, 'Should have CJS context'); ${tsCheck}; - ${nameInError} + ${preserveName} ${sourcemap.test} `, From e43dd0195a48236dde00c1ffb15bf729071196d6 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 14:11:32 +0900 Subject: [PATCH 31/58] wip --- tests/fixtures/catch-signals.js | 18 -- tests/fixtures/import-file.js | 2 - tests/fixtures/import-file.ts | 2 - tests/fixtures/keep-alive.js | 2 - tests/fixtures/lib/cjs-ext-cjs/index.cjs | 56 ----- tests/fixtures/lib/cjs-ext-js/index.js | 59 ----- tests/fixtures/lib/esm-ext-js/index.js | 55 ----- tests/fixtures/lib/esm-ext-mjs/index.mjs | 55 ----- tests/fixtures/lib/ts-ext-cts/index.cts | 56 ----- tests/fixtures/lib/ts-ext-jsx/index.jsx | 59 ----- tests/fixtures/lib/ts-ext-mts/index.mts | 56 ----- tests/fixtures/lib/ts-ext-ts/index.ts | 56 ----- tests/fixtures/lib/ts-ext-ts/index.tsx.ts | 56 ----- tests/fixtures/lib/ts-ext-tsx/index.tsx | 60 ----- tests/fixtures/lib/wasm/index.js | 3 - tests/fixtures/log-argv.ts | 1 - .../node_modules/package-exports/index.js | 2 - .../node_modules/package-exports/package.json | 6 - .../node_modules/package-module/index.js | 2 - .../node_modules/package-module/package.json | 5 - .../node_modules/package-module/ts.ts | 2 - .../package-typescript-export/index.ts | 2 - .../package-typescript-export/package.json | 7 - tests/fixtures/require-file.cjs | 1 - tests/fixtures/require-file.cts | 1 - tests/fixtures/test-runner-file.ts | 6 - tests/fixtures/{lib/wasm => }/test.wasm | Bin .../dependency-resolve-current-directory.ts | 1 - .../dependency-should-not-resolve-baseUrl.ts | 1 - .../dependency-should-not-resolve-paths.ts | 1 - .../resolve-current-directory/lib/file.cjs | 1 - .../resolve-current-directory/lib/file.mjs | 1 - .../resolve-current-directory/lib/index.js | 1 - .../resolve-current-directory/package.json | 6 - .../should-not-resolve-baseUrl/index.cjs | 1 - .../should-not-resolve-baseUrl/index.mjs | 3 - .../node_modules/resolve-target/index.js | 1 - .../node_modules/resolve-target/package.json | 1 - .../should-not-resolve-baseUrl/package.json | 6 - .../should-not-resolve-paths/index.cjs | 1 - .../should-not-resolve-paths/index.mjs | 3 - .../node_modules/p/nested-resolve-target.js | 1 - .../node_modules/p/package.json | 1 - .../should-not-resolve-paths/package.json | 6 - tests/fixtures/tsconfig/src/base-url.ts | 3 - tests/fixtures/tsconfig/src/index.ts | 1 - .../tsconfig/src/paths-exact-match.ts | 3 - .../tsconfig/src/paths-prefix-match.ts | 3 - .../tsconfig/src/paths-suffix-match.ts | 3 - tests/fixtures/tsconfig/src/resolve-target.ts | 1 - tests/fixtures/tsconfig/src/tsx.tsx | 12 - .../src/utils/nested-resolve-target.ts | 1 - .../tsconfig-custom/tsconfig.custom-name.json | 9 - tests/fixtures/tsconfig/tsconfig.json | 13 -- tests/specs/javascript/cjs.ts | 212 ------------------ tests/specs/javascript/esm.ts | 193 ---------------- tests/specs/javascript/index.ts | 10 - tests/specs/json.ts | 78 ------- tests/specs/smoke.ts | 47 +++- 59 files changed, 40 insertions(+), 1215 deletions(-) delete mode 100644 tests/fixtures/catch-signals.js delete mode 100644 tests/fixtures/import-file.js delete mode 100644 tests/fixtures/import-file.ts delete mode 100644 tests/fixtures/keep-alive.js delete mode 100644 tests/fixtures/lib/cjs-ext-cjs/index.cjs delete mode 100644 tests/fixtures/lib/cjs-ext-js/index.js delete mode 100644 tests/fixtures/lib/esm-ext-js/index.js delete mode 100644 tests/fixtures/lib/esm-ext-mjs/index.mjs delete mode 100644 tests/fixtures/lib/ts-ext-cts/index.cts delete mode 100644 tests/fixtures/lib/ts-ext-jsx/index.jsx delete mode 100644 tests/fixtures/lib/ts-ext-mts/index.mts delete mode 100644 tests/fixtures/lib/ts-ext-ts/index.ts delete mode 100644 tests/fixtures/lib/ts-ext-ts/index.tsx.ts delete mode 100644 tests/fixtures/lib/ts-ext-tsx/index.tsx delete mode 100644 tests/fixtures/lib/wasm/index.js delete mode 100644 tests/fixtures/log-argv.ts delete mode 100644 tests/fixtures/node_modules/package-exports/index.js delete mode 100644 tests/fixtures/node_modules/package-exports/package.json delete mode 100644 tests/fixtures/node_modules/package-module/index.js delete mode 100644 tests/fixtures/node_modules/package-module/package.json delete mode 100644 tests/fixtures/node_modules/package-module/ts.ts delete mode 100644 tests/fixtures/node_modules/package-typescript-export/index.ts delete mode 100644 tests/fixtures/node_modules/package-typescript-export/package.json delete mode 100644 tests/fixtures/require-file.cjs delete mode 100644 tests/fixtures/require-file.cts delete mode 100644 tests/fixtures/test-runner-file.ts rename tests/fixtures/{lib/wasm => }/test.wasm (100%) delete mode 100644 tests/fixtures/tsconfig/dependency-resolve-current-directory.ts delete mode 100644 tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts delete mode 100644 tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts delete mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.cjs delete mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.mjs delete mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js delete mode 100644 tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.cjs delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.mjs delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.cjs delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.mjs delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json delete mode 100644 tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json delete mode 100644 tests/fixtures/tsconfig/src/base-url.ts delete mode 100644 tests/fixtures/tsconfig/src/index.ts delete mode 100644 tests/fixtures/tsconfig/src/paths-exact-match.ts delete mode 100644 tests/fixtures/tsconfig/src/paths-prefix-match.ts delete mode 100644 tests/fixtures/tsconfig/src/paths-suffix-match.ts delete mode 100644 tests/fixtures/tsconfig/src/resolve-target.ts delete mode 100644 tests/fixtures/tsconfig/src/tsx.tsx delete mode 100644 tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts delete mode 100644 tests/fixtures/tsconfig/tsconfig-custom/tsconfig.custom-name.json delete mode 100644 tests/fixtures/tsconfig/tsconfig.json delete mode 100644 tests/specs/javascript/cjs.ts delete mode 100644 tests/specs/javascript/esm.ts delete mode 100644 tests/specs/javascript/index.ts delete mode 100644 tests/specs/json.ts diff --git a/tests/fixtures/catch-signals.js b/tests/fixtures/catch-signals.js deleted file mode 100644 index e04df1006..000000000 --- a/tests/fixtures/catch-signals.js +++ /dev/null @@ -1,18 +0,0 @@ -const signals = [ - 'SIGINT', - 'SIGTERM', -]; - -for (const name of signals) { - process.on(name, () => { - console.log(name); - - setTimeout(() => { - console.log(name, 'HANDLER COMPLETED'); - process.exit(200); - }, 100); - }); -} - -setTimeout(() => {}, 1e5); -console.log('READY'); diff --git a/tests/fixtures/import-file.js b/tests/fixtures/import-file.js deleted file mode 100644 index ab57f282e..000000000 --- a/tests/fixtures/import-file.js +++ /dev/null @@ -1,2 +0,0 @@ -// Must be .js file so it can toggle between commonjs and module -import(process.argv[2]).then(m => console.log(JSON.stringify(m))); diff --git a/tests/fixtures/import-file.ts b/tests/fixtures/import-file.ts deleted file mode 100644 index ab57f282e..000000000 --- a/tests/fixtures/import-file.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Must be .js file so it can toggle between commonjs and module -import(process.argv[2]).then(m => console.log(JSON.stringify(m))); diff --git a/tests/fixtures/keep-alive.js b/tests/fixtures/keep-alive.js deleted file mode 100644 index 3948c11df..000000000 --- a/tests/fixtures/keep-alive.js +++ /dev/null @@ -1,2 +0,0 @@ -setTimeout(() => {}, 1e5); -console.log('READY'); diff --git a/tests/fixtures/lib/cjs-ext-cjs/index.cjs b/tests/fixtures/lib/cjs-ext-cjs/index.cjs deleted file mode 100644 index 80f48bdde..000000000 --- a/tests/fixtures/lib/cjs-ext-cjs/index.cjs +++ /dev/null @@ -1,56 +0,0 @@ -async function test(description, testFunction) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); - } -} - -console.log('loaded cjs-ext-cjs/index.cjs'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -// esbuild uses import.meta as a signal for ESM -// test( -// 'import.meta.url', -// () => Boolean(import.meta.url), -// ); - -test( - 'name in error', - () => { - let nameInError; - try { - nameInError(); - } catch (error) { - return error.message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack.includes(':38:'), -); - -test( - 'resolves optional node prefix', - () => Boolean(require('node:fs')), -); - -test( - 'resolves required node prefix', - () => Boolean(require('node:test')), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -module.exports = 1234; diff --git a/tests/fixtures/lib/cjs-ext-js/index.js b/tests/fixtures/lib/cjs-ext-js/index.js deleted file mode 100644 index c2b54b9c3..000000000 --- a/tests/fixtures/lib/cjs-ext-js/index.js +++ /dev/null @@ -1,59 +0,0 @@ -async function test(description, testFunction) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); - } -} - -console.log('loaded cjs-ext-js/index.js'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -// esbuild uses import.meta as a signal for ESM -// test( -// 'import.meta.url', -// () => Boolean(import.meta.url), -// ); - -test( - 'name in error', - () => { - let nameInError; - try { - nameInError(); - } catch (error) { - return error.message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack.includes(':38:'), -); - -test( - 'resolves optional node prefix', - () => Boolean(require('node:fs')), -); - -test( - 'resolves required node prefix', - () => Boolean(require('node:test')), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'module exports', - () => module.exports = 1234, -); diff --git a/tests/fixtures/lib/esm-ext-js/index.js b/tests/fixtures/lib/esm-ext-js/index.js deleted file mode 100644 index 45659781a..000000000 --- a/tests/fixtures/lib/esm-ext-js/index.js +++ /dev/null @@ -1,55 +0,0 @@ -async function test(description, testFunction) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); - } -} - -console.log('loaded esm-ext-js/index.js'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - nameInError(); - } catch (error) { - return error.message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack.includes(':37:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/esm-ext-mjs/index.mjs b/tests/fixtures/lib/esm-ext-mjs/index.mjs deleted file mode 100644 index d1c0e5aec..000000000 --- a/tests/fixtures/lib/esm-ext-mjs/index.mjs +++ /dev/null @@ -1,55 +0,0 @@ -async function test(description, testFunction) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); - } -} - -console.log('loaded esm-ext-mjs/index.mjs'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - nameInError(); - } catch (error) { - return error.message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack.includes(':37:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/ts-ext-cts/index.cts b/tests/fixtures/lib/ts-ext-cts/index.cts deleted file mode 100644 index 05d74947a..000000000 --- a/tests/fixtures/lib/ts-ext-cts/index.cts +++ /dev/null @@ -1,56 +0,0 @@ -async function test(description: string, testFunction: () => any | Promise) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${(error as any).toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-cts/index.cts'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - // @ts-expect-error - this is a test - nameInError(); - } catch (error) { - return (error as any).message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack!.includes(':38:'), -); - -test( - 'resolves optional node prefix', - () => Boolean(require('node:fs')), -); - -test( - 'resolves required node prefix', - () => Boolean(require('node:test')), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/ts-ext-jsx/index.jsx b/tests/fixtures/lib/ts-ext-jsx/index.jsx deleted file mode 100644 index fd462a717..000000000 --- a/tests/fixtures/lib/ts-ext-jsx/index.jsx +++ /dev/null @@ -1,59 +0,0 @@ -async function test(description, testFunction) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${error.toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-jsx/index.jsx'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - nameInError(); - } catch (error) { - return error.message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack.includes(':37:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -const React = { - createElement: (...args) => Array.from(args), -}; - -export default (
hello world
); diff --git a/tests/fixtures/lib/ts-ext-mts/index.mts b/tests/fixtures/lib/ts-ext-mts/index.mts deleted file mode 100644 index 9df079336..000000000 --- a/tests/fixtures/lib/ts-ext-mts/index.mts +++ /dev/null @@ -1,56 +0,0 @@ -async function test(description: string, testFunction: () => any | Promise) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${(error as any).toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-mts/index.mts'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - // @ts-expect-error - this is a test - nameInError(); - } catch (error) { - return (error as any).message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack!.includes(':38:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/ts-ext-ts/index.ts b/tests/fixtures/lib/ts-ext-ts/index.ts deleted file mode 100644 index e36c69b8b..000000000 --- a/tests/fixtures/lib/ts-ext-ts/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -async function test(description: string, testFunction: () => any | Promise) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${(error as any).toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-ts/index.ts'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - // @ts-expect-error - this is a test - nameInError(); - } catch (error) { - return (error as any).message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack!.includes(':38:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/ts-ext-ts/index.tsx.ts b/tests/fixtures/lib/ts-ext-ts/index.tsx.ts deleted file mode 100644 index 7e012596b..000000000 --- a/tests/fixtures/lib/ts-ext-ts/index.tsx.ts +++ /dev/null @@ -1,56 +0,0 @@ -async function test(description: string, testFunction: () => any | Promise) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${(error as any).toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-ts/index.tsx.ts'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - // @ts-expect-error - this is a test - nameInError(); - } catch (error) { - return (error as any).message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack!.includes(':38:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -export default 1234; diff --git a/tests/fixtures/lib/ts-ext-tsx/index.tsx b/tests/fixtures/lib/ts-ext-tsx/index.tsx deleted file mode 100644 index f1ce11bfa..000000000 --- a/tests/fixtures/lib/ts-ext-tsx/index.tsx +++ /dev/null @@ -1,60 +0,0 @@ -async function test(description: string, testFunction: () => any | Promise) { - try { - const result = await testFunction(); - if (!result) { throw result; } - console.log(`✔ ${description}`); - } catch (error) { - console.log(`✖ ${description}: ${(error as any).toString().split('\n').shift()}`); - } -} - -console.log('loaded ts-ext-tsx/index.tsx'); - -test( - 'has CJS context', - () => typeof require !== 'undefined' || typeof module !== 'undefined', -); - -test( - 'import.meta.url', - () => Boolean(import.meta.url), -); - -test( - 'name in error', - () => { - let nameInError; - try { - // @ts-expect-error - this is a test - nameInError(); - } catch (error) { - return (error as any).message.includes('nameInError'); - } - }, -); - -test( - 'sourcemaps', - () => new Error().stack!.includes(':38:'), -); - -test( - 'has dynamic import', - () => import('fs').then(Boolean), -); - -test( - 'resolves optional node prefix', - () => import('node:fs').then(Boolean), -); - -test( - 'resolves required node prefix', - () => import('node:test').then(Boolean), -); - -const React = { - createElement: (...args: any[]) => Array.from(args), -}; - -export default (
hello world
); diff --git a/tests/fixtures/lib/wasm/index.js b/tests/fixtures/lib/wasm/index.js deleted file mode 100644 index 2e6d373be..000000000 --- a/tests/fixtures/lib/wasm/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import { myValue } from './test.wasm'; - -console.log(myValue.valueOf()); diff --git a/tests/fixtures/log-argv.ts b/tests/fixtures/log-argv.ts deleted file mode 100644 index a8fd079cd..000000000 --- a/tests/fixtures/log-argv.ts +++ /dev/null @@ -1 +0,0 @@ -console.log(JSON.stringify(process.argv) as string); // Unnecessary TS syntax to test diff --git a/tests/fixtures/node_modules/package-exports/index.js b/tests/fixtures/node_modules/package-exports/index.js deleted file mode 100644 index b7a20332d..000000000 --- a/tests/fixtures/node_modules/package-exports/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export default 'default export'; -export const namedExport = 'named export'; diff --git a/tests/fixtures/node_modules/package-exports/package.json b/tests/fixtures/node_modules/package-exports/package.json deleted file mode 100644 index 02f110a9a..000000000 --- a/tests/fixtures/node_modules/package-exports/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "package-exports", - "exports": { - "./index.js": "./index.js" - } -} diff --git a/tests/fixtures/node_modules/package-module/index.js b/tests/fixtures/node_modules/package-module/index.js deleted file mode 100644 index b7a20332d..000000000 --- a/tests/fixtures/node_modules/package-module/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export default 'default export'; -export const namedExport = 'named export'; diff --git a/tests/fixtures/node_modules/package-module/package.json b/tests/fixtures/node_modules/package-module/package.json deleted file mode 100644 index 611b46a8b..000000000 --- a/tests/fixtures/node_modules/package-module/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "package-module", - "type": "module", - "main": "index.js" -} diff --git a/tests/fixtures/node_modules/package-module/ts.ts b/tests/fixtures/node_modules/package-module/ts.ts deleted file mode 100644 index 091f60949..000000000 --- a/tests/fixtures/node_modules/package-module/ts.ts +++ /dev/null @@ -1,2 +0,0 @@ -export default 'ts default export'; -export const namedExport: string = 'ts named export'; diff --git a/tests/fixtures/node_modules/package-typescript-export/index.ts b/tests/fixtures/node_modules/package-typescript-export/index.ts deleted file mode 100644 index 091f60949..000000000 --- a/tests/fixtures/node_modules/package-typescript-export/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export default 'ts default export'; -export const namedExport: string = 'ts named export'; diff --git a/tests/fixtures/node_modules/package-typescript-export/package.json b/tests/fixtures/node_modules/package-typescript-export/package.json deleted file mode 100644 index 507f6aae5..000000000 --- a/tests/fixtures/node_modules/package-typescript-export/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "package-typescript-export", - "type": "module", - "exports": { - "import": "./index.ts" - } -} diff --git a/tests/fixtures/require-file.cjs b/tests/fixtures/require-file.cjs deleted file mode 100644 index 77bb3f859..000000000 --- a/tests/fixtures/require-file.cjs +++ /dev/null @@ -1 +0,0 @@ -console.log(JSON.stringify(require(process.argv[2]))); diff --git a/tests/fixtures/require-file.cts b/tests/fixtures/require-file.cts deleted file mode 100644 index 77bb3f859..000000000 --- a/tests/fixtures/require-file.cts +++ /dev/null @@ -1 +0,0 @@ -console.log(JSON.stringify(require(process.argv[2]))); diff --git a/tests/fixtures/test-runner-file.ts b/tests/fixtures/test-runner-file.ts deleted file mode 100644 index 6e7fc8aa8..000000000 --- a/tests/fixtures/test-runner-file.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { test } from 'node:test'; -import assert from 'assert'; - -test('passing test', () => { - assert.strictEqual(1, 1); -}); diff --git a/tests/fixtures/lib/wasm/test.wasm b/tests/fixtures/test.wasm similarity index 100% rename from tests/fixtures/lib/wasm/test.wasm rename to tests/fixtures/test.wasm diff --git a/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts b/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts deleted file mode 100644 index 5295f76ed..000000000 --- a/tests/fixtures/tsconfig/dependency-resolve-current-directory.ts +++ /dev/null @@ -1 +0,0 @@ -import 'resolve-current-directory'; diff --git a/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts b/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts deleted file mode 100644 index 84f5a6724..000000000 --- a/tests/fixtures/tsconfig/dependency-should-not-resolve-baseUrl.ts +++ /dev/null @@ -1 +0,0 @@ -import 'should-not-resolve-baseUrl'; diff --git a/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts b/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts deleted file mode 100644 index c8fd4ce7a..000000000 --- a/tests/fixtures/tsconfig/dependency-should-not-resolve-paths.ts +++ /dev/null @@ -1 +0,0 @@ -import 'should-not-resolve-paths'; diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.cjs b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.cjs deleted file mode 100644 index 9ed959542..000000000 --- a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.cjs +++ /dev/null @@ -1 +0,0 @@ -require('.'); diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.mjs b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.mjs deleted file mode 100644 index 8f7bcd336..000000000 --- a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/file.mjs +++ /dev/null @@ -1 +0,0 @@ -import '.'; diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js deleted file mode 100644 index 7f2bfb16a..000000000 --- a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/lib/index.js +++ /dev/null @@ -1 +0,0 @@ -console.log('resolved'); diff --git a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json b/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json deleted file mode 100644 index aa3034061..000000000 --- a/tests/fixtures/tsconfig/node_modules/resolve-current-directory/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "exports": { - "module": "./lib/file.mjs", - "default": "./lib/file.cjs" - } -} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.cjs b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.cjs deleted file mode 100644 index 4e1262c5a..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.cjs +++ /dev/null @@ -1 +0,0 @@ -console.log(require('resolve-target')); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.mjs b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.mjs deleted file mode 100644 index 4d49952c5..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/index.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'resolve-target'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js deleted file mode 100644 index 08c72abce..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'resolved'; \ No newline at end of file diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json deleted file mode 100644 index 0967ef424..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/node_modules/resolve-target/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json deleted file mode 100644 index ba5e30e4c..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-baseUrl/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "exports": { - "module": "./index.mjs", - "default": "./index.cjs" - } -} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.cjs b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.cjs deleted file mode 100644 index 0a617e463..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.cjs +++ /dev/null @@ -1 +0,0 @@ -console.log(require('p/nested-resolve-target')); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.mjs b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.mjs deleted file mode 100644 index 1b9fc008c..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/index.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'p/nested-resolve-target'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js deleted file mode 100644 index 08c72abce..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/nested-resolve-target.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'resolved'; \ No newline at end of file diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json deleted file mode 100644 index 0967ef424..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/node_modules/p/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json b/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json deleted file mode 100644 index ba5e30e4c..000000000 --- a/tests/fixtures/tsconfig/node_modules/should-not-resolve-paths/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "exports": { - "module": "./index.mjs", - "default": "./index.cjs" - } -} diff --git a/tests/fixtures/tsconfig/src/base-url.ts b/tests/fixtures/tsconfig/src/base-url.ts deleted file mode 100644 index 4d49952c5..000000000 --- a/tests/fixtures/tsconfig/src/base-url.ts +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'resolve-target'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/src/index.ts b/tests/fixtures/tsconfig/src/index.ts deleted file mode 100644 index f9729c6b0..000000000 --- a/tests/fixtures/tsconfig/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -console.log('Should not run'); diff --git a/tests/fixtures/tsconfig/src/paths-exact-match.ts b/tests/fixtures/tsconfig/src/paths-exact-match.ts deleted file mode 100644 index 1b4b714fc..000000000 --- a/tests/fixtures/tsconfig/src/paths-exact-match.ts +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'paths-exact-match'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/src/paths-prefix-match.ts b/tests/fixtures/tsconfig/src/paths-prefix-match.ts deleted file mode 100644 index 1b9fc008c..000000000 --- a/tests/fixtures/tsconfig/src/paths-prefix-match.ts +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'p/nested-resolve-target'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/src/paths-suffix-match.ts b/tests/fixtures/tsconfig/src/paths-suffix-match.ts deleted file mode 100644 index 73cb17386..000000000 --- a/tests/fixtures/tsconfig/src/paths-suffix-match.ts +++ /dev/null @@ -1,3 +0,0 @@ -import value from 'nested-resolve-target/s'; - -console.log(value); diff --git a/tests/fixtures/tsconfig/src/resolve-target.ts b/tests/fixtures/tsconfig/src/resolve-target.ts deleted file mode 100644 index 3e8855613..000000000 --- a/tests/fixtures/tsconfig/src/resolve-target.ts +++ /dev/null @@ -1 +0,0 @@ -export default 'resolve-target'; diff --git a/tests/fixtures/tsconfig/src/tsx.tsx b/tests/fixtures/tsconfig/src/tsx.tsx deleted file mode 100644 index 9b979274c..000000000 --- a/tests/fixtures/tsconfig/src/tsx.tsx +++ /dev/null @@ -1,12 +0,0 @@ -export default [ - ( -
- hello world -
- ), - ( - <> - goodbye world - - ), -]; diff --git a/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts b/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts deleted file mode 100644 index 65a22c6cb..000000000 --- a/tests/fixtures/tsconfig/src/utils/nested-resolve-target.ts +++ /dev/null @@ -1 +0,0 @@ -export default 'nested-resolve-target'; diff --git a/tests/fixtures/tsconfig/tsconfig-custom/tsconfig.custom-name.json b/tests/fixtures/tsconfig/tsconfig-custom/tsconfig.custom-name.json deleted file mode 100644 index f8e649961..000000000 --- a/tests/fixtures/tsconfig/tsconfig-custom/tsconfig.custom-name.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "jsxFactory": "console.error" - }, - "include": [ - "../src" - ] -} diff --git a/tests/fixtures/tsconfig/tsconfig.json b/tests/fixtures/tsconfig/tsconfig.json deleted file mode 100644 index 40c2faa92..000000000 --- a/tests/fixtures/tsconfig/tsconfig.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "compilerOptions": { - "jsx": "react", - "jsxFactory": "console.log", - "jsxFragmentFactory": "null", - "baseUrl": "./src", - "paths": { - "paths-exact-match": ["resolve-target"], - "p/*": ["utils/*"], - "*/s": ["utils/*"] - }, - } -} diff --git a/tests/specs/javascript/cjs.ts b/tests/specs/javascript/cjs.ts deleted file mode 100644 index 136d4c449..000000000 --- a/tests/specs/javascript/cjs.ts +++ /dev/null @@ -1,212 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Load CJS', ({ describe }) => { - describe('.cjs extension', ({ describe }) => { - function assertResults({ stdout, stderr }: ExecaReturnValue) { - expect(stdout).toMatch('loaded cjs-ext-cjs/index.cjs'); - expect(stdout).toMatch('✔ has CJS context'); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/cjs-ext-cjs/index.cjs'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('TypeScript Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('1234'); - }); - }); - - describe('extensionless - should not work', ({ test }) => { - const importPath = './lib/cjs-ext-cjs/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/cjs-ext-cjs'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - }); - - describe('.js extension', ({ describe }) => { - function assertCjsResults({ stdout, stderr }: ExecaReturnValue) { - expect(stdout).toMatch('loaded cjs-ext-js/index.js'); - expect(stdout).toMatch('✔ has CJS context'); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - - expect(stderr).not.toMatch(/loader/i); - } - - function assertEsmResults({ stdout, stderr }: ExecaReturnValue) { - expect(stdout).toMatch('loaded cjs-ext-js/index.js'); - expect(stdout).toMatch('✖ has CJS context'); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stderr).toBe(''); - } - - describe('full path', ({ test }) => { - const importPath = './lib/cjs-ext-js/index.js'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('1234'); - }); - }); - - describe('extensionless', ({ test }) => { - const importPath = './lib/cjs-ext-js/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('1234'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/cjs-ext-js'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - - if (node.isCJS) { - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - } else { - assertEsmResults(nodeProcess); - } - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - assertCjsResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('1234'); - }); - }); - }); - }); -}); diff --git a/tests/specs/javascript/esm.ts b/tests/specs/javascript/esm.ts deleted file mode 100644 index 4fad2dee2..000000000 --- a/tests/specs/javascript/esm.ts +++ /dev/null @@ -1,193 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Load ESM', ({ describe }) => { - describe('.mjs extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - ) { - expect(stdout).toMatch('loaded esm-ext-mjs/index.mjs'); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/esm-ext-mjs/index.mjs'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('TypeScript Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('extensionless - should not work', ({ test }) => { - const importPath = './lib/esm-ext-mjs/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - - describe('directory - should not work', ({ test }) => { - const importPath = './lib/esm-ext-mjs'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - }); - - describe('.js extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - ) { - expect(stdout).toMatch('loaded esm-ext-js/index.js'); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/esm-ext-js/index.js'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('extensionless', ({ test }) => { - const importPath = './lib/esm-ext-js/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/esm-ext-js'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - }); - }); -}); diff --git a/tests/specs/javascript/index.ts b/tests/specs/javascript/index.ts deleted file mode 100644 index 36a852168..000000000 --- a/tests/specs/javascript/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { testSuite } from 'manten'; -import type { NodeApis } from '../../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('JavaScript', ({ runTestSuite }) => { - runTestSuite(import('./cjs'), node); - runTestSuite(import('./esm'), node); - runTestSuite(import('./dependencies'), node); - }); -}); diff --git a/tests/specs/json.ts b/tests/specs/json.ts deleted file mode 100644 index ccb2fe3f8..000000000 --- a/tests/specs/json.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { testSuite, expect } from 'manten'; -import { createFixture } from 'fs-fixture'; -import type { NodeApis } from '../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Load JSON', async ({ describe, onFinish }) => { - const fixture = await createFixture({ - 'package.json': JSON.stringify({ - type: node.packageType, - }), - 'index.json': JSON.stringify({ - loaded: 'json', - }), - }); - - onFinish(async () => await fixture.rm()); - - describe('full path', async ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, './index.json'); - expect(nodeProcess.stdout).toBe(''); - expect(nodeProcess.exitCode).toBe(0); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index.json'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - - test('Require', async () => { - const nodeProcess = await node.requireFile(fixture.path, './index.json'); - expect(nodeProcess.stdout).toBe('{ loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - }); - - describe('extensionless', ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, './index'); - expect(nodeProcess.stdout).toBe(''); - expect(nodeProcess.exitCode).toBe(0); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, './index'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - - test('Require', async () => { - const nodeProcess = await node.requireFile(fixture.path, './index'); - expect(nodeProcess.stdout).toBe('{ loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - }); - - describe('directory', ({ test }) => { - test('Load', async () => { - const nodeProcess = await node.loadFile(fixture.path, '.'); - expect(nodeProcess.stdout).toBe(''); - expect(nodeProcess.exitCode).toBe(0); - }); - - test('Import', async () => { - const nodeProcess = await node.importFile(fixture.path, '.'); - expect(nodeProcess.stdout).toMatch('default: { loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - - test('Require', async () => { - const nodeProcess = await node.requireFile(fixture.path, '.'); - expect(nodeProcess.stdout).toBe('{ loaded: \'json\' }'); - expect(nodeProcess.stderr).toBe(''); - }); - }); - }); -}); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 5491cf00e..a66ddcba0 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -21,7 +21,7 @@ assert( ); `; -const wasmPath = path.resolve('tests/fixtures/lib/wasm/test.wasm'); +const wasmPath = path.resolve('tests/fixtures/test.wasm'); const wasmPathUrl = pathToFileURL(wasmPath).toString(); const syntaxLowering = ` @@ -213,9 +213,25 @@ const files = { 'file.txt': 'hello', - 'node_modules/dep': { - 'package.json': '{}', - 'index.js': syntaxLowering, + node_modules: { + 'pkg-commonjs': { + 'package.json': JSON.stringify({ + type: 'commonjs', + }), + 'index.js': ` + ${syntaxLowering} + `, + }, + 'pkg-module': { + 'package.json': JSON.stringify({ + type: 'module', + exports: './index.js', + }), + 'index.js': ` + ${syntaxLowering} + export const named = 2; + `, + }, }, tsconfig: { @@ -323,7 +339,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // node: prefix import 'node:fs'; - import 'dep'; + import * as pkgCommonjs from 'pkg-commonjs'; + import * as pkgModule from 'pkg-module'; // .js import * as js from './js/index.js'; @@ -387,6 +404,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { json, cjs, mjs, + pkgCommonjs, + pkgModule, })); // Could .js import TS files? @@ -403,6 +422,12 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); + expect(p.stdout).toMatch('"pkgModule":{"esmNamedExport":123,"named":2}'); + if (isCommonJs) { + expect(p.stdout).toMatch('"pkgCommonjs":{"esmNamedExport":123}'); + } else { + expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"esmNamedExport":123}}'); + } // By "require()"ing an ESM file, it forces it to be compiled in a CJS context expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); @@ -421,7 +446,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // node: prefix import 'node:fs'; - import 'dep'; + import * as pkgCommonjs from 'pkg-commonjs'; + import * as pkgModule from 'pkg-module'; // .js import * as js from './js/index.js'; @@ -537,6 +563,8 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { jsx, cjs, mjs, + pkgCommonjs, + pkgModule, })); `, }); @@ -553,11 +581,16 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); + expect(p.stdout).toMatch('"pkgModule":{"esmNamedExport":123,"named":2}'); + if (isCommonJs) { + expect(p.stdout).toMatch('"pkgCommonjs":{"esmNamedExport":123}'); + } else { + expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"esmNamedExport":123}}'); + } // By "require()"ing an ESM file, it forces it to be compiled in a CJS context expect(p.stdout).toMatch(`"mjs":{"mjsHasCjsContext":${isCommonJs}}`); expect(p.stderr).toBe(''); - // console.log(p); }); test('tsconfig', async ({ onTestFail }) => { From 26eadf6e39834946d67d280295403795b0b14b10 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 14:18:13 +0900 Subject: [PATCH 32/58] wip --- tests/specs/smoke.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index a66ddcba0..1412f3e22 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -73,7 +73,8 @@ Object ?? true // es2022 - Class static blocks (class { static {} }); -export const esmNamedExport = 123; +export const named = 2; +export default 1; `; const sourcemap = { @@ -218,19 +219,14 @@ const files = { 'package.json': JSON.stringify({ type: 'commonjs', }), - 'index.js': ` - ${syntaxLowering} - `, + 'index.js': syntaxLowering, }, 'pkg-module': { 'package.json': JSON.stringify({ type: 'module', exports: './index.js', }), - 'index.js': ` - ${syntaxLowering} - export const named = 2; - `, + 'index.js': syntaxLowering, }, }, @@ -419,14 +415,14 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { console.log(p); }); expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"default":1,"named":2}`); expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); - expect(p.stdout).toMatch('"pkgModule":{"esmNamedExport":123,"named":2}'); + expect(p.stdout).toMatch('"pkgModule":{"default":1,"named":2}'); if (isCommonJs) { - expect(p.stdout).toMatch('"pkgCommonjs":{"esmNamedExport":123}'); + expect(p.stdout).toMatch('"pkgCommonjs":{"default":1,"named":2}'); } else { - expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"esmNamedExport":123}}'); + expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"default":1,"named":2}}'); } // By "require()"ing an ESM file, it forces it to be compiled in a CJS context @@ -577,15 +573,15 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { console.log(p); }); expect(p.failed).toBe(false); - expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"esmNamedExport":123}`); + expect(p.stdout).toMatch(`"js":{"cjsContext":${isCommonJs},"default":1,"named":2}`); expect(p.stdout).toMatch('"json":{"default":{"loaded":"json"},"loaded":"json"}'); expect(p.stdout).toMatch('"cjs":{"default":{"named":"named"},"named":"named"}'); expect(p.stdout).toMatch(`"jsx":{"cjsContext":${isCommonJs},"jsx":[null,null,["div",null,"JSX"]]}`); - expect(p.stdout).toMatch('"pkgModule":{"esmNamedExport":123,"named":2}'); + expect(p.stdout).toMatch('"pkgModule":{"default":1,"named":2}'); if (isCommonJs) { - expect(p.stdout).toMatch('"pkgCommonjs":{"esmNamedExport":123}'); + expect(p.stdout).toMatch('"pkgCommonjs":{"default":1,"named":2}'); } else { - expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"esmNamedExport":123}}'); + expect(p.stdout).toMatch('"pkgCommonjs":{"default":{"default":1,"named":2}}'); } // By "require()"ing an ESM file, it forces it to be compiled in a CJS context From f6f99e1ad9846da87cd1ab099bda3dc6e0da87a2 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 18:15:19 +0900 Subject: [PATCH 33/58] wip --- tests/specs/javascript/dependencies.ts | 16 --- tests/specs/typescript/cts.ts | 104 ----------------- tests/specs/typescript/index.ts | 14 --- tests/specs/typescript/jsx.ts | 100 ---------------- tests/specs/typescript/mts.ts | 115 ------------------- tests/specs/typescript/ts.ts | 152 ------------------------- tests/specs/typescript/tsconfig.ts | 75 ------------ tests/specs/typescript/tsx.ts | 100 ---------------- tests/specs/watch.ts | 7 +- 9 files changed, 6 insertions(+), 677 deletions(-) delete mode 100644 tests/specs/javascript/dependencies.ts delete mode 100644 tests/specs/typescript/cts.ts delete mode 100644 tests/specs/typescript/index.ts delete mode 100644 tests/specs/typescript/jsx.ts delete mode 100644 tests/specs/typescript/mts.ts delete mode 100644 tests/specs/typescript/ts.ts delete mode 100644 tests/specs/typescript/tsconfig.ts delete mode 100644 tests/specs/typescript/tsx.ts diff --git a/tests/specs/javascript/dependencies.ts b/tests/specs/javascript/dependencies.ts deleted file mode 100644 index 1fc0e2d7e..000000000 --- a/tests/specs/javascript/dependencies.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { testSuite, expect } from 'manten'; -import type { NodeApis } from '../../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Dependencies', ({ describe }) => { - describe('module dependency', ({ test }) => { - const output = '{"default":"default export","namedExport":"named export"}'; - - test('Import', async () => { - const nodeProcess = await node.import('package-module'); - expect(nodeProcess.stdout).toBe(output); - expect(nodeProcess.stderr).toBe(''); - }); - }); - }); -}); diff --git a/tests/specs/typescript/cts.ts b/tests/specs/typescript/cts.ts deleted file mode 100644 index e68dc3ad2..000000000 --- a/tests/specs/typescript/cts.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('.cts extension', ({ describe }) => { - function assertResults({ stdout, stderr }: ExecaReturnValue) { - expect(stdout).toMatch('loaded ts-ext-cts/index.cts'); - expect(stdout).toMatch('✔ has CJS context'); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-cts/index.cts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('full path via .cjs', ({ test }) => { - const importPath = './lib/ts-ext-cts/index.cjs'; - - test('Load - should not work', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath, { typescript: true }); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('extensionless - should not work', ({ test }) => { - const importPath = './lib/ts-ext-cts/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - - describe('directory - should not work', ({ test }) => { - const importPath = './lib/ts-ext-cts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - }); -}); diff --git a/tests/specs/typescript/index.ts b/tests/specs/typescript/index.ts deleted file mode 100644 index 2b947c276..000000000 --- a/tests/specs/typescript/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { testSuite } from 'manten'; -import type { NodeApis } from '../../utils/tsx'; - -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('./cts'), node); - runTestSuite(import('./tsconfig'), node); - runTestSuite(import('./dependencies'), node); - }); -}); diff --git a/tests/specs/typescript/jsx.ts b/tests/specs/typescript/jsx.ts deleted file mode 100644 index 58215b009..000000000 --- a/tests/specs/typescript/jsx.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('.jsx extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - ) { - expect(stdout).toMatch('loaded ts-ext-jsx/index.jsx'); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-jsx/index.jsx'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - - describe('extensionless', ({ test }) => { - const importPath = './lib/ts-ext-jsx/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/ts-ext-jsx'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - }); -}); diff --git a/tests/specs/typescript/mts.ts b/tests/specs/typescript/mts.ts deleted file mode 100644 index 6d1ad432e..000000000 --- a/tests/specs/typescript/mts.ts +++ /dev/null @@ -1,115 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('.mts extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - ) { - expect(stdout).toMatch('loaded ts-ext-mts/index.mts'); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-mts/index.mts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('full path via .mjs', ({ test }) => { - const importPath = './lib/ts-ext-mts/index.mjs'; - - test('Load - should not work', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath, { typescript: true }); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - - describe('extensionless - should not work', ({ test }) => { - const importPath = './lib/ts-ext-mts/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - - describe('directory - should not work', ({ test }) => { - const importPath = './lib/ts-ext-mts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - }); - }); -}); diff --git a/tests/specs/typescript/ts.ts b/tests/specs/typescript/ts.ts deleted file mode 100644 index d9cbd37a5..000000000 --- a/tests/specs/typescript/ts.ts +++ /dev/null @@ -1,152 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('.ts extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - loadedMessage = 'loaded ts-ext-ts/index.ts', - ) { - expect(stdout).toMatch(loadedMessage); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-ts/index.ts'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require flag', async () => { - const nodeProcess = await node.requireFlag(importPath); - assertResults(nodeProcess, true); - }); - }); - - describe('full path via .js', ({ test }) => { - const importPath = './lib/ts-ext-ts/index.js'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - expect(nodeProcess.stderr).toMatch('Cannot find module'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath, { typescript: true }); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath, { typescript: true }); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - 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, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - 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, node.isCJS, 'loaded ts-ext-ts/index.tsx.ts'); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS, 'loaded ts-ext-ts/index.tsx.ts'); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true, 'loaded 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, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":1234}'); - }); - }); - }); -}); diff --git a/tests/specs/typescript/tsconfig.ts b/tests/specs/typescript/tsconfig.ts deleted file mode 100644 index 9b9d70835..000000000 --- a/tests/specs/typescript/tsconfig.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { testSuite, expect } from 'manten'; -import type { NodeApis } from '../../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('tsconfig', ({ test, describe }) => { - test('jsxFactory & jsxFragmentFactory', async () => { - const nodeProcess = await node.load('./src/tsx.tsx', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('div null hello world\nnull null goodbye world'); - }); - - test('Custom tsconfig.json path', async () => { - const nodeProcess = await node.load('./src/tsx.tsx', { - cwd: './tsconfig', - args: ['--tsconfig', './tsconfig-custom/tsconfig.custom-name.json'], - }); - expect(nodeProcess.stdout).toBe(''); - expect(nodeProcess.stderr).toBe('div null hello world\nnull null goodbye world'); - }); - - describe('paths', ({ test, describe }) => { - test('resolves baseUrl', async () => { - const nodeProcess = await node.load('./src/base-url.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolve-target'); - }); - - test('resolves paths exact match', async () => { - const nodeProcess = await node.load('./src/paths-exact-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolve-target'); - }); - - test('resolves paths prefix', async () => { - const nodeProcess = await node.load('./src/paths-prefix-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('nested-resolve-target'); - }); - - test('resolves paths suffix', async () => { - const nodeProcess = await node.load('./src/paths-suffix-match.ts', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('nested-resolve-target'); - }); - - describe('dependency', ({ test }) => { - test('resolve current directory', async () => { - const nodeProcess = await node.load('./dependency-resolve-current-directory', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); - - test('should not resolve baseUrl', async () => { - const nodeProcess = await node.load('./dependency-should-not-resolve-baseUrl', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); - - test('should not resolve paths', async () => { - const nodeProcess = await node.load('./dependency-should-not-resolve-paths', { - cwd: './tsconfig', - }); - expect(nodeProcess.stdout).toBe('resolved'); - }); - }); - }); - }); -}); diff --git a/tests/specs/typescript/tsx.ts b/tests/specs/typescript/tsx.ts deleted file mode 100644 index 2f7a847c7..000000000 --- a/tests/specs/typescript/tsx.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { testSuite, expect } from 'manten'; -import semver from 'semver'; -import type { ExecaReturnValue } from 'execa'; -import type { NodeApis } from '../../utils/tsx'; -import nodeSupports from '../../utils/node-supports'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('.tsx extension', ({ describe }) => { - function assertResults( - { stdout, stderr }: ExecaReturnValue, - cjsContext = false, - ) { - expect(stdout).toMatch('loaded ts-ext-tsx/index.tsx'); - expect(stdout).toMatch( - cjsContext - ? '✔ has CJS context' - : '✖ has CJS context', - ); - expect(stdout).toMatch('✔ name in error'); - expect(stdout).toMatch('✔ sourcemaps'); - expect(stdout).toMatch('✔ has dynamic import'); - expect(stdout).toMatch('✔ resolves optional node prefix'); - expect(stdout).toMatch( - semver.satisfies(node.version, nodeSupports.testRunner) - ? '✔ resolves required node prefix' - : '✖ resolves required node prefix: Error', - ); - expect(stderr).not.toMatch(/loader/i); - } - - describe('full path', ({ test }) => { - const importPath = './lib/ts-ext-tsx/index.tsx'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - - describe('extensionless', ({ test }) => { - const importPath = './lib/ts-ext-tsx/index'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - - describe('directory', ({ test }) => { - const importPath = './lib/ts-ext-tsx'; - - test('Load', async () => { - const nodeProcess = await node.load(importPath); - assertResults(nodeProcess, node.isCJS); - }); - - test('Import', async () => { - const nodeProcess = await node.import(importPath); - assertResults(nodeProcess, node.isCJS); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - - test('Require', async () => { - const nodeProcess = await node.require(importPath); - - // By "require()"ing an ESM file, it forces it to be compiled in a CJS context - assertResults(nodeProcess, true); - expect(nodeProcess.stdout).toMatch('{"default":["div",null,"hello world"]}'); - }); - }); - }); -}); diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 468bde337..4cc4accfe 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -216,7 +216,7 @@ export default testSuite(async ({ describe }) => { }); describe('ignore', ({ test }) => { - test('file path & glob', async ({ onTestFinish }) => { + test('file path & glob', async ({ onTestFinish, onTestFail }) => { const entryFile = 'index.js'; const fileA = 'file-a.js'; const fileB = 'directory/file-b.js'; @@ -276,6 +276,11 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); const { all, stderr } = await tsxProcess; + onTestFail(() => { + console.log({ + all, + }); + }); expect(all).not.toMatch('fail'); expect(stderr).toBe(''); }, 10_000); From 17b2dd943717e515b7c69212a70d1bd38cf99a53 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 18:16:34 +0900 Subject: [PATCH 34/58] wip --- tests/specs/watch.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 4cc4accfe..d2db9d9b9 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -246,6 +246,11 @@ export default testSuite(async ({ describe }) => { entryFile, ], }); + onTestFail((error) => { + console.error(tsxProcess); + console.error(error); + }); + const negativeSignal = '"fail"'; await interact( From 8aff09723127c501ff26b0d341819e215a59ddd7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 20:47:33 +0900 Subject: [PATCH 35/58] wip --- package.json | 2 +- pnpm-lock.yaml | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index dae629516..bd3a0ab83 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "kolorist": "^1.8.0", "lint-staged": "^14.0.1", "magic-string": "^0.30.3", - "manten": "^1.1.0", + "manten": "github:privatenumber/manten#npm/error-hooks", "node-pty": "^1.0.0", "outdent": "^0.8.0", "pkgroll": "^1.11.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d2bd97f6b..9ed3d1d11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,8 +82,8 @@ devDependencies: specifier: ^0.30.3 version: 0.30.3 manten: - specifier: ^1.1.0 - version: 1.1.0 + specifier: github:privatenumber/manten#npm/error-hooks + version: github.com/privatenumber/manten/7dcc3250ab600f4b7b2c930e242957e71b30243f node-pty: specifier: ^1.0.0 version: 1.0.0 @@ -2931,12 +2931,6 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: true - /manten@1.1.0: - resolution: {integrity: sha512-DyEpskY9RzqXWO3IZqH8SKxsYHdKyN+k+cLtLoTTg82/DGKbKZuHs6nBV17xchnBVFxibAWGhNSXo7h1EHO0jw==} - dependencies: - expect: 29.7.0 - dev: true - /map-age-cleaner@0.1.3: resolution: {integrity: sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==} engines: {node: '>=6'} @@ -4229,3 +4223,11 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true + + github.com/privatenumber/manten/7dcc3250ab600f4b7b2c930e242957e71b30243f: + resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/7dcc3250ab600f4b7b2c930e242957e71b30243f} + name: manten + version: 0.0.0-semantic-release + dependencies: + expect: 29.7.0 + dev: true From 9c14f0d89cda72eb87878befb53c499e3ab740b4 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 21:05:29 +0900 Subject: [PATCH 36/58] wip --- tests/specs/watch.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index d2db9d9b9..aa99cd7cd 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -246,9 +246,11 @@ export default testSuite(async ({ describe }) => { entryFile, ], }); - onTestFail((error) => { - console.error(tsxProcess); + onTestFail(async (error) => { console.error(error); + tsxProcess.kill(); + const result = await tsxProcess; + console.error(result); }); const negativeSignal = '"fail"'; From c8e390e14293a3782e6ecc7cbc81f64768685561 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 21:42:07 +0900 Subject: [PATCH 37/58] wip --- tests/specs/watch.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index aa99cd7cd..559c3de1f 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -149,8 +149,6 @@ export default testSuite(async ({ describe }) => { `, }); - onTestFinish(async () => await fixtureExit.rm()); - const tsxProcess = tsx({ args: [ 'watch', @@ -159,6 +157,11 @@ export default testSuite(async ({ describe }) => { cwd: fixtureExit.path, }); + onTestFinish(async () => { + tsxProcess.kill('SIGKILL'); + await fixtureExit.rm(); + }); + await interact( tsxProcess.stdout!, [ From 87030fcba267faaedeecc766b993065cfcc71f79 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 21:42:33 +0900 Subject: [PATCH 38/58] wip --- tests/specs/watch.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 559c3de1f..d0d5cea9f 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -158,6 +158,7 @@ export default testSuite(async ({ describe }) => { }); onTestFinish(async () => { + console.log(1, tsxProcess); tsxProcess.kill('SIGKILL'); await fixtureExit.rm(); }); From 573b30ea5c75fe1d1bb419ce10b45d6f15ff9304 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 1 Nov 2023 21:45:30 +0900 Subject: [PATCH 39/58] wip --- tests/specs/watch.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index d0d5cea9f..df5a70bc7 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -158,8 +158,12 @@ export default testSuite(async ({ describe }) => { }); onTestFinish(async () => { - console.log(1, tsxProcess); - tsxProcess.kill('SIGKILL'); + if (tsxProcess.exitCode === null) { + tsxProcess.kill('SIGKILL'); + const result = await tsxProcess; + console.log(result); + } + await fixtureExit.rm(); }); From 61449655445111d31f8a01a8aafa7113dd1405ad Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 2 Nov 2023 11:29:13 +0900 Subject: [PATCH 40/58] wip --- tests/specs/watch.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index df5a70bc7..b3bdf9dd3 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -254,11 +254,12 @@ export default testSuite(async ({ describe }) => { entryFile, ], }); - onTestFail(async (error) => { - console.error(error); - tsxProcess.kill(); - const result = await tsxProcess; - console.error(result); + onTestFail(async () => { + if (tsxProcess.exitCode === null) { + tsxProcess.kill(); + const result = await tsxProcess; + console.error(result); + } }); const negativeSignal = '"fail"'; From 449915d9d98748075c30e8e39c59afdf998ad308 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 3 Nov 2023 23:01:52 +0900 Subject: [PATCH 41/58] engines --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index dae629516..7521db615 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,9 @@ "lint-staged": { "*.{js,ts,mjs,mts,cjs,cts,json}": "pnpm lint" }, + "engines": { + "node": ">=18.0.0" + }, "dependencies": { "esbuild": "~0.18.20", "get-tsconfig": "^4.7.2", From 6a162ae5baf9afd774d2f7c6dc09f5e5864c814f Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 18:37:08 +0900 Subject: [PATCH 42/58] wip --- tests/specs/smoke.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index 1412f3e22..cb0678bd4 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -340,6 +340,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // .js import * as js from './js/index.js'; + // import * as js from './js/index.js?query=123'; Support query import './js/index'; import './js/'; @@ -447,6 +448,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // .js import * as js from './js/index.js'; + // import * as js from './js/index.js?query=123'; Support query import './js/index'; import './js/'; From bc05b0f0c587c1cf951c4f50df3251439b230712 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 19:03:58 +0900 Subject: [PATCH 43/58] wip --- tests/specs/wasm.ts | 34 ---------------------------------- tests/specs/watch.ts | 14 ++++++-------- 2 files changed, 6 insertions(+), 42 deletions(-) delete mode 100644 tests/specs/wasm.ts diff --git a/tests/specs/wasm.ts b/tests/specs/wasm.ts deleted file mode 100644 index 823e07211..000000000 --- a/tests/specs/wasm.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { testSuite, expect } from 'manten'; -import type { NodeApis } from '../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Load WASM', ({ test }) => { - const importPath = './lib/wasm/index.js'; - - test('Unsupported extension error', async () => { - const nodeProcess = await node.load(importPath); - - expect(nodeProcess.exitCode).toBe(1); - - if (node.isCJS) { - expect(nodeProcess.stderr).toMatch('Invalid or unexpected token'); - } else { - expect(nodeProcess.stderr).toMatch('ERR_UNKNOWN_FILE_EXTENSION'); - } - }); - - test('Loads with experimental flag', async () => { - const nodeProcess = await node.load(importPath, { - args: ['--experimental-wasm-modules'], - }); - - if (node.isCJS) { - expect(nodeProcess.exitCode).toBe(1); - expect(nodeProcess.stderr).toMatch('Invalid or unexpected token'); - } else { - expect(nodeProcess.exitCode).toBe(0); - expect(nodeProcess.stdout).toBe('1234'); - } - }); - }); -}); diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index b3bdf9dd3..ab89e3bcf 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -254,11 +254,11 @@ export default testSuite(async ({ describe }) => { entryFile, ], }); + onTestFail(async () => { + // If timed out, force kill process if (tsxProcess.exitCode === null) { tsxProcess.kill(); - const result = await tsxProcess; - console.error(result); } }); @@ -291,14 +291,12 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); - const { all, stderr } = await tsxProcess; + const p = await tsxProcess; onTestFail(() => { - console.log({ - all, - }); + console.log(p); }); - expect(all).not.toMatch('fail'); - expect(stderr).toBe(''); + expect(p.all).not.toMatch('fail'); + expect(p.stderr).toBe(''); }, 10_000); }); }); From 72e8e32d6e947e5a15cc9816d6cbc69ed62c5caa Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 19:09:45 +0900 Subject: [PATCH 44/58] wip --- tests/specs/watch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index ab89e3bcf..687a074af 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -255,7 +255,7 @@ export default testSuite(async ({ describe }) => { ], }); - onTestFail(async () => { + onTestFail(() => { // If timed out, force kill process if (tsxProcess.exitCode === null) { tsxProcess.kill(); From 1182ff2c34ddfd9f336e812ad2be931f8e62dcbb Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 20:46:33 +0900 Subject: [PATCH 45/58] wip --- tests/index.ts | 1 + tests/specs/repl.ts | 14 ++++----- tests/specs/smoke.ts | 7 ++++- tests/specs/typescript/dependencies.ts | 39 -------------------------- 4 files changed, 14 insertions(+), 47 deletions(-) delete mode 100644 tests/specs/typescript/dependencies.ts diff --git a/tests/index.ts b/tests/index.ts index 9a332b53f..57acf132d 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -6,6 +6,7 @@ import { nodeVersions } from './utils/node-versions'; await describe('tsx', async ({ runTestSuite, describe }) => { runTestSuite(import('./specs/cli')); runTestSuite(import('./specs/watch')); + runTestSuite(import('./specs/repl')); for (const nodeVersion of nodeVersions) { const node = await createNode(nodeVersion); diff --git a/tests/specs/repl.ts b/tests/specs/repl.ts index 838e661e8..9f13cd188 100644 --- a/tests/specs/repl.ts +++ b/tests/specs/repl.ts @@ -1,10 +1,10 @@ import { testSuite } from 'manten'; -import { type NodeApis } from '../utils/tsx'; +import { tsx } from '../utils/tsx'; -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('repl', ({ test }) => { +export default testSuite(async ({ describe }) => { + describe('REPL', ({ test }) => { test('handles ts', async () => { - const tsxProcess = node.tsx({ + const tsxProcess = tsx({ args: ['--interactive'], }); @@ -32,7 +32,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }, 40_000); test('doesn\'t error on require', async () => { - const tsxProcess = node.tsx({ + const tsxProcess = tsx({ args: ['--interactive'], }); @@ -58,7 +58,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }, 40_000); test('supports incomplete expression in segments', async () => { - const tsxProcess = node.tsx({ + const tsxProcess = tsx({ args: ['--interactive'], }); @@ -87,7 +87,7 @@ export default testSuite(async ({ describe }, node: NodeApis) => { }, 40_000); test('errors on import statement', async () => { - const tsxProcess = node.tsx({ + const tsxProcess = tsx({ args: ['--interactive'], }); diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index cb0678bd4..a0104c0a9 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -443,12 +443,15 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // node: prefix import 'node:fs'; + // Dependencies import * as pkgCommonjs from 'pkg-commonjs'; import * as pkgModule from 'pkg-module'; + // TODO: Test resolving TS files in dependencies (e.g. implicit extensions & export maps) + // .js import * as js from './js/index.js'; - // import * as js from './js/index.js?query=123'; Support query + // import * as js from './js/index.js?query=123'; TODO: Support query import './js/index'; import './js/'; @@ -510,6 +513,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // .cts import './cts/index.cjs'; expectErrors( + // TODO: // [() => import('./cts/index.cts'), 'Cannot find module'], [() => import('./cts/index'), 'Cannot find module'], [() => import('./cts/'), 'Cannot find module'], @@ -527,6 +531,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // .mts import './mts/index.mjs'; expectErrors( + // TODO: // [() => import('./mts/index.mts'), 'Cannot find module'], [() => import('./mts/index'), 'Cannot find module'], [() => import('./mts/'), 'Cannot find module'], diff --git a/tests/specs/typescript/dependencies.ts b/tests/specs/typescript/dependencies.ts deleted file mode 100644 index 987eea347..000000000 --- a/tests/specs/typescript/dependencies.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { testSuite, expect } from 'manten'; -import type { NodeApis } from '../../utils/tsx'; - -export default testSuite(async ({ describe }, node: NodeApis) => { - describe('Dependencies', ({ describe }) => { - describe('TypeScript dependency', ({ test }) => { - const output = '{"default":"ts default export","namedExport":"ts named export"}'; - - test('Import', async () => { - const nodeProcess = await node.import('package-module/ts.ts'); - expect(nodeProcess.stdout).toBe(output); - expect(nodeProcess.stderr).toBe(''); - }); - - test('Import extensionless', async () => { - const nodeProcess = await node.import('package-module/ts'); - expect(nodeProcess.stdout).toBe(output); - expect(nodeProcess.stderr).toBe(''); - }); - - test('Import', async () => { - const nodeProcess = await node.import('package-typescript-export'); - expect(nodeProcess.stdout).toBe(output); - expect(nodeProcess.stderr).toBe(''); - }); - }); - - describe('Export map', ({ test }) => { - const output = '{"default":"default export","namedExport":"named export"}'; - - test('Import', async () => { - const nodeProcess = await node.import('package-exports/index.js', { - typescript: true, - }); - expect(nodeProcess.stdout).toBe(output); - }); - }); - }); -}); From 07097fdd793482514a6b0ae2eec413bf23dd7c0e Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 22:18:30 +0900 Subject: [PATCH 46/58] wip --- pnpm-lock.yaml | 6 +++--- tests/specs/watch.ts | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9ed3d1d11..35b1b8103 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -83,7 +83,7 @@ devDependencies: version: 0.30.3 manten: specifier: github:privatenumber/manten#npm/error-hooks - version: github.com/privatenumber/manten/7dcc3250ab600f4b7b2c930e242957e71b30243f + version: github.com/privatenumber/manten/83dc0dd465e479a09bb44c049af99d81b3b1d558 node-pty: specifier: ^1.0.0 version: 1.0.0 @@ -4224,8 +4224,8 @@ packages: engines: {node: '>=12.20'} dev: true - github.com/privatenumber/manten/7dcc3250ab600f4b7b2c930e242957e71b30243f: - resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/7dcc3250ab600f4b7b2c930e242957e71b30243f} + github.com/privatenumber/manten/83dc0dd465e479a09bb44c049af99d81b3b1d558: + resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/83dc0dd465e479a09bb44c049af99d81b3b1d558} name: manten version: 0.0.0-semantic-release dependencies: diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 687a074af..f0db3aed6 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -24,7 +24,7 @@ const interact = async ( } } - return Buffer.concat(buffers).toString(); + return buffers.map(buffer => buffer.toString()); }; export default testSuite(async ({ describe }) => { @@ -134,7 +134,7 @@ export default testSuite(async ({ describe }) => { expect(all).toMatch('"--some-flag"'); }, 10_000); - test('wait for exit', async ({ onTestFinish }) => { + test('wait for exit', async ({ onTestFinish, onTestFail }) => { const fixtureExit = await createFixture({ 'index.js': ` console.log('start'); @@ -157,17 +157,25 @@ export default testSuite(async ({ describe }) => { cwd: fixtureExit.path, }); + let chunks: string[]; + + onTestFail(() => { + console.log({ + tsxProcess, + chunks, + }); + }); + onTestFinish(async () => { if (tsxProcess.exitCode === null) { tsxProcess.kill('SIGKILL'); - const result = await tsxProcess; - console.log(result); + throw new Error('Child process running'); } await fixtureExit.rm(); }); - await interact( + chunks = await interact( tsxProcess.stdout!, [ (data) => { From ae4e5f5aca59081c994d1db5c66e2b72cde6beba Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 22:22:25 +0900 Subject: [PATCH 47/58] wip --- tests/specs/watch.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index f0db3aed6..29f839438 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -159,19 +159,18 @@ export default testSuite(async ({ describe }) => { let chunks: string[]; - onTestFail(() => { - console.log({ - tsxProcess, - chunks, - }); - }); - - onTestFinish(async () => { + onTestFail(async () => { if (tsxProcess.exitCode === null) { + console.log('Force killing hanging process\n\n'); tsxProcess.kill('SIGKILL'); - throw new Error('Child process running'); + console.log({ + tsxProcess: await tsxProcess, + chunks, + }); } + }); + onTestFinish(async () => { await fixtureExit.rm(); }); @@ -263,10 +262,12 @@ export default testSuite(async ({ describe }) => { ], }); - onTestFail(() => { + onTestFail(async () => { // If timed out, force kill process if (tsxProcess.exitCode === null) { + console.log('Force killing hanging process\n\n'); tsxProcess.kill(); + console.log(await tsxProcess); } }); @@ -300,9 +301,6 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); const p = await tsxProcess; - onTestFail(() => { - console.log(p); - }); expect(p.all).not.toMatch('fail'); expect(p.stderr).toBe(''); }, 10_000); From 21d05920da245ae92ca227586fd971acfc67933a Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 22:34:02 +0900 Subject: [PATCH 48/58] wip --- tests/specs/watch.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 29f839438..931a3d93a 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -23,8 +23,6 @@ const interact = async ( } } } - - return buffers.map(buffer => buffer.toString()); }; export default testSuite(async ({ describe }) => { @@ -157,8 +155,7 @@ export default testSuite(async ({ describe }) => { cwd: fixtureExit.path, }); - let chunks: string[]; - + const chunks: string[] = []; onTestFail(async () => { if (tsxProcess.exitCode === null) { console.log('Force killing hanging process\n\n'); @@ -174,16 +171,20 @@ export default testSuite(async ({ describe }) => { await fixtureExit.rm(); }); - chunks = await interact( + await interact( tsxProcess.stdout!, [ (data) => { + chunks.push(data); if (data.includes('start\n')) { tsxProcess.stdin?.write('enter'); return true; } }, - data => data.includes('end\n'), + data => { + chunks.push(data); + data.includes('end\n'); + }, ], ); From aabaacc91862ca9d8e9a50549492a22cd19992b7 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 22:47:14 +0900 Subject: [PATCH 49/58] wip --- tests/specs/watch.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 931a3d93a..fde3cd672 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -181,9 +181,9 @@ export default testSuite(async ({ describe }) => { return true; } }, - data => { + (data) => { chunks.push(data); - data.includes('end\n'); + return data.includes('end\n'); }, ], ); @@ -263,12 +263,17 @@ export default testSuite(async ({ describe }) => { ], }); + const chunks: string[] = []; + onTestFail(async () => { // If timed out, force kill process if (tsxProcess.exitCode === null) { console.log('Force killing hanging process\n\n'); tsxProcess.kill(); - console.log(await tsxProcess); + console.log({ + tsxProcess: await tsxProcess, + chunks, + }); } }); @@ -278,6 +283,7 @@ export default testSuite(async ({ describe }) => { tsxProcess.stdout!, [ async (data) => { + chunks.push(data); if (data.includes('fail')) { throw new Error('should not log ignored file'); } @@ -295,7 +301,10 @@ export default testSuite(async ({ describe }) => { return true; } }, - data => data === 'TERMINATE\n', + (data) => { + chunks.push(data); + return data === 'TERMINATE\n'; + }, ], ); From b8592c63347f817715a5cbd3be5c6a4f9a66e83b Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 22:55:28 +0900 Subject: [PATCH 50/58] wip --- tests/specs/watch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index fde3cd672..3f0898467 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -297,7 +297,7 @@ export default testSuite(async ({ describe }) => { ]); await setTimeout(1500); - await fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")'); + fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")'); return true; } }, From b16dc15a08260de66161bf047b144f9207bb1750 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 23:12:24 +0900 Subject: [PATCH 51/58] wip --- tests/specs/watch.ts | 55 ++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 3f0898467..eb2b96aa0 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -10,14 +10,33 @@ type MaybePromise = T | Promise; const interact = async ( stdout: Readable, actions: ((data: string) => MaybePromise)[], + timeout: number, ) => { + const startTime = Date.now(); + const logs: [time: number, string][] = []; + let currentAction = actions.shift(); - const buffers: Buffer[] = []; + setTimeout(timeout).then( + () => { + if (currentAction) { + console.error(`Timeout ${timeout}ms exceeded:`); + console.log(logs); + } + }, + () => {}, + ); + while (currentAction) { for await (const [chunk] of on(stdout, 'data')) { - buffers.push(chunk); - if (await currentAction(chunk.toString())) { + const chunkString = chunk.toString(); + logs.push([ + Date.now() - startTime, + chunkString, + ]); + + const gotoNextAction = await currentAction(chunkString); + if (gotoNextAction) { currentAction = actions.shift(); break; } @@ -75,6 +94,7 @@ export default testSuite(async ({ describe }) => { }, data => data.includes(`${initialValue}\n`), ], + 1000, ); tsxProcess.kill(); @@ -102,6 +122,7 @@ export default testSuite(async ({ describe }) => { }, data => data.includes('log-argv.ts'), ], + 1000, ); tsxProcess.kill(); @@ -124,6 +145,7 @@ export default testSuite(async ({ describe }) => { await interact( tsxProcess.stdout!, [data => data.startsWith('["')], + 1000, ); tsxProcess.kill(); @@ -155,7 +177,7 @@ export default testSuite(async ({ describe }) => { cwd: fixtureExit.path, }); - const chunks: string[] = []; + const chunks: [number, string][] = []; onTestFail(async () => { if (tsxProcess.exitCode === null) { console.log('Force killing hanging process\n\n'); @@ -175,17 +197,18 @@ export default testSuite(async ({ describe }) => { tsxProcess.stdout!, [ (data) => { - chunks.push(data); + chunks.push([1, data]); if (data.includes('start\n')) { tsxProcess.stdin?.write('enter'); return true; } }, (data) => { - chunks.push(data); + chunks.push([2, data]); return data.includes('end\n'); }, ], + 1000, ); tsxProcess.kill(); @@ -218,6 +241,7 @@ export default testSuite(async ({ describe }) => { await interact( tsxProcess.stdout!, [data => data.startsWith('["')], + 1000, ); tsxProcess.kill(); @@ -263,7 +287,7 @@ export default testSuite(async ({ describe }) => { ], }); - const chunks: string[] = []; + const chunks: [number, string][] = []; onTestFail(async () => { // If timed out, force kill process @@ -277,35 +301,36 @@ export default testSuite(async ({ describe }) => { } }); - const negativeSignal = '"fail"'; + const negativeSignal = 'fail'; await interact( tsxProcess.stdout!, [ async (data) => { - chunks.push(data); - if (data.includes('fail')) { + chunks.push([1, data]); + if (data.includes(negativeSignal)) { throw new Error('should not log ignored file'); } if (data === 'logA logB logC\n') { // These changes should not trigger a re-run await Promise.all([ - fixtureGlob.writeFile(fileA, `export default ${negativeSignal}`), - fixtureGlob.writeFile(fileB, `export default ${negativeSignal}`), - fixtureGlob.writeFile(depA, `export default ${negativeSignal}`), + fixtureGlob.writeFile(fileA, `export default "${negativeSignal}"`), + fixtureGlob.writeFile(fileB, `export default "${negativeSignal}"`), + fixtureGlob.writeFile(depA, `export default "${negativeSignal}"`), ]); - await setTimeout(1500); + await setTimeout(1000); fixtureGlob.writeFile(entryFile, 'console.log("TERMINATE")'); return true; } }, (data) => { - chunks.push(data); + chunks.push([2, data]); return data === 'TERMINATE\n'; }, ], + 1000, ); tsxProcess.kill(); From 180367c79da30e875be6ac0f260b3481b0e765f9 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 23:13:17 +0900 Subject: [PATCH 52/58] wip --- tests/specs/watch.ts | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index eb2b96aa0..24fb8d4f5 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -177,14 +177,12 @@ export default testSuite(async ({ describe }) => { cwd: fixtureExit.path, }); - const chunks: [number, string][] = []; onTestFail(async () => { if (tsxProcess.exitCode === null) { console.log('Force killing hanging process\n\n'); tsxProcess.kill('SIGKILL'); console.log({ tsxProcess: await tsxProcess, - chunks, }); } }); @@ -197,16 +195,12 @@ export default testSuite(async ({ describe }) => { tsxProcess.stdout!, [ (data) => { - chunks.push([1, data]); if (data.includes('start\n')) { tsxProcess.stdin?.write('enter'); return true; } }, - (data) => { - chunks.push([2, data]); - return data.includes('end\n'); - }, + data => data.includes('end\n'), ], 1000, ); @@ -287,8 +281,6 @@ export default testSuite(async ({ describe }) => { ], }); - const chunks: [number, string][] = []; - onTestFail(async () => { // If timed out, force kill process if (tsxProcess.exitCode === null) { @@ -296,7 +288,6 @@ export default testSuite(async ({ describe }) => { tsxProcess.kill(); console.log({ tsxProcess: await tsxProcess, - chunks, }); } }); @@ -307,7 +298,6 @@ export default testSuite(async ({ describe }) => { tsxProcess.stdout!, [ async (data) => { - chunks.push([1, data]); if (data.includes(negativeSignal)) { throw new Error('should not log ignored file'); } @@ -325,10 +315,7 @@ export default testSuite(async ({ describe }) => { return true; } }, - (data) => { - chunks.push([2, data]); - return data === 'TERMINATE\n'; - }, + data => data === 'TERMINATE\n', ], 1000, ); From 32f53a43be53267fbb9d8fa69b99075299172d85 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Sun, 5 Nov 2023 23:18:57 +0900 Subject: [PATCH 53/58] wip --- tests/specs/watch.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/specs/watch.ts b/tests/specs/watch.ts index 24fb8d4f5..e66afcb1d 100644 --- a/tests/specs/watch.ts +++ b/tests/specs/watch.ts @@ -94,7 +94,7 @@ export default testSuite(async ({ describe }) => { }, data => data.includes(`${initialValue}\n`), ], - 1000, + 5000, ); tsxProcess.kill(); @@ -122,7 +122,7 @@ export default testSuite(async ({ describe }) => { }, data => data.includes('log-argv.ts'), ], - 1000, + 5000, ); tsxProcess.kill(); @@ -145,7 +145,7 @@ export default testSuite(async ({ describe }) => { await interact( tsxProcess.stdout!, [data => data.startsWith('["')], - 1000, + 5000, ); tsxProcess.kill(); @@ -202,7 +202,7 @@ export default testSuite(async ({ describe }) => { }, data => data.includes('end\n'), ], - 1000, + 5000, ); tsxProcess.kill(); @@ -235,7 +235,7 @@ export default testSuite(async ({ describe }) => { await interact( tsxProcess.stdout!, [data => data.startsWith('["')], - 1000, + 5000, ); tsxProcess.kill(); @@ -317,7 +317,7 @@ export default testSuite(async ({ describe }) => { }, data => data === 'TERMINATE\n', ], - 1000, + 9000, ); tsxProcess.kill(); From d51c01f42c1ca94f368f7a2aa810e9fc3171ead1 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Mon, 6 Nov 2023 15:30:57 +0900 Subject: [PATCH 54/58] wip --- tests/specs/smoke.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index a0104c0a9..48c6d170c 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -330,6 +330,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { ...files, 'package.json': JSON.stringify({ type: packageType }), 'import-from-js.js': ` + import assert from 'assert'; import { expectErrors } from './expect-errors'; // node: prefix @@ -343,7 +344,17 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // import * as js from './js/index.js?query=123'; Support query import './js/index'; import './js/'; - + + // No double .default.default in Dynamic Import + import('./js/index.js').then(m => { + if (typeof m.default === 'object') { + assert( + !('default' in m.default), + 'Should not have double .default.default in Dynamic Import', + ); + } + }); + // .json import * as json from './json/index.json'; import './json/index'; @@ -438,6 +449,7 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { 'package.json': JSON.stringify({ type: packageType }), 'import-from-ts.ts': ` + import assert from 'assert'; import { expectErrors } from './expect-errors'; // node: prefix @@ -455,6 +467,16 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { import './js/index'; import './js/'; + // No double .default.default in Dynamic Import + import('./js/index.js').then(m => { + if (typeof m.default === 'object') { + assert( + !('default' in m.default), + 'Should not have double .default.default in Dynamic Import', + ); + } + }); + // .json import * as json from './json/index.json'; import './json/index'; From e0893de17a73e40b13f38765ce4f3a2f85a8f771 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 7 Nov 2023 13:05:27 +0900 Subject: [PATCH 55/58] wip --- tests/specs/cli.ts | 14 ++++++----- tests/utils/expect-match-in-order.ts | 37 ++++++++++++++++++++++++++++ tests/utils/pty-shell/index.ts | 2 +- 3 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 tests/utils/expect-match-in-order.ts diff --git a/tests/specs/cli.ts b/tests/specs/cli.ts index 149188f55..364abbbc9 100644 --- a/tests/specs/cli.ts +++ b/tests/specs/cli.ts @@ -4,6 +4,7 @@ import { createFixture } from 'fs-fixture'; import packageJson from '../../package.json'; import { tsx, tsxPath } from '../utils/tsx'; import { ptyShell, isWindows } from '../utils/pty-shell'; +import { expectMatchInOrder } from '../utils/expect-match-in-order'; export default testSuite(({ describe }) => { describe('CLI', ({ describe, test }) => { @@ -183,12 +184,13 @@ export default testSuite(({ describe }) => { ], ); - expect(output).toMatch( - process.platform === 'win32' - ? 'READY\r\nSIGINT\r\nSIGINT HANDLER COMPLETED\r\n' - : 'READY\r\n^CSIGINT\r\nSIGINT HANDLER COMPLETED\r\n', - ); - expect(output).toMatch(/EXIT_CODE:\s+200/); + expectMatchInOrder(output, [ + 'READY\r\n', + process.platform === 'win32' ? '' : '^C', + 'SIGINT\r\n', + 'SIGINT HANDLER COMPLETED\r\n', + /EXIT_CODE:\s+200/, + ]); }, 10_000); }); }); diff --git a/tests/utils/expect-match-in-order.ts b/tests/utils/expect-match-in-order.ts new file mode 100644 index 000000000..0cf95a403 --- /dev/null +++ b/tests/utils/expect-match-in-order.ts @@ -0,0 +1,37 @@ +type Searchable = string | RegExp; + +const stringify = ( + value: { toString(): string }, +) => JSON.stringify( + value.toString(), // Might be RegExp which requires .toString() +); + +const expectedError = ( + expected: Searchable, + before?: Searchable, +) => new Error(`Expected ${stringify(expected)} ${before ? `to be after ${stringify(before)}` : ''}`); + +export const expectMatchInOrder = ( + subject: string, + expectedOrder: Searchable[], +) => { + let remaining = subject; + for (let i = 0; i < expectedOrder.length; i += 1) { + const previousElement = i > 0 ? expectedOrder[i - 1] : undefined; + const currentElement = expectedOrder[i]; + + if (typeof currentElement === 'string') { + const index = remaining.indexOf(currentElement); + if (index === -1) { + throw expectedError(currentElement, previousElement); + } + remaining = remaining.slice(index + currentElement.length); + } else { + const match = remaining.match(currentElement); + if (!match) { + throw expectedError(currentElement, previousElement); + } + remaining = remaining.slice(match.index! + match[0].length); + } + } +}; diff --git a/tests/utils/pty-shell/index.ts b/tests/utils/pty-shell/index.ts index 527523719..eeef888f2 100644 --- a/tests/utils/pty-shell/index.ts +++ b/tests/utils/pty-shell/index.ts @@ -22,7 +22,7 @@ const getStdin = ( export const ptyShell = ( stdins: StdInArray, -) => new Promise((resolve, reject) => { +) => new Promise((resolve, reject) => { const childProcess = execaNode( fileURLToPath(new URL('node-pty.mjs', import.meta.url)), [shell], From 18e3e8b859906c4f323829b10f355bcbfd8c2721 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 7 Nov 2023 13:12:48 +0900 Subject: [PATCH 56/58] wip --- tests/specs/cli.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/specs/cli.ts b/tests/specs/cli.ts index 364abbbc9..f5f5b6e1a 100644 --- a/tests/specs/cli.ts +++ b/tests/specs/cli.ts @@ -157,7 +157,11 @@ export default testSuite(({ describe }) => { expect(tsxProcessResolved.stdout).toBe('READY'); } else { expect(tsxProcessResolved.exitCode).toBe(200); - expect(tsxProcessResolved.stdout).toBe(`READY\n${signal}\n${signal} HANDLER COMPLETED`); + expectMatchInOrder(tsxProcessResolved.stdout, [ + 'READY\n', + `${signal}\n`, + `${signal} HANDLER COMPLETED`, + ]); } }, 10_000); } From 3b1a07d530de1817a87393d59b085b455e1c9cde Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 8 Nov 2023 13:41:10 +0900 Subject: [PATCH 57/58] wip --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- tests/index.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1f09bf82d..9090340dc 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "kolorist": "^1.8.0", "lint-staged": "^14.0.1", "magic-string": "^0.30.3", - "manten": "github:privatenumber/manten#npm/error-hooks", + "manten": "github:privatenumber/manten#npm/develop", "node-pty": "^1.0.0", "outdent": "^0.8.0", "pkgroll": "^1.11.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 35b1b8103..7ec20719f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,8 +82,8 @@ devDependencies: specifier: ^0.30.3 version: 0.30.3 manten: - specifier: github:privatenumber/manten#npm/error-hooks - version: github.com/privatenumber/manten/83dc0dd465e479a09bb44c049af99d81b3b1d558 + specifier: github:privatenumber/manten#npm/develop + version: github.com/privatenumber/manten/c39ab8f054ebc5182bd12965ab7519b3ee139ddc node-pty: specifier: ^1.0.0 version: 1.0.0 @@ -4224,8 +4224,8 @@ packages: engines: {node: '>=12.20'} dev: true - github.com/privatenumber/manten/83dc0dd465e479a09bb44c049af99d81b3b1d558: - resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/83dc0dd465e479a09bb44c049af99d81b3b1d558} + github.com/privatenumber/manten/c39ab8f054ebc5182bd12965ab7519b3ee139ddc: + resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/c39ab8f054ebc5182bd12965ab7519b3ee139ddc} name: manten version: 0.0.0-semantic-release dependencies: diff --git a/tests/index.ts b/tests/index.ts index 57acf132d..7e7d0cb16 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -4,9 +4,9 @@ import { nodeVersions } from './utils/node-versions'; (async () => { await describe('tsx', async ({ runTestSuite, describe }) => { - runTestSuite(import('./specs/cli')); - runTestSuite(import('./specs/watch')); - runTestSuite(import('./specs/repl')); + await runTestSuite(import('./specs/cli')); + await runTestSuite(import('./specs/watch')); + await runTestSuite(import('./specs/repl')); for (const nodeVersion of nodeVersions) { const node = await createNode(nodeVersion); From b56adf6d79b5c4238cb7786afb29b0ba0ec290a9 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Wed, 8 Nov 2023 14:08:40 +0900 Subject: [PATCH 58/58] wip --- package.json | 2 +- pnpm-lock.yaml | 56 ++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 9090340dc..b094d1cd4 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "kolorist": "^1.8.0", "lint-staged": "^14.0.1", "magic-string": "^0.30.3", - "manten": "github:privatenumber/manten#npm/develop", + "manten": "^1.2.0", "node-pty": "^1.0.0", "outdent": "^0.8.0", "pkgroll": "^1.11.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ec20719f..615be531d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -82,8 +82,8 @@ devDependencies: specifier: ^0.30.3 version: 0.30.3 manten: - specifier: github:privatenumber/manten#npm/develop - version: github.com/privatenumber/manten/c39ab8f054ebc5182bd12965ab7519b3ee139ddc + specifier: ^1.2.0 + version: 1.2.0 node-pty: specifier: ^1.0.0 version: 1.0.0 @@ -401,10 +401,10 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@jest/schemas': 29.6.3 - '@types/istanbul-lib-coverage': 2.0.4 - '@types/istanbul-reports': 3.0.1 + '@types/istanbul-lib-coverage': 2.0.6 + '@types/istanbul-reports': 3.0.4 '@types/node': 20.6.0 - '@types/yargs': 17.0.24 + '@types/yargs': 17.0.31 chalk: 4.1.2 dev: true @@ -625,20 +625,20 @@ packages: resolution: {integrity: sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ==} dev: true - /@types/istanbul-lib-coverage@2.0.4: - resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} + /@types/istanbul-lib-coverage@2.0.6: + resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} dev: true - /@types/istanbul-lib-report@3.0.0: - resolution: {integrity: sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==} + /@types/istanbul-lib-report@3.0.3: + resolution: {integrity: sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==} dependencies: - '@types/istanbul-lib-coverage': 2.0.4 + '@types/istanbul-lib-coverage': 2.0.6 dev: true - /@types/istanbul-reports@3.0.1: - resolution: {integrity: sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==} + /@types/istanbul-reports@3.0.4: + resolution: {integrity: sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==} dependencies: - '@types/istanbul-lib-report': 3.0.0 + '@types/istanbul-lib-report': 3.0.3 dev: true /@types/json-schema@7.0.12: @@ -693,22 +693,22 @@ packages: source-map: 0.6.1 dev: true - /@types/stack-utils@2.0.1: - resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==} + /@types/stack-utils@2.0.3: + resolution: {integrity: sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==} dev: true /@types/unist@2.0.8: resolution: {integrity: sha512-d0XxK3YTObnWVp6rZuev3c49+j4Lo8g4L1ZRm9z5L0xpoZycUPshHgczK5gsUMaZOstjVYYi09p5gYvUtfChYw==} dev: true - /@types/yargs-parser@21.0.0: - resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} + /@types/yargs-parser@21.0.3: + resolution: {integrity: sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==} dev: true - /@types/yargs@17.0.24: - resolution: {integrity: sha512-6i0aC7jV6QzQB8ne1joVZ0eSFIstHsCrobmOtghM11yGlH0j43FKL2UhWdELkyps0zuf7qVTUVCCR+tgSlyLLw==} + /@types/yargs@17.0.31: + resolution: {integrity: sha512-bocYSx4DI8TmdlvxqGpVNXOgCNR1Jj0gNPhhAY+iz1rgKDAaYrAYdFYnhDV1IFuiuVc9HkOwyDcFxaTElF3/wg==} dependencies: - '@types/yargs-parser': 21.0.0 + '@types/yargs-parser': 21.0.3 dev: true /@typescript-eslint/eslint-plugin@6.7.0(@typescript-eslint/parser@6.7.0)(eslint@8.49.0)(typescript@5.2.2): @@ -2684,7 +2684,7 @@ packages: dependencies: '@babel/code-frame': 7.22.13 '@jest/types': 29.6.3 - '@types/stack-utils': 2.0.1 + '@types/stack-utils': 2.0.3 chalk: 4.1.2 graceful-fs: 4.2.11 micromatch: 4.0.5 @@ -2931,6 +2931,12 @@ packages: '@jridgewell/sourcemap-codec': 1.4.15 dev: true + /manten@1.2.0: + resolution: {integrity: sha512-H6+meeudHQqh8k4N5IKB40TP27V1rjcYfmRdkJ5ffCaMYxVKW0M1p9+LVAH0uGoxcMcHKJ4GNUPhOit4Ok/ykA==} + dependencies: + expect: 29.7.0 + dev: true + /map-age-cleaner@0.1.3: resolution: {integrity: sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w==} engines: {node: '>=6'} @@ -4223,11 +4229,3 @@ packages: resolution: {integrity: sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==} engines: {node: '>=12.20'} dev: true - - github.com/privatenumber/manten/c39ab8f054ebc5182bd12965ab7519b3ee139ddc: - resolution: {tarball: https://codeload.github.com/privatenumber/manten/tar.gz/c39ab8f054ebc5182bd12965ab7519b3ee139ddc} - name: manten - version: 0.0.0-semantic-release - dependencies: - expect: 29.7.0 - dev: true