-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathoutput-path_spec_large.ts
90 lines (75 loc) · 3.08 KB
/
output-path_spec_large.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @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
*/
import { Architect } from '@angular-devkit/architect';
import { getSystemPath, join, virtualFs } from '@angular-devkit/core';
import * as fs from 'fs';
import { browserBuild, createArchitect, host } from '../utils';
describe('Browser Builder output path', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('deletes output path', async () => {
// Write a file to the output path to later verify it was deleted.
await host.write(
join(host.root(), 'dist/file.txt'),
virtualFs.stringToFileBuffer('file'),
).toPromise();
// Delete an app file to force a failed compilation.
// Failed compilations still delete files, but don't output any.
await host.delete(join(host.root(), 'src', 'app', 'app.component.ts')).toPromise();
const run = await architect.scheduleTarget(target);
const output = await run.result;
expect(output.success).toBe(false);
expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
await run.stop();
});
it('deletes output path and unlink symbolic link', async () => {
// Write a file to the output path to later verify it was deleted.
host.writeMultipleFiles({
'src-link/dummy.txt': '',
'dist/file.txt': virtualFs.stringToFileBuffer('file'),
});
const distLinked = join(host.root(), 'dist', 'linked');
// create symbolic link
fs.symlinkSync(
getSystemPath(join(host.root(), 'src-link')),
getSystemPath(distLinked),
'junction',
);
expect(await host.exists(distLinked).toPromise()).toBe(true);
// Delete an app file to force a failed compilation.
// Failed compilations still delete files, but don't output any.
await host.delete(join(host.root(), 'src', 'app', 'app.component.ts')).toPromise();
const run = await architect.scheduleTarget(target);
const output = await run.result;
expect(output.success).toBe(false);
expect(await host.exists(join(host.root(), 'dist')).toPromise()).toBe(false);
expect(await host.exists(join(host.root(), 'src-link')).toPromise()).toBe(true);
});
it('does not allow output path to be project root', async () => {
const overrides = { outputPath: './' };
const run = await architect.scheduleTarget(target, overrides);
try {
await run.result;
expect('THE ABOVE LINE SHOULD THROW').toBe('');
} catch { }
await run.stop();
});
it('works with absolute outputPath', async () => {
const overrides = {
outputPath: getSystemPath(join(host.root(), 'dist')),
};
const { files } = await browserBuild(architect, host, target, overrides);
expect('main.js' in files).toBe(true);
expect('index.html' in files).toBe(true);
});
});