1
1
// @flow
2
2
import assert from 'assert' ;
3
- import { shardUrlUnchecked , shardUrl , domainShardingKey } from '../src/index.js' ;
3
+ import {
4
+ shardUrlUnchecked ,
5
+ shardUrl ,
6
+ domainShardingKey ,
7
+ applyShardToDomain ,
8
+ } from '../src/index.js' ;
4
9
5
10
describe ( 'domain sharding helpers' , ( ) => {
6
11
beforeEach ( ( ) => {
7
12
// $FlowFixMe
8
13
delete globalThis [ domainShardingKey ] ;
9
14
} ) ;
10
15
16
+ describe ( 'applyShardToDomain' , ( ) => {
17
+ it ( 'should use the base domain for shard 0' , ( ) => {
18
+ const testBundle =
19
+ 'https://bundle-shard.assets.example.com/assets/test-bundle.123abc.js' ;
20
+
21
+ const result = applyShardToDomain ( testBundle , 0 ) ;
22
+
23
+ assert . equal (
24
+ result ,
25
+ 'https://bundle-shard.assets.example.com/assets/test-bundle.123abc.js' ,
26
+ ) ;
27
+ } ) ;
28
+
29
+ it ( 'should use the 0 shard domain for shard 1' , ( ) => {
30
+ const testBundle =
31
+ 'https://bundle-shard.assets.example.com/assets/test-bundle.123abc.js' ;
32
+
33
+ const result = applyShardToDomain ( testBundle , 1 ) ;
34
+
35
+ assert . equal (
36
+ result ,
37
+ 'https://bundle-shard-0.assets.example.com/assets/test-bundle.123abc.js' ,
38
+ ) ;
39
+ } ) ;
40
+
41
+ it ( 'should use the 2 shard domain for shard 3' , ( ) => {
42
+ const testBundle =
43
+ 'https://bundle-shard.assets.example.com/assets/test-bundle.123abc.js' ;
44
+
45
+ const result = applyShardToDomain ( testBundle , 3 ) ;
46
+
47
+ assert . equal (
48
+ result ,
49
+ 'https://bundle-shard-2.assets.example.com/assets/test-bundle.123abc.js' ,
50
+ ) ;
51
+ } ) ;
52
+ } ) ;
53
+
11
54
describe ( 'shardUrlUnchecked' , ( ) => {
12
55
it ( 'should shard a URL' , ( ) => {
13
56
const testBundle =
@@ -17,7 +60,19 @@ describe('domain sharding helpers', () => {
17
60
18
61
assert . equal (
19
62
result ,
20
- 'https://bundle-shard-0.assets.example.com/assets/test-bundle.123abc.js' ,
63
+ 'https://bundle-shard-1.assets.example.com/assets/test-bundle.123abc.js' ,
64
+ ) ;
65
+ } ) ;
66
+
67
+ it ( 'should include the original domain in the shar' , ( ) => {
68
+ const testBundle =
69
+ 'https://bundle-shard.assets.example.com/assets/test-bundle.123abc.js' ;
70
+
71
+ const result = shardUrlUnchecked ( testBundle , 5 ) ;
72
+
73
+ assert . equal (
74
+ result ,
75
+ 'https://bundle-shard-1.assets.example.com/assets/test-bundle.123abc.js' ,
21
76
) ;
22
77
} ) ;
23
78
@@ -29,7 +84,7 @@ describe('domain sharding helpers', () => {
29
84
30
85
assert . equal (
31
86
result ,
32
- 'https://bundle-shard-4 .assets.example.com/assets/TestBundle.1a2b3c.js' ,
87
+ 'https://bundle-shard-2 .assets.example.com/assets/TestBundle.1a2b3c.js' ,
33
88
) ;
34
89
} ) ;
35
90
@@ -38,7 +93,7 @@ describe('domain sharding helpers', () => {
38
93
39
94
const result = shardUrlUnchecked ( testBundle , 5 ) ;
40
95
41
- assert . equal ( result , 'http://localhost-3 /assets/testBundle.123abc.js' ) ;
96
+ assert . equal ( result , 'http://localhost-2 /assets/testBundle.123abc.js' ) ;
42
97
} ) ;
43
98
44
99
it ( 'should handle domains with ports' , ( ) => {
@@ -48,7 +103,7 @@ describe('domain sharding helpers', () => {
48
103
49
104
assert . equal (
50
105
result ,
51
- 'http://localhost-3 :8081/assets/testBundle.123abc.js' ,
106
+ 'http://localhost-2 :8081/assets/testBundle.123abc.js' ,
52
107
) ;
53
108
} ) ;
54
109
} ) ;
@@ -63,7 +118,7 @@ describe('domain sharding helpers', () => {
63
118
64
119
assert . equal (
65
120
result ,
66
- 'https://bundle-shard-0 .assets.example.com/assets/test-bundle.123abc.js' ,
121
+ 'https://bundle-shard-1 .assets.example.com/assets/test-bundle.123abc.js' ,
67
122
) ;
68
123
} ) ;
69
124
0 commit comments