-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathexport-ref_spec.ts
58 lines (51 loc) · 2 KB
/
export-ref_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
/**
* @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 * as path from 'path';
import { CollectionCannotBeResolvedException } from '.';
import { ExportStringRef } from './export-ref';
describe('ExportStringRef', () => {
// Depending on how the package is built the module might be either .js or .ts.
// To make expectations easier, we strip the extension.
const stripExtension = (p: string) => p.replace(/\.(j|t)s$/, '');
it('works', () => {
// META
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname);
expect(ref.ref).toBe(ExportStringRef);
expect(ref.path).toBe(__dirname);
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('works without an inner ref', () => {
// META
const ref = new ExportStringRef(path.join(__dirname, 'export-ref'));
expect(ref.ref).toBe(undefined);
expect(ref.path).toBe(__dirname);
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('returns the exports', () => {
// META
const ref = new ExportStringRef('./export-ref#ExportStringRef', __dirname, false);
expect(ref.ref).toEqual({ ExportStringRef });
expect(ref.path).toBe(__dirname);
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'export-ref'));
});
it('works on package names', () => {
// META
const ref = new ExportStringRef(
'@angular-devkit/schematics/tools#CollectionCannotBeResolvedException',
);
expect(ref.ref).toEqual(CollectionCannotBeResolvedException);
expect(ref.path).toBe(__dirname);
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
});
it('works on directory', () => {
// META
const ref = new ExportStringRef(__dirname);
expect(ref.path).toBe(__dirname);
expect(stripExtension(ref.module)).toBe(path.join(__dirname, 'index'));
});
});