Skip to content

Commit 0480b8b

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
test: add snapshot material e2e tests
1 parent 7cce3f0 commit 0480b8b

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

tests/legacy-cli/e2e/ng-snapshot/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
"private": true,
44
"dependencies": {
55
"@angular/animations": "github:angular/animations-builds#f003815f2763fd17fc5fe096ee2a7f4bf767c2f1",
6+
"@angular/cdk": "github:angular/cdk-builds#c941e7722542df2cf9e031aa1715f8a2e37b1a80",
67
"@angular/common": "github:angular/common-builds#21e7e8c61555abbb0aa11df48d81e59b125a47f2",
78
"@angular/compiler": "github:angular/compiler-builds#454c14560dd6163a4e3a60a5311111944d820d7c",
89
"@angular/compiler-cli": "github:angular/compiler-cli-builds#672497fd83daa436971f7c6d81ceddbe79d4c463",
910
"@angular/core": "github:angular/core-builds#cfde37d8320664a393012ae9f6aaa41c4ae0dbc5",
1011
"@angular/forms": "github:angular/forms-builds#ecd930c051152cd2502e1a8e01e0db1d4c25ec8a",
1112
"@angular/language-service": "github:angular/language-service-builds#f891789a31917e98d6ff1551d1a30862ab04de8f",
1213
"@angular/localize": "github:angular/localize-builds#2bab28b252fd6a4e4900dae8b13834220020c34a",
14+
"@angular/material": "github:angular/material2-builds#77e9c11620c5d535ecb910daaa0f79f61c055e04",
1315
"@angular/platform-browser": "github:angular/platform-browser-builds#49262e2dfe4f0f68244479de078956e9f875f294",
1416
"@angular/platform-browser-dynamic": "github:angular/platform-browser-dynamic-builds#65583111b5c173f72a97d677b78549576b892595",
1517
"@angular/platform-server": "github:angular/platform-server-builds#cfda848b6b556e838ddfe8b9620369253b4860c0",
1618
"@angular/router": "github:angular/router-builds#f53bbd435141e1514c7495f7b6af99e67e5b55f3"
1719
}
18-
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { getGlobalVariable } from '../../utils/env';
2+
import { ng, silentNpm } from '../../utils/process';
3+
import { updateJsonFile } from '../../utils/project';
4+
5+
const snapshots = require('../../ng-snapshot/package.json');
6+
7+
export default async function () {
8+
await ng('add', '@angular/material');
9+
10+
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
11+
if (isSnapshotBuild) {
12+
await updateJsonFile('package.json', packageJson => {
13+
const dependencies = packageJson['dependencies'];
14+
// Angular material adds dependencies on other Angular packages
15+
// Iterate over all of the packages to update them to the snapshot version.
16+
for (const { name, version } of Object.entries[snapshots.dependencies]) {
17+
if (name in dependencies) {
18+
dependencies[name] = version;
19+
}
20+
}
21+
});
22+
}
23+
24+
await silentNpm('install');
25+
await ng('build', '--prod');
26+
}
Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,57 @@
1+
import { stripIndents } from 'common-tags';
2+
import { getGlobalVariable } from '../../../utils/env';
13
import {
4+
replaceInFile,
25
writeMultipleFiles,
3-
replaceInFile
46
} from '../../../utils/fs';
57
import { ng, silentNpm } from '../../../utils/process';
6-
import { stripIndents } from 'common-tags';
78
import { updateJsonFile } from '../../../utils/project';
89

9-
export default function () {
10+
const snapshots = require('../../../ng-snapshot/package.json');
11+
12+
export default async function () {
1013
// TODO(architect): Delete this test. It is now in devkit/build-angular.
1114

12-
const extensions = ['css', 'scss', 'less', 'styl'];
13-
let promise: Promise<any> = Promise.resolve()
14-
.then(() => silentNpm('install', '@angular/[email protected]'))
15-
.then(() => silentNpm('install', '@angular/[email protected]'));
15+
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
16+
await updateJsonFile('package.json', packageJson => {
17+
const dependencies = packageJson['dependencies'];
18+
dependencies['@angular/material'] = isSnapshotBuild ? snapshots.dependencies['@angular/material'] : 'latest';
19+
dependencies['@angular/cdk'] = isSnapshotBuild ? snapshots.dependencies['@angular/cdk'] : 'latest';
20+
});
21+
22+
await silentNpm('install');
1623

17-
extensions.forEach(ext => {
18-
promise = promise.then(() => {
19-
return writeMultipleFiles({
20-
[`src/styles.${ext}`]: stripIndents`
21-
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
24+
for (const ext of ['css', 'scss', 'less', 'styl']) {
25+
await writeMultipleFiles({
26+
[`src/styles.${ext}`]: stripIndents`
27+
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
28+
`,
29+
[`src/app/app.component.${ext}`]: stripIndents`
30+
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
31+
`,
32+
});
33+
34+
// change files to use preprocessor
35+
await updateJsonFile('angular.json', workspaceJson => {
36+
const appArchitect = workspaceJson.projects['test-project'].architect;
37+
appArchitect.build.options.styles = [
38+
{ input: `src/styles.${ext}` },
39+
];
40+
});
41+
42+
await replaceInFile('src/app/app.component.ts', './app.component.css', `./app.component.${ext}`);
43+
44+
// run build app
45+
await ng('build', '--extract-css', '--source-map');
46+
await writeMultipleFiles({
47+
[`src/styles.${ext}`]: stripIndents`
48+
@import "@angular/material/prebuilt-themes/indigo-pink.css";
2249
`,
23-
[`src/app/app.component.${ext}`]: stripIndents`
24-
@import "~@angular/material/prebuilt-themes/indigo-pink.css";
50+
[`src/app/app.component.${ext}`]: stripIndents`
51+
@import "@angular/material/prebuilt-themes/indigo-pink.css";
2552
`,
26-
})
27-
// change files to use preprocessor
28-
.then(() => updateJsonFile('angular.json', workspaceJson => {
29-
const appArchitect = workspaceJson.projects['test-project'].architect;
30-
appArchitect.build.options.styles = [
31-
{ input: `src/styles.${ext}` },
32-
];
33-
}))
34-
.then(() => replaceInFile('src/app/app.component.ts',
35-
'./app.component.css', `./app.component.${ext}`))
36-
// run build app
37-
.then(() => ng('build', '--extract-css', '--source-map'))
38-
.then(() => writeMultipleFiles({
39-
[`src/styles.${ext}`]: stripIndents`
40-
@import "@angular/material/prebuilt-themes/indigo-pink.css";
41-
`,
42-
[`src/app/app.component.${ext}`]: stripIndents`
43-
@import "@angular/material/prebuilt-themes/indigo-pink.css";
44-
`,
45-
}))
46-
.then(() => ng('build', '--extract-css'));
4753
});
48-
});
4954

50-
return promise;
55+
await ng('build', '--extract-css');
56+
}
5157
}

0 commit comments

Comments
 (0)