Skip to content

Commit

Permalink
test(@angular/cli): extract version specifier e2e test
Browse files Browse the repository at this point in the history
(cherry picked from commit d081974)
  • Loading branch information
alan-agius4 authored and clydin committed Nov 12, 2020
1 parent 0068783 commit b70116e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
20 changes: 0 additions & 20 deletions tests/legacy-cli/e2e/tests/commands/add/add-material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,7 @@ export default async function () {
await ng('add', `@angular/material${tag}`, '--theme', 'custom', '--verbose');
await expectFileToMatch('package.json', /@angular\/material/);

const output1 = await ng('add', '@angular/material');
if (!output1.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation was not skipped');
}

// Clean up existing cdk package
// Not doing so can cause adding material to fail if an incompatible cdk is present
await uninstallPackage('@angular/cdk');

const output2 = await ng('add', '@angular/material@latest');
if (output2.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation should not have been skipped');
}

const output3 = await ng('add', '@angular/[email protected]');
if (output3.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation should not have been skipped');
}

const output4 = await ng('add', '@angular/material@8');
if (!output4.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation was not skipped');
}
}
22 changes: 11 additions & 11 deletions tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { expectFileToExist, readFile, rimraf } from '../../../utils/fs';
import { ng } from '../../../utils/process';

export default async function () {
// forcibly remove in case another test doesn't clean itself up
await rimraf('node_modules/@angular/pwa');
await ng('add', '@angular/pwa');
await expectFileToExist(join(process.cwd(), 'src/manifest.webmanifest'));
// forcibly remove in case another test doesn't clean itself up
await rimraf('node_modules/@angular/pwa');
await ng('add', '@angular/pwa');
await expectFileToExist(join(process.cwd(), 'src/manifest.webmanifest'));

// Angular PWA doesn't install as a dependency
const { dependencies, devDependencies } = JSON.parse(await readFile(join(process.cwd(), 'package.json')));
const hasPWADep = Object.keys({ ...dependencies, ...devDependencies })
.some(d => d === '@angular/pwa');
if (hasPWADep) {
throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`);
}
// Angular PWA doesn't install as a dependency
const { dependencies, devDependencies } = JSON.parse(await readFile(join(process.cwd(), 'package.json')));
const hasPWADep = Object.keys({ ...dependencies, ...devDependencies })
.some(d => d === '@angular/pwa');
if (hasPWADep) {
throw new Error(`Expected 'package.json' not to contain a dependency on '@angular/pwa'.`);
}
}
37 changes: 37 additions & 0 deletions tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expectFileToMatch, rimraf } from '../../../utils/fs';
import { uninstallPackage } from '../../../utils/packages';
import { ng } from '../../../utils/process';
import { isPrereleaseCli } from '../../../utils/project';


export default async function () {
// forcibly remove in case another test doesn't clean itself up.
await rimraf('node_modules/@angular/localize');

const tag = await isPrereleaseCli() ? '@next' : '';

await ng('add', `@angular/localize${tag}`);
await expectFileToMatch('package.json', /@angular\/localize/);

const output1 = await ng('add', '@angular/localize');
if (!output1.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation was not skipped');
}

const output2 = await ng('add', '@angular/localize@latest');
if (output2.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation should not have been skipped');
}

const output3 = await ng('add', '@angular/[email protected]');
if (output3.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation should not have been skipped');
}

const output4 = await ng('add', '@angular/localize@10');
if (!output4.stdout.includes('Skipping installation: Package already installed')) {
throw new Error('Installation was not skipped');
}

await uninstallPackage('@angular/localize');
}

0 comments on commit b70116e

Please sign in to comment.