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
55 lines (53 loc) · 2.13 KB
/
test-assets.ts
File metadata and controls
55 lines (53 loc) · 2.13 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
50
51
52
53
54
55
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 () {
// TODO(architect): Figure out why this test is not working.
return;
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.json)
.then(() => updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.assets = [];
}))
.then(() => expectToFail(() => ng('test', '--watch=false'),
'Should fail because the assets to serve were not in the Angular CLI config'))
// Test passing condition (assets are included)
.then(() => updateJsonFile('angular.json', workspaceJson => {
const appArchitect = workspaceJson.projects['test-project'].architect;
appArchitect.build.options.assets = [
{ 'glob': '**/*', 'input': 'src/assets' },
{ 'glob': 'file.txt' },
];
}))
.then(() => ng('test', '--watch=false'));
}