From 98b437db82fb2f59c9da8a1c745e0aced642963a Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Tue, 28 May 2024 16:06:03 +0200 Subject: [PATCH] test: external source maps closes #340 --- tests/fixtures.ts | 15 ++++++++++++--- tests/specs/smoke.ts | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/fixtures.ts b/tests/fixtures.ts index b31d789bb..cdb8969a0 100644 --- a/tests/fixtures.ts +++ b/tests/fixtures.ts @@ -1,3 +1,4 @@ +import outdent from 'outdent'; import type { PackageJson, TsConfigJson } from 'type-fest'; export const createPackageJson = (packageJson: PackageJson) => JSON.stringify(packageJson); @@ -104,7 +105,10 @@ export const expectErrors = { if (!thrown) { return new Error('No error thrown'); - } else if (!thrown.message.includes(expectedError)) { + } else if ( + !thrown.message.includes(expectedError) + && !thrown.stack.includes(expectedError) + ) { return new Error(\`Message \${JSON.stringify(expectedError)} not found in \${JSON.stringify(thrown.message)}\n\${thrown.stack}\`); } }), @@ -123,7 +127,7 @@ export const expectErrors = { export const files = { ...expectErrors, - 'js/index.js': ` + 'js/index.js': outdent` import assert from 'assert'; ${syntaxLowering} ${preserveName} @@ -145,7 +149,7 @@ export const files = { exports.named = 'named'; `, - 'mjs/index.mjs': ` + 'mjs/index.mjs': outdent` import assert from 'assert'; export const mjsHasCjsContext = ${cjsContextCheck}; @@ -231,6 +235,11 @@ export const files = { 'broken-syntax.ts': 'if', + 'file-with-sourcemap.js': outdent` + throw new Error; + //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiYXNkZi5qcyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cblxuXG5cbnRocm93IG5ldyBFcnJvcigpIl0sCiAgIm1hcHBpbmdzIjogIkFBNkJBLE1BQU0sSUFBSSIsCiAgIm5hbWVzIjogW10KfQo= + `, + node_modules: { 'pkg-commonjs': { 'package.json': createPackageJson({ diff --git a/tests/specs/smoke.ts b/tests/specs/smoke.ts index ed28f29b9..b1cb6a649 100644 --- a/tests/specs/smoke.ts +++ b/tests/specs/smoke.ts @@ -93,8 +93,11 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { // Is TS loadable here? // Import jsx? - // Unsupported files expectErrors( + // External source maps + [() => import ('./file-with-sourcemap.js'), '/asdf.js:30:7'], + + // Unsupported files [() => import ('./file.txt'), 'Unknown file extension'], [() => import (${JSON.stringify(wasmPathUrl)}), 'Unknown file extension'], ${ @@ -293,8 +296,11 @@ export default testSuite(async ({ describe }, { tsx }: NodeApis) => { ); // Loading via Node arg should not work via .mjs but with .mts - // Unsupported files expectErrors( + // External source maps + [() => import ('./file-with-sourcemap.js'), '/asdf.js:30:7'], + + // Unsupported files [() => import ('./file.txt'), 'Unknown file extension'], [() => import (${JSON.stringify(wasmPathUrl)}), 'Unknown file extension'], ${