|
| 1 | +import { spawnPromisified } from '../common/index.mjs'; |
| 2 | +import * as fixtures from '../common/fixtures.mjs'; |
| 3 | + |
| 4 | +import assert from 'node:assert'; |
| 5 | +import { execPath } from 'node:process'; |
| 6 | +import { describe, it } from 'node:test'; |
| 7 | + |
| 8 | +const urlToRegister = fixtures.fileURL('es-module-loaders', 'loader-resolve-passthru.mjs'); |
| 9 | +const urlToRegisterEscaped = JSON.stringify(urlToRegister.href); |
| 10 | + |
| 11 | + |
| 12 | +describe('module.register() deprecation (DEP0205)', { concurrency: !process.env.TEST_PARALLEL }, () => { |
| 13 | + it('emits DEP0205 when module.register() is called', async () => { |
| 14 | + const { code, stderr } = await spawnPromisified(execPath, [ |
| 15 | + '--input-type=module', |
| 16 | + '--eval', |
| 17 | + `import { register } from 'node:module'; register(${urlToRegisterEscaped});`, |
| 18 | + ]); |
| 19 | + |
| 20 | + assert.match(stderr, /\[DEP0205\]/); |
| 21 | + assert.strictEqual(code, 0); |
| 22 | + }); |
| 23 | + |
| 24 | + it('only emits the warning once per process', async () => { |
| 25 | + const { code, stderr } = await spawnPromisified(execPath, [ |
| 26 | + '--input-type=module', |
| 27 | + '--eval', |
| 28 | + `import { register } from 'node:module'; |
| 29 | + register(${urlToRegisterEscaped}); |
| 30 | + register(${urlToRegisterEscaped});`, |
| 31 | + ]); |
| 32 | + |
| 33 | + assert.strictEqual(stderr.split('[DEP0205]').length - 1, 1); |
| 34 | + assert.strictEqual(code, 0); |
| 35 | + }); |
| 36 | + |
| 37 | + it('does not emit when --no-deprecation is set', async () => { |
| 38 | + const { code, stderr } = await spawnPromisified(execPath, [ |
| 39 | + '--no-deprecation', |
| 40 | + '--input-type=module', |
| 41 | + '--eval', |
| 42 | + `import { register } from 'node:module'; register(${urlToRegisterEscaped});`, |
| 43 | + ]); |
| 44 | + |
| 45 | + assert.doesNotMatch(stderr, /DEP0205/); |
| 46 | + assert.strictEqual(code, 0); |
| 47 | + }); |
| 48 | + |
| 49 | + it('throws when --throw-deprecation is set', async () => { |
| 50 | + const { code, stderr } = await spawnPromisified(execPath, [ |
| 51 | + '--throw-deprecation', |
| 52 | + '--input-type=module', |
| 53 | + '--eval', |
| 54 | + `import { register } from 'node:module'; register(${urlToRegisterEscaped});`, |
| 55 | + ]); |
| 56 | + |
| 57 | + assert.match(stderr, /DEP0205/); |
| 58 | + assert.notStrictEqual(code, 0); |
| 59 | + }); |
| 60 | +}); |
0 commit comments