Skip to content

Commit 58794f7

Browse files
committed
Added e2e tests for prod build covering style bundling for css, less and sass
1 parent 4c5cdfd commit 58794f7

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

tests/e2e/tests/build/prod-build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default function() {
3434
.then(() => expectFileToExist(join(process.cwd(), 'dist')))
3535
// Check for cache busting hash script src
3636
.then(() => expectFileToMatch('dist/index.html', /main\.[0-9a-f]{20}\.bundle\.js/))
37+
.then(() => expectFileToMatch('dist/index.html', /styles\.[0-9a-f]{20}\.bundle\.css/))
3738

3839
// Check that the process didn't change local files.
3940
.then(() => expectGitToBeClean())

tests/e2e/tests/build/styles/css.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,61 @@
1+
import * as fs from 'fs';
2+
13
import {writeMultipleFiles, expectFileToMatch} from '../../../utils/fs';
24
import {ng} from '../../../utils/process';
5+
import {updateJsonFile} from '../../../utils/project';
36

47

58
export default function() {
69
return writeMultipleFiles({
710
'src/styles.css': `
811
@import './imported-styles.css';
9-
12+
1013
body { background-color: blue; }
1114
`,
1215
'src/imported-styles.css': `
1316
p { background-color: red; }
17+
`,
18+
'src/styles.less': `
19+
.outer {
20+
.inner {
21+
background: #fff;
22+
}
23+
}
24+
`,
25+
'src/styles.scss': `
26+
.upper {
27+
.lower {
28+
background: #def;
29+
}
30+
}
1431
`
1532
})
33+
.then(() => updateJsonFile('angular-cli.json', configJson => {
34+
const app = configJson['apps'][0];
35+
app['styles'].push('src/styles.less');
36+
app['styles'].push('src/styles.scss');
37+
}))
1638
.then(() => ng('build'))
1739
.then(() => expectFileToMatch('dist/styles.bundle.js', 'body { background-color: blue; }'))
18-
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }'));
40+
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }'))
41+
.then(() => expectFileToMatch('dist/styles.bundle.js', /.outer.*.inner.*background:\s*#[fF]+/))
42+
.then(() => expectFileToMatch('dist/styles.bundle.js', /.upper.*.lower.*background.*#def/))
43+
44+
.then(() => ng('build', '--prod'))
45+
.then(() => new Promise<string>((resolve, reject) => {
46+
fs.readdir('dist', (err, files) => {
47+
if (err) {
48+
reject(err);
49+
} else {
50+
const styles = files.find(file => /styles\.[0-9a-f]{20}\.bundle\.css/.test(file));
51+
resolve(styles);
52+
}
53+
});
54+
}))
55+
.then((styles) =>
56+
expectFileToMatch(styles, 'body { background-color: blue; }')
57+
.then(() => expectFileToMatch(styles, 'p { background-color: red; }')
58+
.then(() => expectFileToMatch(styles, /.outer.*.inner.*background:\s*#[fF]+/))
59+
.then(() => expectFileToMatch(styles, /.upper.*.lower.*background.*#def/)))
60+
);
1961
}

0 commit comments

Comments
 (0)