forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions_spec.ts
More file actions
85 lines (71 loc) · 2.69 KB
/
options_spec.ts
File metadata and controls
85 lines (71 loc) · 2.69 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
/**
* @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 { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { normalizeOptions } from './options';
import type { Schema as UnitTestBuilderOptions } from './schema';
function createMockContext(workspaceRoot: string) {
return {
workspaceRoot,
target: { project: 'test-project', target: 'test', configuration: '' },
logger: { warn: () => {}, info: () => {}, error: () => {}, debug: () => {} },
getProjectMetadata: async (_projectName: string) => ({
root: '.',
sourceRoot: 'src',
}),
getBuilderNameForTarget: async () => '@angular/build:application',
};
}
describe('normalizeOptions', () => {
let workspaceRoot: string;
beforeEach(async () => {
workspaceRoot = await mkdtemp(join(tmpdir(), 'angular-cli-options-spec-'));
// Write a minimal package.json so cache normalization works
await writeFile(join(workspaceRoot, 'package.json'), '{}');
// Create a tsconfig.spec.json so tsConfig resolution succeeds
await mkdir(join(workspaceRoot, 'src'), { recursive: true });
await writeFile(join(workspaceRoot, 'tsconfig.spec.json'), '{}');
});
afterEach(async () => {
await rm(workspaceRoot, { recursive: true, force: true });
});
it('should set update to false by default', async () => {
const options: UnitTestBuilderOptions = {};
const context = createMockContext(workspaceRoot);
const normalized = await normalizeOptions(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context as any,
'test-project',
options,
);
expect(normalized.update).toBeFalse();
});
it('should set update to true when update option is true', async () => {
const options: UnitTestBuilderOptions = { update: true };
const context = createMockContext(workspaceRoot);
const normalized = await normalizeOptions(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context as any,
'test-project',
options,
);
expect(normalized.update).toBeTrue();
});
it('should set update to false when update option is explicitly false', async () => {
const options: UnitTestBuilderOptions = { update: false };
const context = createMockContext(workspaceRoot);
const normalized = await normalizeOptions(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
context as any,
'test-project',
options,
);
expect(normalized.update).toBeFalse();
});
});