• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const { checkoutEOL, spawnPromisified } = require('../common');
4const fixtures = require('../common/fixtures.js');
5const assert = require('node:assert');
6const { execPath } = require('node:process');
7const { describe, it } = require('node:test');
8
9
10describe('ESM: Package.json', { concurrency: true }, () => {
11  it('should throw on invalid pson', async () => {
12    const entry = fixtures.path('/es-modules/import-invalid-pjson.mjs');
13    const invalidJson = fixtures.path('/node_modules/invalid-pjson/package.json');
14
15    const { code, signal, stderr } = await spawnPromisified(execPath, [entry]);
16
17    assert.ok(
18      stderr.includes(
19        `[ERR_INVALID_PACKAGE_CONFIG]: Invalid package config ${invalidJson} ` +
20        `while importing "invalid-pjson" from ${entry}. ` +
21        `Unexpected token } in JSON at position ${12 + checkoutEOL.length * 2}`
22      ),
23      stderr
24    );
25    assert.strictEqual(code, 1);
26    assert.strictEqual(signal, null);
27  });
28});
29