This repository has been archived by the owner on Oct 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
getOutputPublicPath_spec.ts
114 lines (98 loc) · 3.53 KB
/
getOutputPublicPath_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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) 2018 Steven Enten. All rights reserved. Licensed under the MIT license.
import * as webpack from 'webpack';
import { getOutputPublicPath } from '../../../lib/util/getOutputPublicPath';
describe('getOutputPublicPath.ts', () => {
describe('getOutputPublicPath', () => {
it('should return "/" when given bad param', () => {
expect(getOutputPublicPath(null)).toEqual('/');
expect(getOutputPublicPath(undefined)).toEqual('/');
});
it('should return given url when param is a string', () => {
expect(getOutputPublicPath('/')).toEqual('/');
expect(getOutputPublicPath('/foo')).toEqual('/foo');
});
it('should remove base url when option pathOnly is true', () => {
expect(getOutputPublicPath('http://foo/bar', { pathOnly: true })).toEqual('/bar');
expect(getOutputPublicPath('http://foo/bar', { pathOnly: false })).toEqual('http://foo/bar');
});
it('should add ends slash when option endsSlash is true', () => {
expect(getOutputPublicPath('/foo', { endsSlash: true })).toEqual('/foo/');
expect(getOutputPublicPath('/foo/', { endsSlash: true })).toEqual('/foo/');
expect(getOutputPublicPath('/foo', { endsSlash: false })).toEqual('/foo');
expect(getOutputPublicPath('/foo/', { endsSlash: false })).toEqual('/foo');
});
it('should add starts slash when option startsSlash is true', () => {
expect(getOutputPublicPath('foo', { startsSlash: true })).toEqual('/foo');
expect(getOutputPublicPath('/foo', { startsSlash: true })).toEqual('/foo');
expect(getOutputPublicPath('foo', { startsSlash: false })).toEqual('foo');
expect(getOutputPublicPath('/foo', { startsSlash: false })).toEqual('foo');
});
it('should reduce from highest potential object to webpack config options output', () => {
expect(getOutputPublicPath({
compilation: {
compiler: {
options: {
output: {
publicPath: 'http://foo/bar/',
},
},
},
},
} as { compilation: webpack.compilation.Compilation }, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath({
compiler: {
options: {
output: {
publicPath: 'http://foo/bar/',
},
},
},
} as webpack.compilation.Compilation, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath({
options: {
output: {
publicPath: 'http://foo/bar/',
},
},
} as webpack.Compiler, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath({
output: {
publicPath: 'http://foo/bar/',
},
} as webpack.Configuration, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath({
publicPath: 'http://foo/bar/',
} as webpack.Output, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath('http://foo/bar/', {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('bar');
expect(getOutputPublicPath({}, {
endsSlash: false,
pathOnly: true,
startsSlash: false,
})).toEqual('');
});
});
});