-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathresources-output-path_spec.ts
75 lines (59 loc) · 2.66 KB
/
resources-output-path_spec.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
// tslint:disable:no-big-function
import { Architect } from '@angular-devkit/architect';
import { ServerBuilderOutput } from '@angular-devkit/build-angular';
import { join, normalize, virtualFs } from '@angular-devkit/core';
import { createArchitect, host } from '../test-utils';
describe('Server Builder styles resources output path (No emit assets)', () => {
function writeFiles() {
host.copyFile('src/spectrum.png', './src/assets/component-img-relative.png');
host.copyFile('src/spectrum.png', './src/assets/component-img-absolute.png');
host.writeMultipleFiles({
'src/app/app.component.css': `
h3 { background: url('/assets/component-img-absolute.png'); }
h4 { background: url('../assets/component-img-relative.png'); }
`,
});
}
const target = { project: 'app', target: 'server' };
let architect: Architect;
const outputPath = normalize('dist-server');
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it(`supports resourcesOutputPath in resource urls`, async () => {
writeFiles();
const overrides = {
resourcesOutputPath: 'out-assets',
};
const run = await architect.scheduleTarget(target, overrides);
const output = await run.result as ServerBuilderOutput;
expect(output.success).toBe(true);
const fileName = join(outputPath, 'main.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toContain(`url('/assets/component-img-absolute.png')`);
expect(content).toContain(`url('out-assets/component-img-relative.png')`);
expect(host.scopedSync().exists(normalize(`${outputPath}/out-assets/component-img-relative.png`)))
.toBe(false);
});
it(`supports blank resourcesOutputPath`, async () => {
writeFiles();
const run = await architect.scheduleTarget(target);
const output = await run.result as ServerBuilderOutput;
expect(output.success).toBe(true);
const fileName = join(outputPath, 'main.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toContain(`url('/assets/component-img-absolute.png')`);
expect(content).toContain(`url('component-img-relative.png')`);
expect(host.scopedSync().exists(normalize(`${outputPath}/component-img-relative.png`)))
.toBe(false);
});
});