|
| 1 | +import { |
| 2 | + writeMultipleFiles, |
| 3 | + deleteFile, |
| 4 | + expectFileToMatch, |
| 5 | + replaceInFile |
| 6 | +} from '../../../utils/fs'; |
| 7 | +import { expectToFail } from '../../../utils/utils'; |
| 8 | +import { ng } from '../../../utils/process'; |
| 9 | +import { stripIndents } from 'common-tags'; |
| 10 | +import { updateJsonFile } from '../../../utils/project'; |
| 11 | + |
| 12 | +export default function () { |
| 13 | + const extensions = ['css', 'scss', 'less', 'styl']; |
| 14 | + let promise = Promise.resolve(); |
| 15 | + |
| 16 | + extensions.forEach(ext => { |
| 17 | + promise = promise.then(() => { |
| 18 | + return writeMultipleFiles({ |
| 19 | + [`src/styles.${ext}`]: stripIndents` |
| 20 | + @import './imported-styles.${ext}'; |
| 21 | + body { background-color: #00f; } |
| 22 | + `, |
| 23 | + [`src/imported-styles.${ext}`]: stripIndents` |
| 24 | + p { background-color: #f00; } |
| 25 | + `, |
| 26 | + [`src/app/app.component.${ext}`]: stripIndents` |
| 27 | + @import './imported-component-styles.${ext}'; |
| 28 | + .outer { |
| 29 | + .inner { |
| 30 | + background: #fff; |
| 31 | + } |
| 32 | + } |
| 33 | + `, |
| 34 | + [`src/imported-component-styles.${ext}`]: stripIndents` |
| 35 | + h1 { background: #000; } |
| 36 | + `}) |
| 37 | + .then(() => deleteFile('src/app/app.component.css')) |
| 38 | + // change files to use preprocessor |
| 39 | + .then(() => updateJsonFile('angular-cli.json', configJson => { |
| 40 | + const app = configJson['apps'][0]; |
| 41 | + app['styles'] = [`styles.${ext}`]; |
| 42 | + })) |
| 43 | + .then(() => replaceInFile('src/app/app.component.ts', |
| 44 | + './app.component.css', `./app.component.${ext}`)) |
| 45 | + // run build app |
| 46 | + .then(() => ng('build', '--extract-css', '--sourcemap')) |
| 47 | + // verify global styles |
| 48 | + .then(() => expectFileToMatch('dist/styles.bundle.css', |
| 49 | + /body\s*{\s*background-color: #00f;\s*}/)) |
| 50 | + .then(() => expectFileToMatch('dist/styles.bundle.css', |
| 51 | + /p\s*{\s*background-color: #f00;\s*}/)) |
| 52 | + // verify global styles sourcemap |
| 53 | + .then(() => expectToFail(() => |
| 54 | + expectFileToMatch('dist/styles.bundle.css', '"mappings":""'))) |
| 55 | + // verify component styles |
| 56 | + .then(() => expectFileToMatch('dist/main.bundle.js', |
| 57 | + /.outer.*.inner.*background:\s*#[fF]+/)) |
| 58 | + .then(() => expectFileToMatch('dist/main.bundle.js', |
| 59 | + /h1.*background:\s*#000+/)) |
| 60 | + // change files back |
| 61 | + .then(() => updateJsonFile('angular-cli.json', configJson => { |
| 62 | + const app = configJson['apps'][0]; |
| 63 | + app['styles'] = ['styles.css']; |
| 64 | + })) |
| 65 | + .then(() => replaceInFile('src/app/app.component.ts', |
| 66 | + `./app.component.${ext}`, './app.component.css')); |
| 67 | + }); |
| 68 | + }); |
| 69 | + |
| 70 | + return promise; |
| 71 | +} |
0 commit comments