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