-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathfind-tests_spec.ts
67 lines (59 loc) · 2.38 KB
/
find-tests_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
/**
* @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 { getTestEntrypoints } from './find-tests';
const UNIX_ENTRYPOINTS_OPTIONS = {
pathSeparator: '/',
workspaceRoot: '/my/workspace/root',
projectSourceRoot: '/my/workspace/root/src-root',
};
const WINDOWS_ENTRYPOINTS_OPTIONS = {
pathSeparator: '\\',
workspaceRoot: 'C:\\my\\workspace\\root',
projectSourceRoot: 'C:\\my\\workspace\\root\\src-root',
};
describe('getTestEntrypoints', () => {
for (const options of [UNIX_ENTRYPOINTS_OPTIONS, WINDOWS_ENTRYPOINTS_OPTIONS]) {
describe(`with path separator "${options.pathSeparator}"`, () => {
function joinWithSeparator(base: string, rel: string) {
return `${base}${options.pathSeparator}${rel.replace(/\//g, options.pathSeparator)}`;
}
function getEntrypoints(workspaceRelative: string[], sourceRootRelative: string[] = []) {
return getTestEntrypoints(
[
...workspaceRelative.map((p) => joinWithSeparator(options.workspaceRoot, p)),
...sourceRootRelative.map((p) => joinWithSeparator(options.projectSourceRoot, p)),
],
options,
);
}
it('returns an empty map without test files', () => {
expect(getEntrypoints([])).toEqual(new Map());
});
it('strips workspace root and/or project source root', () => {
expect(getEntrypoints(['a/b.spec.js'], ['c/d.spec.js'])).toEqual(
new Map<string, string>([
['spec-a-b.spec', joinWithSeparator(options.workspaceRoot, 'a/b.spec.js')],
['spec-c-d.spec', joinWithSeparator(options.projectSourceRoot, 'c/d.spec.js')],
]),
);
});
it('adds unique prefixes to distinguish between similar names', () => {
expect(getEntrypoints(['a/b/c/d.spec.js', 'a-b/c/d.spec.js'], ['a/b-c/d.spec.js'])).toEqual(
new Map<string, string>([
['spec-a-b-c-d.spec', joinWithSeparator(options.workspaceRoot, 'a/b/c/d.spec.js')],
['spec-a-b-c-d-2.spec', joinWithSeparator(options.workspaceRoot, 'a-b/c/d.spec.js')],
[
'spec-a-b-c-d-3.spec',
joinWithSeparator(options.projectSourceRoot, 'a/b-c/d.spec.js'),
],
]),
);
});
});
}
});