Skip to content

Commit

Permalink
test: external source maps
Browse files Browse the repository at this point in the history
closes #340
  • Loading branch information
privatenumber committed May 28, 2024
1 parent 3d7bce7 commit f30b296
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 12 additions & 3 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import outdent from 'outdent';
import type { PackageJson, TsConfigJson } from 'type-fest';

export const createPackageJson = (packageJson: PackageJson) => JSON.stringify(packageJson);
Expand Down Expand Up @@ -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}\`);
}
}),
Expand All @@ -123,7 +127,7 @@ export const expectErrors = {
export const files = {
...expectErrors,

'js/index.js': `
'js/index.js': outdent`
import assert from 'assert';
${syntaxLowering}
${preserveName}
Expand All @@ -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};
Expand Down Expand Up @@ -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({
Expand Down
10 changes: 8 additions & 2 deletions tests/specs/smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
${
Expand Down Expand Up @@ -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'],
${
Expand Down

0 comments on commit f30b296

Please sign in to comment.