|
| 1 | +import { expectFileToExist } from '../../utils/fs'; |
| 2 | +import { ng } from '../../utils/process'; |
| 3 | +import { updateJsonFile } from '../../utils/project'; |
| 4 | +import { expectToFail } from '../../utils/utils'; |
| 5 | + |
| 6 | +export default async function () { |
| 7 | + await updateJsonFile('angular.json', workspaceJson => { |
| 8 | + const appArchitect = workspaceJson.projects['test-project'].architect; |
| 9 | + // These are the default options, that we'll overwrite in subsequent configs. |
| 10 | + // extractCss defaults to false |
| 11 | + // sourceMap defaults to true |
| 12 | + appArchitect['options'] = { |
| 13 | + outputPath: 'dist/latest-project', |
| 14 | + index: 'src/index.html', |
| 15 | + main: 'src/main.ts', |
| 16 | + polyfills: 'src/polyfills.ts', |
| 17 | + tsConfig: 'tsconfig.app.json', |
| 18 | + assets: [ |
| 19 | + 'src/favicon.ico', |
| 20 | + 'src/assets', |
| 21 | + ], |
| 22 | + 'styles': [ |
| 23 | + 'src/styles.css', |
| 24 | + ], |
| 25 | + 'scripts': [], |
| 26 | + }; |
| 27 | + const browserConfigs = appArchitect['build'].configurations; |
| 28 | + browserConfigs['production'] = { |
| 29 | + extractCss: true, |
| 30 | + }; |
| 31 | + browserConfigs['one'] = { |
| 32 | + assets: [], |
| 33 | + }; |
| 34 | + browserConfigs['two'] = { |
| 35 | + sourceMap: false, |
| 36 | + }; |
| 37 | + browserConfigs['three'] = { |
| 38 | + extractCss: false, // Defaults to false when not set. |
| 39 | + }; |
| 40 | + }); |
| 41 | + |
| 42 | + // Test the base configuration. |
| 43 | + await ng('build'); |
| 44 | + await expectFileToExist('dist/test-project/favicon.ico'); |
| 45 | + await expectFileToExist('dist/test-project/main-es2015.js.map'); |
| 46 | + await expectFileToExist('dist/test-project/styles-es2015.js'); |
| 47 | + await expectFileToExist('dist/test-project/vendor-es2015.js'); |
| 48 | + // Test that --prod extracts css. |
| 49 | + await ng('build', '--prod'); |
| 50 | + await expectFileToExist('dist/test-project/styles.css'); |
| 51 | + // But using a config overrides prod. |
| 52 | + await ng('build', '--prod', '--configuration=three'); |
| 53 | + await expectFileToExist('dist/test-project/styles-es2015.js'); |
| 54 | + await expectToFail(() => expectFileToExist('dist/test-project/styles.css')); |
| 55 | + // Use two configurations. |
| 56 | + await ng('build', '--configuration=one,two', '--vendor-chunk=false'); |
| 57 | + await expectToFail(() => expectFileToExist('dist/test-project/favicon.ico')); |
| 58 | + await expectToFail(() => expectFileToExist('dist/test-project/main-es2015.js.map')); |
| 59 | + // Use two configurations and two overrides, one of which overrides a config. |
| 60 | + await ng('build', '--configuration=one,two', '--vendor-chunk=false', '--sourceMap=true'); |
| 61 | + await expectToFail(() => expectFileToExist('dist/test-project/favicon.ico')); |
| 62 | + await expectFileToExist('dist/test-project/main-es2015.js.map'); |
| 63 | + await expectToFail(() => expectFileToExist('dist/test-project/vendor-es2015.js')); |
| 64 | + // Use two configurations and a override, and prod at the end. |
| 65 | + await ng('build', '--configuration=one,two', '--vendor-chunk=false', '--prod'); |
| 66 | + await expectToFail(() => expectFileToExist('dist/test-project/favicon.ico')); |
| 67 | + await expectToFail(() => expectFileToExist('dist/test-project/main-es2015.js.map')); |
| 68 | + await expectToFail(() => expectFileToExist('dist/test-project/vendor-es2015.js')); |
| 69 | + await expectFileToExist('dist/test-project/styles-es2015.js'); |
| 70 | + await expectToFail(() => expectFileToExist('dist/test-project/styles.css')); |
| 71 | +} |
0 commit comments