Skip to content

Commit 6918431

Browse files
authored
test: adding fixtures for lockfiles to support --frozen-lockfile (yarn, pnpm) and ci (npm) (#8899)
Sometimes `master` branch (and all subsequent PRs) gets broken simply due to a fixture dependency's sub-dependency changes/updates/redeploys. TLDR; Solution: - Leverage `--frozen-lockfile` and `npm ci` with lockfile fixtures Implementation: - This PR introduces a new fixture directory containing lockfiles: `test/fixtures/lockfiles/<test file name>/<test name>.txt` - If a test has `isInstallDepsBefore: true`, then we reuse existing logic flow to check if there's a lockfile fixture already existing, if so, copy it to the temp `projectDir`. Install deps with arg `--frozen-lockfile` to use pinned deps specific to each test. - npm: `npm ci` - yarn: `yarn install --frozen-lockfile` - pnpm `pnpm install --frozen-lockfile` - If a test has no lockfile and deps are installed before running the test, then write the lockfile at the end of the `npm install` (or yarn, or pnpm) phase of the process. - Adds `UPDATE_LOCKFILE_FIXTURES` as a way to re-save the lockfile (such as when test dependencies are changed) - Adds `installOptions` containing `cmd`, `installArgs`, and `lockfile` properties to each Node Module Collector class for easy usage specific to each test
1 parent 0425af4 commit 6918431

36 files changed

+10879
-127
lines changed

.changeset/wise-seas-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
test: adding fixtures for lockfiles to support `--frozen-lockfile` (yarn, pnpm) and `ci` (npm)

packages/app-builder-lib/src/node-module-collector/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function isPnpmProjectHoisted(rootDir: string) {
1212
return lines["node-linker"] === "hoisted"
1313
}
1414

15-
async function getCollectorByPackageManager(rootDir: string) {
15+
export async function getCollectorByPackageManager(rootDir: string) {
1616
const manager: PM = await detect({ cwd: rootDir })
1717
switch (manager) {
1818
case "pnpm":

packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export abstract class NodeModulesCollector<T extends Dependency<T, OptionalsType
2828
return this.nodeModules
2929
}
3030

31+
public abstract readonly installOptions: Promise<{
32+
cmd: string
33+
args: string[]
34+
lockfile: string
35+
}>
3136
protected abstract readonly pmCommand: Lazy<string>
3237
protected abstract getArgs(): string[]
3338
protected abstract parseDependenciesTree(jsonBlob: string): T

packages/app-builder-lib/src/node-module-collector/npmNodeModulesCollector.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export class NpmNodeModulesCollector extends NodeModulesCollector<NpmDependency,
88
super(rootDir)
99
}
1010

11-
protected readonly pmCommand = new Lazy<string>(() => Promise.resolve(process.platform === "win32" ? "npm.cmd" : "npm"))
11+
public readonly pmCommand = new Lazy<string>(() => Promise.resolve(process.platform === "win32" ? "npm.cmd" : "npm"))
12+
public readonly installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: ["ci"], lockfile: "package-lock.json" }))
1213

1314
protected getArgs(): string[] {
1415
return ["list", "-a", "--include", "prod", "--include", "optional", "--omit", "dev", "--json", "--long", "--silent"]

packages/app-builder-lib/src/node-module-collector/pnpmNodeModulesCollector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class PnpmNodeModulesCollector extends NodeModulesCollector<PnpmDependenc
2222
})
2323

2424
protected readonly pmCommand: Lazy<string> = PnpmNodeModulesCollector.pmCommand
25+
public readonly installOptions = this.pmCommand.value.then(cmd => ({ cmd, args: ["install", "--frozen-lockfile"], lockfile: "pnpm-lock.yaml" }))
2526

2627
protected getArgs(): string[] {
2728
return ["list", "--prod", "--json", "--depth", "Infinity"]

packages/app-builder-lib/src/node-module-collector/yarnNodeModulesCollector.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ export class YarnNodeModulesCollector extends NpmNodeModulesCollector {
44
constructor(rootDir: string) {
55
super(rootDir)
66
}
7+
8+
public readonly installOptions = Promise.resolve({
9+
cmd: process.platform === "win32" ? "yarn.cmd" : "yarn",
10+
args: ["install", "--frozen-lockfile"],
11+
lockfile: "yarn.lock",
12+
})
713
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)