forked from webpack/webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathURLAbsoluteSpecifier.unittest.js
85 lines (82 loc) · 1.51 KB
/
URLAbsoluteSpecifier.unittest.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const { getScheme, getProtocol } = require("../lib/util/URLAbsoluteSpecifier");
/**
* @type {Array<{specifier: string, expected: string|undefined}>}
*/
const samples = [
{
specifier: "@babel/core",
expected: undefined
},
{
specifier: "webpack",
expected: undefined
},
{
specifier: "1webpack:///c:/windows/dir",
expected: undefined
},
{
specifier: "webpack:///c:/windows/dir",
expected: "webpack"
},
{
specifier: "WEBPACK2020:///c:/windows/dir",
expected: "webpack2020"
},
{
specifier: "my-data:image/jpg;base64",
expected: "my-data"
},
{
specifier: "My+Data:image/jpg;base64",
expected: "my+data"
},
{
specifier: "mY+dATA:image/jpg;base64",
expected: "my+data"
},
{
specifier: "my-data/next:image/",
expected: undefined
},
{
specifier: "my-data\\next:image/",
expected: undefined
},
{
specifier: "D:\\path\\file.js",
expected: undefined
},
{
specifier: "d:/path/file.js",
expected: undefined
},
{
specifier: "z:#foo",
expected: undefined
},
{
specifier: "Z:?query",
expected: undefined
},
{
specifier: "C:",
expected: undefined
}
];
describe("getScheme", () => {
samples.forEach(({ specifier, expected }, i) => {
it(`should handle ${specifier}`, () => {
expect(getScheme(specifier)).toBe(expected);
});
});
});
describe("getProtocol", () => {
samples.forEach(({ specifier, expected }, i) => {
it(`should handle ${specifier}`, () => {
expect(getProtocol(specifier)).toBe(
expected ? expected + ":" : undefined
);
});
});
});