|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright Google LLC All Rights Reserved. |
| 4 | + * |
| 5 | + * Use of this source code is governed by an MIT-style license that can be |
| 6 | + * found in the LICENSE file at https://angular.dev/license |
| 7 | + */ |
| 8 | + |
| 9 | +import { getTestEntrypoints } from './find-tests'; |
| 10 | + |
| 11 | +const UNIX_ENTRYPOINTS_OPTIONS = { |
| 12 | + pathSeparator: '/', |
| 13 | + workspaceRoot: '/my/workspace/root', |
| 14 | + projectSourceRoot: '/my/workspace/root/src-root', |
| 15 | +}; |
| 16 | + |
| 17 | +const WINDOWS_ENTRYPOINTS_OPTIONS = { |
| 18 | + pathSeparator: '\\', |
| 19 | + workspaceRoot: 'C:\\my\\workspace\\root', |
| 20 | + projectSourceRoot: 'C:\\my\\workspace\\root\\src-root', |
| 21 | +}; |
| 22 | + |
| 23 | +describe('getTestEntrypoints', () => { |
| 24 | + for (const options of [UNIX_ENTRYPOINTS_OPTIONS, WINDOWS_ENTRYPOINTS_OPTIONS]) { |
| 25 | + describe(`with path separator "${options.pathSeparator}"`, () => { |
| 26 | + function joinWithSeparator(base: string, rel: string) { |
| 27 | + return `${base}${options.pathSeparator}${rel.replace(/\//g, options.pathSeparator)}`; |
| 28 | + } |
| 29 | + |
| 30 | + function getEntrypoints(workspaceRelative: string[], sourceRootRelative: string[] = []) { |
| 31 | + return getTestEntrypoints( |
| 32 | + [ |
| 33 | + ...workspaceRelative.map((p) => joinWithSeparator(options.workspaceRoot, p)), |
| 34 | + ...sourceRootRelative.map((p) => joinWithSeparator(options.projectSourceRoot, p)), |
| 35 | + ], |
| 36 | + options, |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + it('returns an empty map without test files', () => { |
| 41 | + expect(getEntrypoints([])).toEqual(new Map()); |
| 42 | + }); |
| 43 | + |
| 44 | + it('strips workspace root and/or project source root', () => { |
| 45 | + expect(getEntrypoints(['a/b.spec.js'], ['c/d.spec.js'])).toEqual( |
| 46 | + new Map<string, string>([ |
| 47 | + ['spec-a-b.spec', joinWithSeparator(options.workspaceRoot, 'a/b.spec.js')], |
| 48 | + ['spec-c-d.spec', joinWithSeparator(options.projectSourceRoot, 'c/d.spec.js')], |
| 49 | + ]), |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('adds unique prefixes to distinguish between similar names', () => { |
| 54 | + expect(getEntrypoints(['a/b/c/d.spec.js', 'a-b/c/d.spec.js'], ['a/b-c/d.spec.js'])).toEqual( |
| 55 | + new Map<string, string>([ |
| 56 | + ['spec-a-b-c-d.spec', joinWithSeparator(options.workspaceRoot, 'a/b/c/d.spec.js')], |
| 57 | + ['spec-a-b-c-d-2.spec', joinWithSeparator(options.workspaceRoot, 'a-b/c/d.spec.js')], |
| 58 | + [ |
| 59 | + 'spec-a-b-c-d-3.spec', |
| 60 | + joinWithSeparator(options.projectSourceRoot, 'a/b-c/d.spec.js'), |
| 61 | + ], |
| 62 | + ]), |
| 63 | + ); |
| 64 | + }); |
| 65 | + }); |
| 66 | + } |
| 67 | +}); |
0 commit comments