-
-
Notifications
You must be signed in to change notification settings - Fork 32k
esm: refactor esm tests out of test/message #41352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9cc2d32
37041fb
6b8320b
72e8a70
caab55c
54821b7
9be8289
12c3457
3ea5e1b
d64d044
b042d99
13861f0
c191d04
17e01c3
f55caa6
2964898
211db37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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.
Uh oh!
There was an error while loading. Please reload this page.