-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathapi_spec.ts
49 lines (45 loc) · 1.82 KB
/
api_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
/**
* @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 { Target, targetFromTargetString, targetStringFromTarget } from './api';
describe('Architect API', () => {
const goldens: { [t: string]: Target } = {
'a:b:c': { project: 'a', target: 'b', configuration: 'c' },
'a:b': { project: 'a', target: 'b' },
':b': { project: '', target: 'b' },
':b:c': { project: '', target: 'b', configuration: 'c' },
':': { project: '', target: '' },
'::': { project: '', target: '', configuration: '' },
'a:b:': { project: 'a', target: 'b', configuration: '' },
'a::c': { project: 'a', target: '', configuration: 'c' },
'a:b:c:': { project: 'a', target: 'b', configuration: 'c' },
'a:b:c:d': { project: 'a', target: 'b', configuration: 'c' },
'a:b:c:d:': { project: 'a', target: 'b', configuration: 'c' },
};
describe('targetFromTargetString', () => {
for (const ts of Object.getOwnPropertyNames(goldens)) {
const t: Target = goldens[ts];
it(`works for ${JSON.stringify(ts)}`, () => {
expect(targetFromTargetString(ts)).toEqual(t);
});
}
it('errors out for invalid strings', () => {
expect(() => targetFromTargetString('')).toThrow();
expect(() => targetFromTargetString('a')).toThrow();
});
});
describe('targetStringFromTarget', () => {
for (const ts of Object.getOwnPropertyNames(goldens)) {
const t: Target = goldens[ts];
it(`works for ${JSON.stringify(t)}`, () => {
// We have some invalid goldens. Remove everything after the second :.
const goldenTs = ts.replace(/(\w+:\w+(:\w*)?).*/, '$1');
expect(targetStringFromTarget(t)).toEqual(goldenTs);
});
}
});
});