This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathindex.spec.ts
54 lines (49 loc) · 2.49 KB
/
index.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
import { getConvertedExternals } from './index';
describe('index', () => {
describe('getConvertedExternals', () => {
it('returns empty array when nullable is passed', () => {
const actualResult = getConvertedExternals(null);
expect(actualResult).toEqual([]);
});
const testCases = [
{
input: ['nativescript-vue'],
expectedOutput: [/^nativescript-vue((\/.*)|$)/]
},
{
input: ['nativescript-vue', 'nativescript-angular'],
expectedOutput: [/^nativescript-vue((\/.*)|$)/, /^nativescript-angular((\/.*)|$)/]
}
];
testCases.forEach(testCase => {
it('converts passed strings to regular expressions', () => {
const actualResult = getConvertedExternals(testCase.input);
expect(actualResult).toEqual(testCase.expectedOutput);
});
it(`returns regular expressions which match expected modules and their subdirs, for input ${testCase.input}`, () => {
[
'nativescript-vue',
'nativescript-vue/subdir',
'nativescript-vue/subdir/subdir-2'
].forEach(testString => {
const regExpsExternals = getConvertedExternals(testCase.input);
const result = regExpsExternals.some((regExp: RegExp) => !!regExp.exec(testString));
expect(result).toBe(true, `String ${testString} does not match any of the regular expressions: ${regExpsExternals.join(', ')}`);
});
});
it(`returns regular expressions which does not match expected modules and their subdirs, for input ${testCase.input}`, () => {
[
'nativescript-facebook',
'nativescript-facebook/nativescript-vue',
'main-plugin/subdir/nativescript-vue',
'nativescript-vue-template-compiler',
'nativescript-vue-template-compiler/subdir'
].forEach(testString => {
const regExpsExternals = getConvertedExternals(testCase.input);
const result = regExpsExternals.some((regExp: RegExp) => !!regExp.exec(testString));
expect(result).toBe(false, `String ${testString} matches some of the regular expressions: ${regExpsExternals.join(', ')}`);
});
});
});
});
});