forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-assets.ts
More file actions
49 lines (48 loc) · 1.89 KB
/
test-assets.ts
File metadata and controls
49 lines (48 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { writeMultipleFiles } from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { expectToFail } from '../../utils/utils';
import { stripIndent } from 'common-tags';
// Make sure asset files are served
export default function () {
return Promise.resolve()
.then(() => writeMultipleFiles({
'src/assets/file.txt': 'assets-folder-content',
'src/file.txt': 'file-content',
// Not using `async()` in tests as it seemed to swallow `fetch()` errors
'src/app/app.component.spec.ts': stripIndent`
describe('Test Runner', () => {
const fetch = global['fetch'];
it('should serve files in assets folder', (done) => {
fetch('/assets/file.txt')
.then(response => response.text())
.then(fileText => {
expect(fileText).toMatch('assets-folder-content');
done();
});
});
it('should serve files explicitly added to assets array', (done) => {
fetch('/file.txt')
.then(response => response.text())
.then(fileText => {
expect(fileText).toMatch('file-content');
done();
});
});
});
`
}))
// Test failure condition (no assets in angular-cli.json)
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['assets'] = [];
}))
.then(() => expectToFail(() => ng('test', '--single-run'),
'Should fail because the assets to serve were not in the Angular CLI config'))
// Test passing condition (assets are included)
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['assets'] = ['assets', 'file.txt'];
}))
.then(() => ng('test', '--single-run'));
}