|
| 1 | +import * as fs from 'fs'; |
| 2 | + |
1 | 3 | import {writeMultipleFiles, expectFileToMatch} from '../../../utils/fs';
|
2 | 4 | import {ng} from '../../../utils/process';
|
| 5 | +import {updateJsonFile} from '../../../utils/project'; |
3 | 6 |
|
4 | 7 |
|
5 | 8 | export default function() {
|
6 | 9 | return writeMultipleFiles({
|
7 | 10 | 'src/styles.css': `
|
8 | 11 | @import './imported-styles.css';
|
9 |
| - |
| 12 | +
|
10 | 13 | body { background-color: blue; }
|
11 | 14 | `,
|
12 | 15 | 'src/imported-styles.css': `
|
13 | 16 | 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 | + } |
14 | 31 | `
|
15 | 32 | })
|
| 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 | + })) |
16 | 38 | .then(() => ng('build'))
|
17 | 39 | .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 | + ); |
19 | 61 | }
|
0 commit comments