Skip to content

Commit 58d5af4

Browse files
committed
test: update
1 parent 60297e6 commit 58d5af4

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

packages/aws-cdk/test/commands/init.test.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,14 +1341,28 @@ describe('constructs version', () => {
13411341
});
13421342

13431343
describe('package-manager option', () => {
1344+
let spawnSpy: jest.SpyInstance;
1345+
1346+
beforeEach(() => {
1347+
// Mock child_process.spawn to track which package manager is called
1348+
spawnSpy = jest.spyOn(require('child_process'), 'spawn').mockImplementation(() => ({
1349+
stdout: { on: jest.fn() },
1350+
stderr: { on: jest.fn() },
1351+
}));
1352+
});
1353+
1354+
afterEach(() => {
1355+
spawnSpy.mockRestore();
1356+
});
1357+
13441358
test.each([
1345-
['typescript', 'npm', 'package-lock.json'],
1346-
['typescript', 'yarn', 'yarn.lock'],
1347-
['typescript', 'pnpm', 'pnpm-lock.yaml'],
1348-
['javascript', 'npm', 'package-lock.json'],
1349-
['javascript', 'yarn', 'yarn.lock'],
1350-
['javascript', 'pnpm', 'pnpm-lock.yaml'],
1351-
])('creates %s project with %s (verifying %s)', async (language, packageManager, lockFile) => {
1359+
{ language: 'typescript', packageManager: 'npm' },
1360+
{ language: 'typescript', packageManager: 'yarn' },
1361+
{ language: 'typescript', packageManager: 'pnpm' },
1362+
{ language: 'javascript', packageManager: 'npm' },
1363+
{ language: 'javascript', packageManager: 'yarn' },
1364+
{ language: 'javascript', packageManager: 'pnpm' },
1365+
])('uses $packageManager for $language project', async ({ language, packageManager }) => {
13521366
await withTempDir(async (workDir) => {
13531367
await cliInit({
13541368
ioHelper,
@@ -1360,8 +1374,10 @@ describe('constructs version', () => {
13601374
workDir,
13611375
});
13621376

1363-
expect(await fs.pathExists(path.join(workDir, lockFile))).toBeTruthy();
1364-
expect(await fs.pathExists(path.join(workDir, 'package.json'))).toBeTruthy();
1377+
const installCalls = spawnSpy.mock.calls.filter(
1378+
([cmd, args]) => cmd === packageManager && args.includes('install'),
1379+
);
1380+
expect(installCalls.length).toBeGreaterThan(0);
13651381
});
13661382
});
13671383

0 commit comments

Comments
 (0)