|
1 |
| -import {ng} from '../../utils/process'; |
2 |
| -import {expectFileToExist} from '../../utils/fs'; |
3 |
| -import {expectToFail} from '../../utils/utils'; |
| 1 | +import * as fs from 'fs'; |
| 2 | +import { expectFileToExist } from '../../utils/fs'; |
| 3 | +import { ng } from '../../utils/process'; |
4 | 4 |
|
| 5 | +export default async function() { |
| 6 | + await ng('build', '--prod', '--output-hashing=none', '--source-map'); |
5 | 7 |
|
6 |
| -export default function() { |
7 |
| - // TODO(architect): Delete this test. It is now in devkit/build-angular. |
| 8 | + await expectFileToExist('dist/test-project/main-es5.js.map'); |
8 | 9 |
|
9 |
| - return ng('build', '--source-map') |
10 |
| - .then(() => expectFileToExist('dist/test-project/main-es5.js.map')) |
| 10 | + const files = fs.readdirSync('./dist/test-project'); |
11 | 11 |
|
12 |
| - .then(() => ng('build', '--source-map', 'false')) |
13 |
| - .then(() => expectToFail(() => expectFileToExist('dist/test-project/main-es5.js.map'))) |
| 12 | + let count = 0; |
| 13 | + for (const file of files) { |
| 14 | + if (!file.endsWith('.js')) { |
| 15 | + continue; |
| 16 | + } |
14 | 17 |
|
15 |
| - .then(() => ng('build', '--optimization', '--output-hashing=none', '--source-map', 'false')) |
16 |
| - .then(() => expectToFail(() => expectFileToExist('dist/test-project/main-es5.js.map'))) |
| 18 | + ++count; |
17 | 19 |
|
18 |
| - .then(() => ng('build', '--optimization', '--output-hashing=none', '--source-map')) |
19 |
| - .then(() => expectFileToExist('dist/test-project/main-es5.js.map')); |
| 20 | + if (!files.includes(file + '.map')) { |
| 21 | + throw new Error('Sourcemap not generated for ' + file); |
| 22 | + } |
| 23 | + |
| 24 | + const content = fs.readFileSync('./dist/test-project/' + file, 'utf8'); |
| 25 | + const lastLineIndex = content.lastIndexOf('\n'); |
| 26 | + const comment = lastLineIndex !== -1 && content.slice(lastLineIndex).trim(); |
| 27 | + if (comment !== `//# sourceMappingURL=${file}.map`) { |
| 28 | + throw new Error('Sourcemap comment not generated for ' + file); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + if (count < 6) { |
| 33 | + throw new Error('Javascript file count is low'); |
| 34 | + } |
20 | 35 | }
|
0 commit comments