Skip to content

Commit 8dbf5af

Browse files
clydindgp1130
authored andcommitted
test: update E2E tests to support using npm 7+
Several tests that perform package actions during the test have been updated to function correctly when used with npm. npm 7+ performs additional resolution on peer dependencies which can result in failures during testing. The following tests have been updated: * `build/material` - This test contained an actual error in that it was installing the `latest` version of `@angular/material-moment-adapter` when testing prereleases even though it should have been installing the `next` tag instead. * `build/styles/tailwind-v2` - This test had to be reordered due to npm 7+ keeping the installed `tailwindcss` peer dependency in a non-hoisted location even after the project level package was uninstalled. The ordering also uncovered a Webpack cache key creation defect wherein the cache key does not account for the presence of `tailwindcss`. Until this is corrected, the test temporarily disables caching. * `commands/add/version-specifier` - This test intentionally attempts to install package versions that do not meet peer dependency requirements to ensure that the `ng add` command correctly notifies the user. To allow for this to occur, the npm `force` option is used to prevent the package install aspects of the command from failing.
1 parent 0fc1c33 commit 8dbf5af

File tree

4 files changed

+44
-34
lines changed

4 files changed

+44
-34
lines changed

tests/legacy-cli/e2e/tests/build/material.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default async function () {
2828

2929
await installWorkspacePackages();
3030
} else {
31-
await installPackage('@angular/material-moment-adapter');
31+
await installPackage(`@angular/material-moment-adapter${tag}`);
3232
}
3333

3434
await installPackage('moment');

tests/legacy-cli/e2e/tests/build/styles/tailwind-v2.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@ import { ng, silentExec } from '../../../utils/process';
44
import { expectToFail } from '../../../utils/utils';
55

66
export default async function () {
7-
// Install Tailwind
8-
await installPackage('tailwindcss@2');
7+
// Temporarily turn off caching until the build cache accounts for the presence of tailwind
8+
// and its configuration file. Otherwise cached builds without tailwind will cause test failures.
9+
await ng('cache', 'off');
910

1011
// Create configuration file
11-
await silentExec('npx', 'tailwindcss', 'init');
12+
await silentExec('npx', 'tailwindcss@2', 'init');
1213

1314
// Add Tailwind directives to a component style
1415
await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;');
1516

1617
// Add Tailwind directives to a global style
1718
await writeFile('src/styles.css', '@tailwind base; @tailwind components;');
1819

20+
// Ensure installation warning is present
21+
const { stderr } = await ng('build', '--configuration=development');
22+
if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
23+
throw new Error(`Expected tailwind installation warning. STDERR:\n${stderr}`);
24+
}
25+
26+
// Tailwind directives should be unprocessed with missing package
27+
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
28+
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
29+
30+
// Install Tailwind
31+
await installPackage('tailwindcss@2');
32+
1933
// Build should succeed and process Tailwind directives
2034
await ng('build', '--configuration=development');
2135

@@ -37,19 +51,6 @@ export default async function () {
3751
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
3852
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
3953

40-
// Recreate configuration file
41-
await silentExec('npx', 'tailwindcss', 'init');
42-
4354
// Uninstall Tailwind
4455
await uninstallPackage('tailwindcss');
45-
46-
// Ensure installation warning is present
47-
const { stderr } = await ng('build', '--configuration=development');
48-
if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
49-
throw new Error('Expected tailwind installation warning');
50-
}
51-
52-
// Tailwind directives should be unprocessed with missing package
53-
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
54-
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
5556
}

tests/legacy-cli/e2e/tests/build/styles/tailwind-v3.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,32 @@ import { ng, silentExec } from '../../../utils/process';
44
import { expectToFail } from '../../../utils/utils';
55

66
export default async function () {
7-
// Install Tailwind
8-
await installPackage('tailwindcss@3');
7+
// Temporarily turn off caching until the build cache accounts for the presence of tailwind
8+
// and its configuration file. Otherwise cached builds without tailwind will cause test failures.
9+
await ng('cache', 'off');
910

1011
// Create configuration file
11-
await silentExec('npx', 'tailwindcss', 'init');
12+
await silentExec('npx', 'tailwindcss@3', 'init');
1213

1314
// Add Tailwind directives to a component style
1415
await writeFile('src/app/app.component.css', '@tailwind base; @tailwind components;');
1516

1617
// Add Tailwind directives to a global style
1718
await writeFile('src/styles.css', '@tailwind base; @tailwind components;');
1819

20+
// Ensure installation warning is present
21+
const { stderr } = await ng('build', '--configuration=development');
22+
if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
23+
throw new Error('Expected tailwind installation warning');
24+
}
25+
26+
// Tailwind directives should be unprocessed with missing package
27+
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
28+
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
29+
30+
// Install Tailwind
31+
await installPackage('tailwindcss@3');
32+
1933
// Build should succeed and process Tailwind directives
2034
await ng('build', '--configuration=development');
2135

@@ -37,19 +51,6 @@ export default async function () {
3751
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
3852
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
3953

40-
// Recreate configuration file
41-
await silentExec('npx', 'tailwindcss', 'init');
42-
4354
// Uninstall Tailwind
4455
await uninstallPackage('tailwindcss');
45-
46-
// Ensure installation warning is present
47-
const { stderr } = await ng('build', '--configuration=development');
48-
if (!stderr.includes("To enable Tailwind CSS, please install the 'tailwindcss' package.")) {
49-
throw new Error('Expected tailwind installation warning');
50-
}
51-
52-
// Tailwind directives should be unprocessed with missing package
53-
await expectFileToMatch('dist/test-project/styles.css', '@tailwind base; @tailwind components;');
54-
await expectFileToMatch('dist/test-project/main.js', '@tailwind base; @tailwind components;');
5556
}

tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { appendFile } from 'fs/promises';
12
import { expectFileToMatch, rimraf } from '../../../utils/fs';
2-
import { uninstallPackage } from '../../../utils/packages';
3+
import { getActivePackageManager, uninstallPackage } from '../../../utils/packages';
34
import { ng } from '../../../utils/process';
45
import { isPrereleaseCli } from '../../../utils/project';
56

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

11+
// If using npm, enable the force option to allow testing the output behavior of the
12+
// `ng add` command itself and not the behavior of npm which may otherwise fail depending
13+
// on the npm version in use and the version specifier supplied in each test.
14+
if (getActivePackageManager() === 'npm') {
15+
appendFile('.npmrc', '\nforce=true\n');
16+
}
17+
1018
const tag = (await isPrereleaseCli()) ? '@next' : '';
1119

1220
await ng('add', `@angular/localize${tag}`, '--skip-confirmation');

0 commit comments

Comments
 (0)