Skip to content

Commit 53d8005

Browse files
committed
Fix CI coverage test isolation
1 parent 117ef67 commit 53d8005

3 files changed

Lines changed: 25 additions & 13 deletions

File tree

src/utils/runtime.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ export function detectPackageManager(
119119
cwd = process.cwd(),
120120
env: NodeJS.ProcessEnv = process.env,
121121
): PackageManager {
122+
const lockFiles: Array<[string, PackageManager]> = [
123+
['bun.lock', 'bun'],
124+
['bun.lockb', 'bun'],
125+
['pnpm-lock.yaml', 'pnpm'],
126+
['yarn.lock', 'yarn'],
127+
['package-lock.json', 'npm'],
128+
];
129+
for (const [lockFile, manager] of lockFiles) {
130+
if (fs.existsSync(path.join(cwd, lockFile))) {
131+
return manager;
132+
}
133+
}
134+
122135
const userAgent = env.npm_config_user_agent ?? '';
123136
if (userAgent.startsWith('bun/')) {
124137
return 'bun';
@@ -133,19 +146,6 @@ export function detectPackageManager(
133146
return 'npm';
134147
}
135148

136-
const lockFiles: Array<[string, PackageManager]> = [
137-
['bun.lock', 'bun'],
138-
['bun.lockb', 'bun'],
139-
['pnpm-lock.yaml', 'pnpm'],
140-
['yarn.lock', 'yarn'],
141-
['package-lock.json', 'npm'],
142-
];
143-
for (const [lockFile, manager] of lockFiles) {
144-
if (fs.existsSync(path.join(cwd, lockFile))) {
145-
return manager;
146-
}
147-
}
148-
149149
return isBunRuntime ? 'bun' : 'npm';
150150
}
151151

tests/runtime.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ describe('runtime package manager detection', () => {
4242
expect(detectPackageManager(tempRoot, {})).toBe('pnpm');
4343
});
4444

45+
test('prefers project lockfile over current process user agent', () => {
46+
fs.writeFileSync(path.join(tempRoot, 'package-lock.json'), '');
47+
48+
expect(
49+
detectPackageManager(tempRoot, {
50+
npm_config_user_agent: 'bun/1.3.0 npm/? node/v24',
51+
}),
52+
).toBe('npm');
53+
});
54+
4555
test('builds bun add command for bun projects', () => {
4656
fs.writeFileSync(path.join(tempRoot, 'bun.lock'), '');
4757

tests/versions.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ describe('versionCommands.update package range selection', () => {
251251
});
252252

253253
test('applies minPackageVersion and maxPackageVersion together', async () => {
254+
postSpy.mockClear();
255+
254256
await versionCommands.update({
255257
options: {
256258
appId: '100',

0 commit comments

Comments
 (0)