-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
PR-URL: #41352 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { path } from '../common/fixtures.mjs'; | ||
import { match, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const importStatement = | ||
'import { foo, notfound } from \'./module-named-exports.mjs\';'; | ||
const importStatementMultiline = `import { | ||
foo, | ||
notfound | ||
} from './module-named-exports.mjs'; | ||
`; | ||
|
||
[importStatement, importStatementMultiline].forEach((input) => { | ||
const child = spawn(execPath, [ | ||
'--input-type=module', | ||
'--eval', | ||
input, | ||
], { | ||
cwd: path('es-module-loaders'), | ||
}); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
|
||
// SyntaxError: The requested module './module-named-exports.mjs' | ||
// does not provide an export named 'notfound' | ||
match(stderr, /SyntaxError:/); | ||
// The quotes ensure that the path starts with ./ and not ../ | ||
match(stderr, /'\.\/module-named-exports\.mjs'/); | ||
match(stderr, /notfound/); | ||
})); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { path } from '../common/fixtures.mjs'; | ||
import { match, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const child = spawn(execPath, [ | ||
'--experimental-json-modules', | ||
path('es-modules', 'import-json-named-export.mjs'), | ||
]); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
|
||
// SyntaxError: The requested module '../experimental.json' | ||
// does not provide an export named 'ofLife' | ||
match(stderr, /SyntaxError:/); | ||
match(stderr, /'\.\.\/experimental\.json'/); | ||
match(stderr, /'ofLife'/); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { path } from '../common/fixtures.mjs'; | ||
import { match, ok, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const child = spawn(execPath, [ | ||
'--experimental-loader', | ||
'i-dont-exist', | ||
path('print-error-message.js'), | ||
]); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
|
||
// Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' | ||
// imported from | ||
match(stderr, /ERR_MODULE_NOT_FOUND/); | ||
match(stderr, /'i-dont-exist'/); | ||
|
||
ok(!stderr.includes('Bad command or file name')); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { fileURL, path } from '../common/fixtures.mjs'; | ||
import { match, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const child = spawn(execPath, [ | ||
'--no-warnings', | ||
'--throw-deprecation', | ||
'--experimental-loader', | ||
fileURL('es-module-loaders', 'hooks-obsolete.mjs').href, | ||
path('print-error-message.js'), | ||
]); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
|
||
// DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: | ||
// dynamicInstantiate, getFormat, getSource, transformSource | ||
match(stderr, /DeprecationWarning:/); | ||
match(stderr, /dynamicInstantiate/); | ||
match(stderr, /getFormat/); | ||
match(stderr, /getSource/); | ||
match(stderr, /transformSource/); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { fileURL, path } from '../common/fixtures.mjs'; | ||
import { match, ok, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const child = spawn(execPath, [ | ||
'--experimental-loader', | ||
fileURL('es-module-loaders', 'syntax-error.mjs').href, | ||
path('print-error-message.js'), | ||
]); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
|
||
match(stderr, /SyntaxError:/); | ||
|
||
ok(!stderr.includes('Bad command or file name')); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { fixturesDir } from '../common/fixtures.mjs'; | ||
import { match, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
[ | ||
{ | ||
input: 'import "./print-error-message"', | ||
// Did you mean to import ../print-error-message.js? | ||
expected: / \.\.\/print-error-message\.js\?/, | ||
}, | ||
{ | ||
input: 'import obj from "some_module/obj"', | ||
expected: / some_module\/obj\.js\?/, | ||
}, | ||
].forEach(({ input, expected }) => { | ||
const child = spawn(execPath, [ | ||
'--input-type=module', | ||
'--eval', | ||
input, | ||
], { | ||
cwd: fixturesDir, | ||
}); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
match(stderr, expected); | ||
})); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { mustCall } from '../common/index.mjs'; | ||
import { path } from '../common/fixtures.mjs'; | ||
import { match, notStrictEqual } from 'assert'; | ||
import { spawn } from 'child_process'; | ||
import { execPath } from 'process'; | ||
|
||
const child = spawn(execPath, [ | ||
path('es-module-loaders', 'syntax-error.mjs'), | ||
]); | ||
|
||
let stderr = ''; | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', (data) => { | ||
stderr += data; | ||
}); | ||
child.on('close', mustCall((code, _signal) => { | ||
notStrictEqual(code, 0); | ||
match(stderr, /SyntaxError:/); | ||
})); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import { ofLife } from '../experimental.json' assert { type: 'json' }; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.error('Bad command or file name'); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.