Skip to content

Commit deedd00

Browse files
committed
update test
1 parent 1292545 commit deedd00

File tree

1 file changed

+30
-44
lines changed

1 file changed

+30
-44
lines changed

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

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,9 @@ describe('constructs version', () => {
14251425
});
14261426

14271427
describe('validate CLI init options', () => {
1428+
const cdkBin = path.join(__dirname, '..', '..', 'bin', 'cdk');
1429+
const commonEnv = { ...process.env, CDK_DISABLE_VERSION_CHECK: '1', CI: 'true', FORCE_COLOR: '0' };
1430+
14281431
test.each([
14291432
'python',
14301433
'java',
@@ -1433,23 +1436,17 @@ describe('constructs version', () => {
14331436
'fsharp',
14341437
])('warns when package-manager option is specified for non-JS language=%s', async (language) => {
14351438
await withTempDir(async (workDir) => {
1436-
const warnSpy = jest.spyOn(ioHelper.defaults, 'warn');
1437-
1438-
await cliInit({
1439-
ioHelper,
1440-
type: 'app',
1441-
language,
1442-
packageManager: 'npm',
1443-
canUseNetwork: false,
1444-
generateOnly: true,
1445-
workDir,
1446-
});
1447-
1448-
expect(warnSpy).toHaveBeenCalledWith(
1449-
expect.stringContaining('--package-manager option is only applicable for JavaScript and TypeScript projects'),
1439+
const output = child_process.execSync(
1440+
`node ${cdkBin} init app --language ${language} --package-manager npm --generate-only`,
1441+
{
1442+
cwd: workDir,
1443+
env: commonEnv,
1444+
encoding: 'utf-8',
1445+
},
14501446
);
14511447

1452-
warnSpy.mockRestore();
1448+
expect(output).toContain('--package-manager option is only applicable for JavaScript and TypeScript projects');
1449+
expect(output).toContain(`Applying project template app for ${language}`);
14531450
});
14541451
});
14551452

@@ -1461,22 +1458,17 @@ describe('constructs version', () => {
14611458
'fsharp',
14621459
])('does not warn when package-manager option is omitted for non-JS language=%s', async (language) => {
14631460
await withTempDir(async (workDir) => {
1464-
const warnSpy = jest.spyOn(ioHelper.defaults, 'warn');
1465-
1466-
await cliInit({
1467-
ioHelper,
1468-
type: 'app',
1469-
language,
1470-
canUseNetwork: false,
1471-
generateOnly: true,
1472-
workDir,
1473-
});
1474-
1475-
expect(warnSpy).not.toHaveBeenCalledWith(
1476-
expect.stringContaining('--package-manager option is only applicable for JavaScript and TypeScript projects'),
1461+
const output = child_process.execSync(
1462+
`node ${cdkBin} init app --language ${language} --generate-only`,
1463+
{
1464+
cwd: workDir,
1465+
env: commonEnv,
1466+
encoding: 'utf-8',
1467+
},
14771468
);
14781469

1479-
warnSpy.mockRestore();
1470+
expect(output).not.toContain('--package-manager option is only applicable for JavaScript and TypeScript projects');
1471+
expect(output).toContain(`Applying project template app for ${language}`);
14801472
});
14811473
});
14821474

@@ -1485,23 +1477,17 @@ describe('constructs version', () => {
14851477
'javascript',
14861478
])('does not warn when package-manager option is specified for language=%s', async (language) => {
14871479
await withTempDir(async (workDir) => {
1488-
const warnSpy = jest.spyOn(ioHelper.defaults, 'warn');
1489-
1490-
await cliInit({
1491-
ioHelper,
1492-
type: 'app',
1493-
language,
1494-
packageManager: 'npm',
1495-
canUseNetwork: false,
1496-
generateOnly: true,
1497-
workDir,
1498-
});
1499-
1500-
expect(warnSpy).not.toHaveBeenCalledWith(
1501-
expect.stringContaining('--package-manager option is only applicable for JavaScript and TypeScript projects'),
1480+
const output = child_process.execSync(
1481+
`node ${cdkBin} init app --language ${language} --generate-only`,
1482+
{
1483+
cwd: workDir,
1484+
env: commonEnv,
1485+
encoding: 'utf-8',
1486+
},
15021487
);
15031488

1504-
warnSpy.mockRestore();
1489+
expect(output).not.toContain('--package-manager option is only applicable for JavaScript and TypeScript projects');
1490+
expect(output).toContain(`Applying project template app for ${language}`);
15051491
});
15061492
});
15071493
});

0 commit comments

Comments
 (0)