Skip to content

Commit a28735a

Browse files
committed
test: adapt error message expectations for Node.js 22+ JSON parsing
1 parent 5c605aa commit a28735a

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

test/jest/dep-graph-builders/npm-lock-v2.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,18 +402,24 @@ describe('dep-graph-builder npm-lock-v2', () => {
402402
'utf8',
403403
);
404404
const npmLockContent = '';
405+
406+
const nodeMajorVersion = parseInt(
407+
process.version.substring(1).split('.')[0],
408+
10,
409+
);
410+
const expectedErrorMessage =
411+
nodeMajorVersion >= 22
412+
? 'package.json parsing failed with error Expected double-quoted property name in JSON at position 100 (line 6 column 3)'
413+
: 'package.json parsing failed with error Unexpected token } in JSON at position 100';
414+
405415
await expect(
406416
parseNpmLockV2Project(pkgJsonContent, npmLockContent, {
407417
includeDevDeps: false,
408418
includeOptionalDeps: true,
409419
pruneCycles: true,
410420
strictOutOfSync: false,
411421
}),
412-
).rejects.toThrow(
413-
new InvalidUserInputError(
414-
'package.json parsing failed with error Unexpected token } in JSON at position 100',
415-
),
416-
);
422+
).rejects.toThrow(new InvalidUserInputError(expectedErrorMessage));
417423
});
418424

419425
it('project: simple-non-top-level-out-of-sync -> throws OutOfSyncError', async () => {

test/jest/dep-graph-builders/pnpm-lock.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,24 @@ describe.each(['pnpm-lock-v5', 'pnpm-lock-v6', 'pnpm-lock-v9'])(
182182
'utf8',
183183
);
184184
const pnpmLockContent = '';
185+
186+
const nodeMajorVersion = parseInt(
187+
process.version.substring(1).split('.')[0],
188+
10,
189+
);
190+
const expectedErrorMessage =
191+
nodeMajorVersion >= 22
192+
? 'package.json parsing failed with error Expected double-quoted property name in JSON at position 100 (line 6 column 3)'
193+
: 'package.json parsing failed with error Unexpected token } in JSON at position 100';
194+
185195
await expect(
186196
parsePnpmProject(pkgJsonContent, pnpmLockContent, {
187197
includeDevDeps: false,
188198
includeOptionalDeps: true,
189199
pruneWithinTopLevelDeps: true,
190200
strictOutOfSync: false,
191201
}),
192-
).rejects.toThrow(
193-
new InvalidUserInputError(
194-
'package.json parsing failed with error Unexpected token } in JSON at position 100',
195-
),
196-
);
202+
).rejects.toThrow(new InvalidUserInputError(expectedErrorMessage));
197203
});
198204
it('project: simple-non-top-level-out-of-sync -> throws OutOfSyncError', async () => {
199205
const fixtureName = 'missing-non-top-level-deps';

test/jest/dep-graph-builders/yarn-lock-v1-realistic-fixtures.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ describe('Unhappy path tests', () => {
311311
'utf8',
312312
);
313313
const yarnLockContent = '';
314+
315+
const nodeMajorVersion = parseInt(
316+
process.version.substring(1).split('.')[0],
317+
10,
318+
);
319+
const expectedErrorMessage =
320+
nodeMajorVersion >= 22
321+
? 'package.json parsing failed with error Expected double-quoted property name in JSON at position 100 (line 6 column 3)'
322+
: 'package.json parsing failed with error Unexpected token } in JSON at position 100';
323+
314324
await expect(
315325
parseYarnLockV1Project(pkgJsonContent, yarnLockContent, {
316326
includeDevDeps: false,
@@ -319,11 +329,7 @@ describe('Unhappy path tests', () => {
319329
pruneLevel: 'cycles',
320330
strictOutOfSync: false,
321331
}),
322-
).rejects.toThrow(
323-
new InvalidUserInputError(
324-
'package.json parsing failed with error Unexpected token } in JSON at position 100',
325-
),
326-
);
332+
).rejects.toThrow(new InvalidUserInputError(expectedErrorMessage));
327333
});
328334

329335
it('project: simple-top-level-out-of-sync -> throws OutOfSyncError', async () => {

0 commit comments

Comments
 (0)