Skip to content

Commit 4d11ace

Browse files
clydindgp1130
authored andcommitted
test: improve resilience of E2E postinstall check to package hoisting
False positive package paths are now checked relative to their containing `node_modules` directory. This avoids issues checking the paths when the package manager changes its hoisting strategy for one of the affected paths. (cherry picked from commit 8431b3f)
1 parent 170c16f commit 4d11ace

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tests/legacy-cli/e2e/tests/misc/check-postinstalls.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@ const POTENTIAL_SCRIPTS: ReadonlyArray<string> = ['preinstall', 'install', 'post
1313

1414
// Some packages include test and/or example code that causes false positives
1515
const FALSE_POSITIVE_PATHS: ReadonlySet<string> = new Set([
16-
'node_modules/jasmine-spec-reporter/examples/protractor/package.json',
17-
'node_modules/resolve/test/resolver/multirepo/package.json',
16+
'jasmine-spec-reporter/examples/protractor/package.json',
17+
'resolve/test/resolver/multirepo/package.json',
1818
]);
1919

20+
const INNER_NODE_MODULES_SEGMENT = '/node_modules/';
21+
2022
export default async function () {
2123
const manifestPaths = await globAsync('node_modules/**/package.json');
2224
const newPackages: string[] = [];
2325

2426
for (const manifestPath of manifestPaths) {
25-
if (FALSE_POSITIVE_PATHS.has(manifestPath)) {
27+
const lastNodeModuleIndex = manifestPath.lastIndexOf(INNER_NODE_MODULES_SEGMENT);
28+
const packageRelativePath = manifestPath.slice(
29+
lastNodeModuleIndex === -1
30+
? INNER_NODE_MODULES_SEGMENT.length - 1
31+
: lastNodeModuleIndex + INNER_NODE_MODULES_SEGMENT.length,
32+
);
33+
if (FALSE_POSITIVE_PATHS.has(packageRelativePath)) {
2634
continue;
2735
}
2836

0 commit comments

Comments
 (0)