|
1 |
| -import {ng} from '../../utils/process'; |
| 1 | +import { writeMultipleFiles } from '../../utils/fs'; |
| 2 | +import { ng } from '../../utils/process'; |
| 3 | +import { updateJsonFile } from '../../utils/project'; |
| 4 | +import { expectToFail } from '../../utils/utils'; |
| 5 | +import { stripIndent } from 'common-tags'; |
2 | 6 |
|
3 | 7 |
|
4 |
| -export default function() { |
5 |
| - // make sure both --watch=false and --single-run work |
| 8 | +export default function () { |
| 9 | + // Each test function returns PromiseLike<Something_Different>, |
| 10 | + // which would throw normally |
| 11 | + // but resolve() normalizes this to <any> from the start |
| 12 | + return Promise.resolve() |
| 13 | + .then(() => testWatchFalseAndSingleRun()) |
| 14 | + .then(() => testAssetsAreServed()); |
| 15 | +} |
| 16 | + |
| 17 | +// Make sure both --watch=false and --single-run work |
| 18 | +function testWatchFalseAndSingleRun() { |
6 | 19 | return ng('test', '--single-run')
|
7 | 20 | .then(() => ng('test', '--watch=false'));
|
8 | 21 | }
|
| 22 | + |
| 23 | +// Make sure asset files are served |
| 24 | +function testAssetsAreServed() { |
| 25 | + return Promise.resolve() |
| 26 | + .then(() => writeMultipleFiles({ |
| 27 | + 'src/assets/file.txt': 'assets-folder-content', |
| 28 | + 'src/file.txt': 'file-content', |
| 29 | + // Not using `async()` in tests as it seemed to swallow `fetch()` errors |
| 30 | + 'src/app/app.component.spec.ts': stripIndent` |
| 31 | + describe('Test Runner', () => { |
| 32 | + const fetch = global['fetch']; |
| 33 | + it('should serve files in assets folder', (done) => { |
| 34 | + fetch('/assets/file.txt') |
| 35 | + .then(response => response.text()) |
| 36 | + .then(fileText => { |
| 37 | + expect(fileText).toMatch('assets-folder-content'); |
| 38 | + done(); |
| 39 | + }); |
| 40 | + }); |
| 41 | + it('should serve files explicitly added to assets array', (done) => { |
| 42 | + fetch('/file.txt') |
| 43 | + .then(response => response.text()) |
| 44 | + .then(fileText => { |
| 45 | + expect(fileText).toMatch('file-content'); |
| 46 | + done(); |
| 47 | + }); |
| 48 | + }); |
| 49 | + }); |
| 50 | + ` |
| 51 | + })) |
| 52 | + // Test failure condition (no assets in angular-cli.json) |
| 53 | + .then(() => updateJsonFile('angular-cli.json', configJson => { |
| 54 | + const app = configJson['apps'][0]; |
| 55 | + app['assets'] = []; |
| 56 | + })) |
| 57 | + .then(() => expectToFail(() => ng('test', '--single-run'), |
| 58 | + 'Should fail because the assets to serve were not in the angular-cli config')) |
| 59 | + // Test passing condition (assets are included) |
| 60 | + .then(() => updateJsonFile('angular-cli.json', configJson => { |
| 61 | + const app = configJson['apps'][0]; |
| 62 | + app['assets'] = ['assets', 'file.txt']; |
| 63 | + })) |
| 64 | + .then(() => ng('test', '--single-run')); |
| 65 | +} |
0 commit comments