GeezerVison is showing github.com — esm: refactor esm tests out of test/message · nodejs/node@8a94ca7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: test/common/fixtures.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | const path = require('path'); | 4 | 4 | const fs = require('fs'); | | 5 | +const { pathToFileURL } = require('url'); | 5 | 6 |
| 6 | 7 | const fixturesDir = path.join(__dirname, '..', 'fixtures'); | 7 | 8 |
| 8 | 9 | function fixturesPath(...args) { | 9 | 10 | return path.join(fixturesDir, ...args); | 10 | 11 | } | 11 | 12 |
| | 13 | +function fixturesFileURL(...args) { | | 14 | + return pathToFileURL(fixturesPath(...args)); | | 15 | +} | | 16 | + | 12 | 17 | function readFixtureSync(args, enc) { | 13 | 18 | if (Array.isArray(args)) | 14 | 19 | return fs.readFileSync(fixturesPath(...args), enc); | @@ -26,6 +31,7 @@ function readFixtureKeys(enc, ...names) { | 26 | 31 | module.exports = { | 27 | 32 | fixturesDir, | 28 | 33 | path: fixturesPath, | | 34 | + fileURL: fixturesFileURL, | 29 | 35 | readSync: readFixtureSync, | 30 | 36 | readKey: readFixtureKey, | 31 | 37 | readKeys: readFixtureKeys, | |
Collapse file Copy file name to clipboardExpand all lines: test/common/fixtures.mjs +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,13 +3,15 @@ import fixtures from './fixtures.js'; | 3 | 3 | const { | 4 | 4 | fixturesDir, | 5 | 5 | path, | | 6 | + fileURL, | 6 | 7 | readSync, | 7 | 8 | readKey, | 8 | 9 | } = fixtures; | 9 | 10 |
| 10 | 11 | export { | 11 | 12 | fixturesDir, | 12 | 13 | path, | | 14 | + fileURL, | 13 | 15 | readSync, | 14 | 16 | readKey, | 15 | 17 | }; |
Collapse file Copy file name to clipboard +39Lines changed: 39 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { path } from '../common/fixtures.mjs'; | | 3 | +import { match, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const importStatement = | | 8 | + 'import { foo, notfound } from \'./module-named-exports.mjs\';'; | | 9 | +const importStatementMultiline = `import { | | 10 | + foo, | | 11 | + notfound | | 12 | +} from './module-named-exports.mjs'; | | 13 | +`; | | 14 | + | | 15 | +[importStatement, importStatementMultiline].forEach((input) => { | | 16 | + const child = spawn(execPath, [ | | 17 | + '--input-type=module', | | 18 | + '--eval', | | 19 | + input, | | 20 | + ], { | | 21 | + cwd: path('es-module-loaders'), | | 22 | + }); | | 23 | + | | 24 | + let stderr = ''; | | 25 | + child.stderr.setEncoding('utf8'); | | 26 | + child.stderr.on('data', (data) => { | | 27 | + stderr += data; | | 28 | + }); | | 29 | + child.on('close', mustCall((code, _signal) => { | | 30 | + notStrictEqual(code, 0); | | 31 | + | | 32 | + // SyntaxError: The requested module './module-named-exports.mjs' | | 33 | + // does not provide an export named 'notfound' | | 34 | + match(stderr, /SyntaxError:/); | | 35 | + // The quotes ensure that the path starts with ./ and not ../ | | 36 | + match(stderr, /'\.\/module-named-exports\.mjs'/); | | 37 | + match(stderr, /notfound/); | | 38 | + })); | | 39 | +}); |
Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { path } from '../common/fixtures.mjs'; | | 3 | +import { match, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const child = spawn(execPath, [ | | 8 | + '--experimental-json-modules', | | 9 | + path('es-modules', 'import-json-named-export.mjs'), | | 10 | +]); | | 11 | + | | 12 | +let stderr = ''; | | 13 | +child.stderr.setEncoding('utf8'); | | 14 | +child.stderr.on('data', (data) => { | | 15 | + stderr += data; | | 16 | +}); | | 17 | +child.on('close', mustCall((code, _signal) => { | | 18 | + notStrictEqual(code, 0); | | 19 | + | | 20 | + // SyntaxError: The requested module '../experimental.json' | | 21 | + // does not provide an export named 'ofLife' | | 22 | + match(stderr, /SyntaxError:/); | | 23 | + match(stderr, /'\.\.\/experimental\.json'/); | | 24 | + match(stderr, /'ofLife'/); | | 25 | +})); |
Collapse file Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { path } from '../common/fixtures.mjs'; | | 3 | +import { match, ok, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const child = spawn(execPath, [ | | 8 | + '--experimental-loader', | | 9 | + 'i-dont-exist', | | 10 | + path('print-error-message.js'), | | 11 | +]); | | 12 | + | | 13 | +let stderr = ''; | | 14 | +child.stderr.setEncoding('utf8'); | | 15 | +child.stderr.on('data', (data) => { | | 16 | + stderr += data; | | 17 | +}); | | 18 | +child.on('close', mustCall((code, _signal) => { | | 19 | + notStrictEqual(code, 0); | | 20 | + | | 21 | + // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' | | 22 | + // imported from | | 23 | + match(stderr, /ERR_MODULE_NOT_FOUND/); | | 24 | + match(stderr, /'i-dont-exist'/); | | 25 | + | | 26 | + ok(!stderr.includes('Bad command or file name')); | | 27 | +})); |
Collapse file Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { fileURL, path } from '../common/fixtures.mjs'; | | 3 | +import { match, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const child = spawn(execPath, [ | | 8 | + '--no-warnings', | | 9 | + '--throw-deprecation', | | 10 | + '--experimental-loader', | | 11 | + fileURL('es-module-loaders', 'hooks-obsolete.mjs').href, | | 12 | + path('print-error-message.js'), | | 13 | +]); | | 14 | + | | 15 | +let stderr = ''; | | 16 | +child.stderr.setEncoding('utf8'); | | 17 | +child.stderr.on('data', (data) => { | | 18 | + stderr += data; | | 19 | +}); | | 20 | +child.on('close', mustCall((code, _signal) => { | | 21 | + notStrictEqual(code, 0); | | 22 | + | | 23 | + // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: | | 24 | + // dynamicInstantiate, getFormat, getSource, transformSource | | 25 | + match(stderr, /DeprecationWarning:/); | | 26 | + match(stderr, /dynamicInstantiate/); | | 27 | + match(stderr, /getFormat/); | | 28 | + match(stderr, /getSource/); | | 29 | + match(stderr, /transformSource/); | | 30 | +})); |
Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { fileURL, path } from '../common/fixtures.mjs'; | | 3 | +import { match, ok, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const child = spawn(execPath, [ | | 8 | + '--experimental-loader', | | 9 | + fileURL('es-module-loaders', 'syntax-error.mjs').href, | | 10 | + path('print-error-message.js'), | | 11 | +]); | | 12 | + | | 13 | +let stderr = ''; | | 14 | +child.stderr.setEncoding('utf8'); | | 15 | +child.stderr.on('data', (data) => { | | 16 | + stderr += data; | | 17 | +}); | | 18 | +child.on('close', mustCall((code, _signal) => { | | 19 | + notStrictEqual(code, 0); | | 20 | + | | 21 | + match(stderr, /SyntaxError:/); | | 22 | + | | 23 | + ok(!stderr.includes('Bad command or file name')); | | 24 | +})); |
Collapse file Copy file name to clipboard +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { fixturesDir } from '../common/fixtures.mjs'; | | 3 | +import { match, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +[ | | 8 | + { | | 9 | + input: 'import "./print-error-message"', | | 10 | + // Did you mean to import ../print-error-message.js? | | 11 | + expected: / \.\.\/print-error-message\.js\?/, | | 12 | + }, | | 13 | + { | | 14 | + input: 'import obj from "some_module/obj"', | | 15 | + expected: / some_module\/obj\.js\?/, | | 16 | + }, | | 17 | +].forEach(({ input, expected }) => { | | 18 | + const child = spawn(execPath, [ | | 19 | + '--input-type=module', | | 20 | + '--eval', | | 21 | + input, | | 22 | + ], { | | 23 | + cwd: fixturesDir, | | 24 | + }); | | 25 | + | | 26 | + let stderr = ''; | | 27 | + child.stderr.setEncoding('utf8'); | | 28 | + child.stderr.on('data', (data) => { | | 29 | + stderr += data; | | 30 | + }); | | 31 | + child.on('close', mustCall((code, _signal) => { | | 32 | + notStrictEqual(code, 0); | | 33 | + match(stderr, expected); | | 34 | + })); | | 35 | +}); |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { mustCall } from '../common/index.mjs'; | | 2 | +import { path } from '../common/fixtures.mjs'; | | 3 | +import { match, notStrictEqual } from 'assert'; | | 4 | +import { spawn } from 'child_process'; | | 5 | +import { execPath } from 'process'; | | 6 | + | | 7 | +const child = spawn(execPath, [ | | 8 | + path('es-module-loaders', 'syntax-error.mjs'), | | 9 | +]); | | 10 | + | | 11 | +let stderr = ''; | | 12 | +child.stderr.setEncoding('utf8'); | | 13 | +child.stderr.on('data', (data) => { | | 14 | + stderr += data; | | 15 | +}); | | 16 | +child.on('close', mustCall((code, _signal) => { | | 17 | + notStrictEqual(code, 0); | | 18 | + match(stderr, /SyntaxError:/); | | 19 | +})); |
Collapse file Copy file name to clipboardExpand all lines: test/fixtures/es-module-loaders/syntax-error-import.mjs -1Lines changed: 0 additions & 1 deletion
|