forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_spec.ts
More file actions
99 lines (84 loc) · 3.24 KB
/
build_spec.ts
File metadata and controls
99 lines (84 loc) · 3.24 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
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
91
92
93
94
95
96
97
98
99
/**
* @license
* Copyright Google LLC 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.dev/license
*/
import { CommandError, Host } from '../host';
import type { MockHost } from '../testing/mock-host';
import { runBuild } from './build';
describe('Build Tool', () => {
let mockHost: MockHost;
beforeEach(() => {
mockHost = {
runCommand: jasmine.createSpy<Host['runCommand']>('runCommand').and.resolveTo({ logs: [] }),
stat: jasmine.createSpy<Host['stat']>('stat'),
existsSync: jasmine.createSpy<Host['existsSync']>('existsSync'),
} as MockHost;
});
it('should construct the command correctly with default configuration', async () => {
await runBuild({}, mockHost);
expect(mockHost.runCommand).toHaveBeenCalledWith('ng', ['build', '-c', 'development']);
});
it('should construct the command correctly with a specified project', async () => {
await runBuild({ project: 'another-app' }, mockHost);
expect(mockHost.runCommand).toHaveBeenCalledWith('ng', [
'build',
'another-app',
'-c',
'development',
]);
});
it('should construct the command correctly for a custom configuration', async () => {
await runBuild({ configuration: 'myconfig' }, mockHost);
expect(mockHost.runCommand).toHaveBeenCalledWith('ng', ['build', '-c', 'myconfig']);
});
it('should handle a successful build and extract the output path and logs', async () => {
const buildLogs = [
'Build successful!',
'Some other log lines...',
'some warning',
'Output location: dist/my-app',
];
mockHost.runCommand.and.resolveTo({
logs: buildLogs,
});
const { structuredContent } = await runBuild({ project: 'my-app' }, mockHost);
expect(mockHost.runCommand).toHaveBeenCalledWith('ng', [
'build',
'my-app',
'-c',
'development',
]);
expect(structuredContent.status).toBe('success');
expect(structuredContent.logs).toEqual(buildLogs);
expect(structuredContent.path).toBe('dist/my-app');
});
it('should handle a failed build and capture logs', async () => {
const buildLogs = ['Some output before the crash.', 'Error: Something went wrong!'];
const error = new CommandError('Build failed', buildLogs, 1);
mockHost.runCommand.and.rejectWith(error);
const { structuredContent } = await runBuild(
{ project: 'my-failed-app', configuration: 'production' },
mockHost,
);
expect(mockHost.runCommand).toHaveBeenCalledWith('ng', [
'build',
'my-failed-app',
'-c',
'production',
]);
expect(structuredContent.status).toBe('failure');
expect(structuredContent.logs).toEqual(buildLogs);
expect(structuredContent.path).toBeUndefined();
});
it('should handle builds where the output path is not found in logs', async () => {
const buildLogs = ["Some logs that don't match any output path."];
mockHost.runCommand.and.resolveTo({ logs: buildLogs });
const { structuredContent } = await runBuild({}, mockHost);
expect(structuredContent.status).toBe('success');
expect(structuredContent.logs).toEqual(buildLogs);
expect(structuredContent.path).toBeUndefined();
});
});