node/test/es-module/test-esm-invalid-pjson.js
Michaël Zasso 67bbfeb7e1
test: make tests pass on Windows with Unix EOL
It is possible on Windows to configure Git to checkout line-endings
"as-is", which for Node.js means Unix-style.
This change makes the tests that rely on line endings pass in that case.

PR-URL: https://github.com/nodejs/node/pull/40002
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2021-09-21 19:13:36 +01:00

27 lines
884 B
JavaScript

'use strict';
const { mustCall, checkoutEOL } = require('../common');
const fixtures = require('../common/fixtures');
const { spawn } = require('child_process');
const { strictEqual, ok } = require('assert');
const entry = fixtures.path('/es-modules/import-invalid-pjson.mjs');
const invalidJson = fixtures.path('/node_modules/invalid-pjson/package.json');
const child = spawn(process.execPath, [entry]);
child.stderr.setEncoding('utf8');
let stderr = '';
child.stderr.on('data', (data) => {
stderr += data;
});
child.on('close', mustCall((code, signal) => {
strictEqual(code, 1);
strictEqual(signal, null);
ok(
stderr.includes(
`[ERR_INVALID_PACKAGE_CONFIG]: Invalid package config ${invalidJson} ` +
`while importing "invalid-pjson" from ${entry}. ` +
`Unexpected token } in JSON at position ${12 + checkoutEOL.length * 2}`
),
stderr);
}));