@modern-js/server 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/js/modern/dev-tools/babel/register.js +1 -0
  3. package/dist/js/modern/dev-tools/dev-server-plugin.js +1 -2
  4. package/dist/js/modern/dev-tools/mock/getMockData.js +24 -1
  5. package/dist/js/modern/dev-tools/mock/index.js +1 -26
  6. package/dist/js/modern/dev-tools/socket-server.js +4 -2
  7. package/dist/js/modern/dev-tools/watcher/index.js +3 -4
  8. package/dist/js/modern/dev-tools/watcher/stats-cache.js +32 -20
  9. package/dist/js/modern/libs/context/context.js +6 -0
  10. package/dist/js/modern/libs/hook-api/route.js +6 -4
  11. package/dist/js/modern/libs/render/index.js +1 -0
  12. package/dist/js/modern/libs/render/ssr.js +7 -2
  13. package/dist/js/modern/libs/route/index.js +0 -1
  14. package/dist/js/modern/libs/route/matcher.js +15 -3
  15. package/dist/js/modern/libs/route/route.js +1 -0
  16. package/dist/js/modern/server/dev-server/dev-server.js +3 -0
  17. package/dist/js/modern/server/index.js +5 -4
  18. package/dist/js/modern/server/modern-server-split.js +1 -1
  19. package/dist/js/modern/server/modern-server.js +9 -5
  20. package/dist/js/modern/utils.js +7 -0
  21. package/dist/js/node/dev-tools/babel/register.js +1 -0
  22. package/dist/js/node/dev-tools/dev-server-plugin.js +1 -2
  23. package/dist/js/node/dev-tools/mock/getMockData.js +29 -2
  24. package/dist/js/node/dev-tools/mock/index.js +5 -26
  25. package/dist/js/node/dev-tools/socket-server.js +4 -2
  26. package/dist/js/node/dev-tools/watcher/index.js +6 -2
  27. package/dist/js/node/dev-tools/watcher/stats-cache.js +33 -20
  28. package/dist/js/node/libs/context/context.js +6 -0
  29. package/dist/js/node/libs/hook-api/route.js +6 -4
  30. package/dist/js/node/libs/render/index.js +1 -0
  31. package/dist/js/node/libs/render/ssr.js +8 -2
  32. package/dist/js/node/libs/route/index.js +0 -1
  33. package/dist/js/node/libs/route/matcher.js +16 -3
  34. package/dist/js/node/libs/route/route.js +1 -0
  35. package/dist/js/node/server/dev-server/dev-server.js +3 -0
  36. package/dist/js/node/server/index.js +9 -6
  37. package/dist/js/node/server/modern-server-split.js +1 -1
  38. package/dist/js/node/server/modern-server.js +9 -5
  39. package/dist/js/node/utils.js +13 -2
  40. package/dist/types/dev-tools/mock/getMockData.d.ts +2 -1
  41. package/dist/types/dev-tools/socket-server.d.ts +1 -2
  42. package/dist/types/dev-tools/watcher/index.d.ts +2 -1
  43. package/dist/types/dev-tools/watcher/stats-cache.d.ts +3 -2
  44. package/dist/types/libs/context/context.d.ts +2 -0
  45. package/dist/types/libs/hook-api/route.d.ts +3 -2
  46. package/dist/types/libs/render/ssr.d.ts +1 -0
  47. package/dist/types/libs/route/matcher.d.ts +1 -1
  48. package/dist/types/libs/route/route.d.ts +1 -0
  49. package/dist/types/server/dev-server/dev-server-split.d.ts +3 -3
  50. package/dist/types/server/modern-server-split.d.ts +3 -3
  51. package/dist/types/server/modern-server.d.ts +1 -1
  52. package/dist/types/type.d.ts +5 -3
  53. package/dist/types/utils.d.ts +2 -1
  54. package/package.json +8 -6
  55. package/tests/context.test.ts +12 -1
  56. package/tests/dev.test.ts +300 -6
  57. package/tests/fixtures/mock/exist/config/mock/index.ts +11 -0
  58. package/tests/fixtures/mock/zero/config/mock/index.ts +1 -0
  59. package/tests/fixtures/route-spec/dynamic.json +13 -0
  60. package/tests/fixtures/ssr/bundle.js +5 -0
  61. package/tests/fixtures/watch/a.ts +3 -0
  62. package/tests/fixtures/watch/index.ts +5 -0
  63. package/tests/fixtures/watch/stats.txt +1 -0
  64. package/tests/hook.test.ts +1 -1
  65. package/tests/route.test.ts +26 -3
  66. package/tests/ssr.test.ts +34 -0
  67. package/tests/utils.test.ts +6 -0
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.2",
14
+ "version": "1.4.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -34,12 +34,12 @@
34
34
  "@babel/preset-typescript": "^7.15.0",
35
35
  "@babel/register": "^7.15.3",
36
36
  "@babel/runtime": "^7",
37
- "@modern-js/core": "^1.3.2",
37
+ "@modern-js/core": "^1.4.0",
38
38
  "@modern-js/hmr-client": "^1.2.1",
39
- "@modern-js/server-plugin": "^1.2.1",
39
+ "@modern-js/server-core": "^1.2.2",
40
40
  "@modern-js/server-utils": "^1.2.1",
41
41
  "@modern-js/bff-utils": "^1.2.2",
42
- "@modern-js/utils": "^1.2.2",
42
+ "@modern-js/utils": "^1.3.0",
43
43
  "axios": "^0.24.0",
44
44
  "babel-plugin-module-resolver": "^4.1.0",
45
45
  "chokidar": "^3.5.2",
@@ -60,11 +60,12 @@
60
60
  "ua-parser-js": "^0.7.28",
61
61
  "webpack-dev-middleware": "^5.0.0",
62
62
  "ws": "^8.2.0",
63
- "lodash.clone": "^4.5.0"
63
+ "lodash.clone": "^4.5.0",
64
+ "cookie": "^0.4.2"
64
65
  },
65
66
  "devDependencies": {
66
67
  "@scripts/build": "0.0.0",
67
- "@modern-js/types": "^1.2.1",
68
+ "@modern-js/types": "^1.3.0",
68
69
  "@types/jest": "^26",
69
70
  "@types/lru-cache": "^5.1.1",
70
71
  "@types/mime-types": "^2.1.0",
@@ -79,6 +80,7 @@
79
80
  "@types/webpack-dev-middleware": "^5.0.2",
80
81
  "@types/ws": "^7.4.7",
81
82
  "@types/lodash.clone": "^4",
83
+ "@types/cookie": "^0.4.1",
82
84
  "typescript": "^4",
83
85
  "webpack": "^5.54.0",
84
86
  "node-mocks-http": "^1.11.0",
@@ -14,6 +14,7 @@ describe('test server context', () => {
14
14
  method: 'GET',
15
15
  });
16
16
  const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
17
+ const context = createContext(req, res);
17
18
  const {
18
19
  method,
19
20
  url,
@@ -25,7 +26,7 @@ describe('test server context', () => {
25
26
  querystring,
26
27
  protocol,
27
28
  params,
28
- } = createContext(req, res);
29
+ } = context;
29
30
 
30
31
  expect(method).toBe('GET');
31
32
  expect(url).toBe('/pathname?foo=baz');
@@ -37,5 +38,15 @@ describe('test server context', () => {
37
38
  expect(querystring).toBe('foo=baz');
38
39
  expect(protocol).toBe('http');
39
40
  expect(params).toEqual({});
41
+
42
+ expect(context.serverData).toEqual({});
43
+ context.setServerData('foo', {
44
+ name: 'foo',
45
+ });
46
+ expect(context.serverData).toEqual({
47
+ foo: {
48
+ name: 'foo',
49
+ },
50
+ });
40
51
  });
41
52
  });
package/tests/dev.test.ts CHANGED
@@ -1,5 +1,19 @@
1
1
  import http from 'http';
2
+ import path from 'path';
3
+ import { webpack } from 'webpack';
4
+ import { fs, LAUNCH_EDITOR_ENDPOINT } from '@modern-js/utils';
2
5
  import SocketServer from '../src/dev-tools/socket-server';
6
+ import DevServerPlugin from '../src/dev-tools/dev-server-plugin';
7
+ import Watcher, { getWatchedFiles } from '../src/dev-tools/watcher';
8
+ import { StatsCache } from '../src/dev-tools/watcher/stats-cache';
9
+ import { createMockHandler } from '../src/dev-tools/mock';
10
+ import getMockData, { getMatched } from '../src/dev-tools/mock/getMockData';
11
+ import { createLaunchEditorHandler } from '../src/dev-tools/launch-editor';
12
+ import { genHttpsOptions } from '../src/dev-tools/https';
13
+
14
+ const noop = () => {
15
+ // empty
16
+ };
3
17
 
4
18
  function getRandomPort() {
5
19
  return Math.floor(Math.random() * (8000 - 1024)) + 1024;
@@ -23,11 +37,9 @@ describe('test dev tools', () => {
23
37
  hot: true,
24
38
  liveReload: true,
25
39
  });
26
- const app = http
27
- .createServer((req, res) => {
28
- res.end();
29
- })
30
- .listen(port);
40
+ const app = http.createServer((req, res) => {
41
+ res.end();
42
+ });
31
43
 
32
44
  socketServer.prepare(app);
33
45
  expect(socketServer.app).toBe(app);
@@ -39,6 +51,288 @@ describe('test dev tools', () => {
39
51
  socketServer.updateStats(mockStats);
40
52
  expect(socketServer.stats).toBe(mockStats);
41
53
 
42
- app.close();
54
+ const socket = {
55
+ state: 1,
56
+ close() {
57
+ socket.state = 0;
58
+ // empty
59
+ },
60
+ };
61
+ socketServer.sockets = [socket];
62
+ socketServer.close();
63
+ expect(socket.state).toBe(0);
64
+ });
65
+
66
+ test('should dev server plugin work correctly', () => {
67
+ const compiler = webpack({});
68
+ new DevServerPlugin({
69
+ client: {
70
+ port: '8080',
71
+ overlay: false,
72
+ logging: 'error',
73
+ path: '/',
74
+ host: '127.0.0.1',
75
+ },
76
+ dev: {
77
+ writeToDisk: false,
78
+ },
79
+ watch: true,
80
+ hot: true,
81
+ liveReload: true,
82
+ }).apply(compiler);
83
+
84
+ // expect(compiler.options.entry)
85
+ const entryPluginHook = compiler.hooks.compilation.taps.filter(
86
+ tap => tap.name === 'EntryPlugin',
87
+ );
88
+ const hotPluginHook = compiler.hooks.compilation.taps.filter(
89
+ tap => tap.name === 'HotModuleReplacementPlugin',
90
+ );
91
+ expect(entryPluginHook.length).toBe(3);
92
+ expect(hotPluginHook.length).toBe(1);
93
+ });
94
+
95
+ describe('test watcher', () => {
96
+ let watcher: any;
97
+ const baseDir = path.join(__dirname, 'fixtures');
98
+ const watchDir = path.join(baseDir, 'watch/**');
99
+ const filepath = path.join(baseDir, 'watch', 'index.ts');
100
+ const filepatha = path.join(baseDir, 'watch', 'a.ts');
101
+ const txt = path.join(baseDir, 'watch', 'stats.txt');
102
+
103
+ afterEach(() => {
104
+ if (watcher) {
105
+ watcher.close();
106
+ }
107
+ fs.writeFileSync(txt, '1');
108
+ });
109
+
110
+ it('should create watcher instance correctly', resolve => {
111
+ watcher = new Watcher();
112
+ expect(watcher.dependencyTree).toBeNull();
113
+ watcher.createDepTree();
114
+ expect(watcher.dependencyTree).not.toBeNull();
115
+
116
+ expect(watcher.watcher).toBeUndefined();
117
+ watcher.listen([watchDir], {}, () => {
118
+ // empty
119
+ });
120
+
121
+ expect(watcher.watcher).toBeDefined();
122
+ require(filepath);
123
+ expect(watcher.dependencyTree.getNode(filepath)).toBeUndefined();
124
+ watcher.updateDepTree();
125
+ expect(watcher.dependencyTree.getNode(filepath)).toBeDefined();
126
+ watcher.cleanDepCache(filepath);
127
+ expect(watcher.dependencyTree.getNode(filepath)).toBeDefined();
128
+
129
+ jest.resetModules();
130
+ watcher.updateDepTree();
131
+ expect(watcher.dependencyTree.getNode(filepath)).toBeUndefined();
132
+
133
+ setTimeout(() => {
134
+ const fl = getWatchedFiles(watcher.watcher);
135
+ expect(fl.includes(filepatha)).toBeTruthy();
136
+ expect(fl.includes(filepath)).toBeTruthy();
137
+ expect(fl.includes(txt)).toBeTruthy();
138
+ resolve();
139
+ }, 1000);
140
+ });
141
+
142
+ it('should stats cache instance work correctly', () => {
143
+ const statsCache = new StatsCache();
144
+
145
+ // should not exist false before add
146
+ expect(statsCache.has(txt)).toBeFalsy();
147
+
148
+ // should exist true after add
149
+ statsCache.add([txt]);
150
+ expect(statsCache.has(txt)).toBeTruthy();
151
+
152
+ // should diff correctly
153
+ fs.writeFileSync(txt, 'foo');
154
+ expect(statsCache.isDiff(txt)).toBeTruthy();
155
+
156
+ // should not diff if not refresh
157
+ fs.writeFileSync(txt, '1');
158
+ expect(statsCache.isDiff(txt)).toBeFalsy();
159
+
160
+ // should diff after refresh
161
+ fs.writeFileSync(txt, 'foo');
162
+ statsCache.refresh(txt);
163
+ fs.writeFileSync(txt, '1');
164
+ expect(statsCache.isDiff(txt)).toBeTruthy();
165
+
166
+ // should diff when content change
167
+ statsCache.refresh(txt);
168
+ fs.writeFileSync(txt, '2');
169
+ expect(statsCache.isDiff(txt)).toBeTruthy();
170
+
171
+ // should not exist after del
172
+ statsCache.del(txt);
173
+ expect(statsCache.has(txt)).toBeFalsy();
174
+ });
175
+ });
176
+
177
+ describe('should mock middleware work correctly', () => {
178
+ const pwd = path.join(__dirname, './fixtures/mock');
179
+
180
+ it('should return null if no config mock dir', () => {
181
+ expect(createMockHandler({ pwd: path.join(pwd, 'empty') })).toBeNull();
182
+ });
183
+
184
+ it('should return null if no api dir', () => {
185
+ expect(createMockHandler({ pwd: path.join(pwd, 'zero') })).toBeNull();
186
+ });
187
+
188
+ it('should return middleware if mock api exist', async () => {
189
+ const middleware = createMockHandler({ pwd: path.join(pwd, 'exist') });
190
+
191
+ expect(middleware).not.toBeNull();
192
+
193
+ let response: any;
194
+ const context: any = {
195
+ path: '/api/getInfo',
196
+ method: 'get',
197
+ res: {
198
+ setHeader: noop,
199
+ end: (data: any) => {
200
+ response = JSON.parse(data);
201
+ },
202
+ },
203
+ };
204
+ await middleware?.(context, noop);
205
+ expect(response).toEqual({
206
+ data: [1, 2, 3, 4],
207
+ });
208
+ });
209
+
210
+ it('should get api list correctly', () => {
211
+ const apiList = getMockData(path.join(pwd, 'exist/config/mock/index.ts'));
212
+ expect(apiList.length).toBe(3);
213
+
214
+ const pathList = apiList.map(api => api.path);
215
+ expect(pathList).toEqual([
216
+ '/api/getInfo',
217
+ '/api/getExample',
218
+ '/api/addInfo',
219
+ ]);
220
+
221
+ let response: any;
222
+ const context: any = {
223
+ res: {
224
+ setHeader: noop,
225
+ end: (data: any) => {
226
+ response = JSON.parse(data);
227
+ },
228
+ },
229
+ };
230
+
231
+ apiList[0].handler(context, noop as any);
232
+ expect(response).toEqual({
233
+ data: [1, 2, 3, 4],
234
+ });
235
+ apiList[1].handler(context, noop as any);
236
+ expect(response).toEqual({ id: 1 });
237
+ });
238
+
239
+ it('should match api correctly', () => {
240
+ const apiList = [
241
+ {
242
+ method: 'get',
243
+ path: '/api/getInfo',
244
+ handler: noop,
245
+ },
246
+ {
247
+ method: 'get',
248
+ path: '/api/getExample',
249
+ handler: noop,
250
+ },
251
+ {
252
+ method: 'get',
253
+ path: '/api/addInfo',
254
+ handler: noop,
255
+ },
256
+ ];
257
+ const matched = getMatched(
258
+ { path: '/api/getInfo', method: 'get' } as any,
259
+ apiList,
260
+ );
261
+ expect(matched).toBe(apiList[0]);
262
+
263
+ const missMethod = getMatched(
264
+ { path: '/api/getModern', method: 'post' } as any,
265
+ apiList,
266
+ );
267
+ expect(missMethod).toBeUndefined();
268
+ });
269
+ });
270
+
271
+ describe('should createLaunchEditorHandler work correctly', () => {
272
+ const middleware = createLaunchEditorHandler();
273
+
274
+ it('should return 200 if filename exist', () => {
275
+ let response: any;
276
+ const context: any = {
277
+ url: LAUNCH_EDITOR_ENDPOINT,
278
+ query: {
279
+ filename: 'test.ts',
280
+ },
281
+ res: {
282
+ end: (data: any) => {
283
+ response = data;
284
+ },
285
+ },
286
+ };
287
+ middleware(context, noop);
288
+ expect(context.status).toBe(200);
289
+ expect(response).toBeUndefined();
290
+ });
291
+
292
+ it('should return 500 if filename not exist', () => {
293
+ let response: any;
294
+ const context: any = {
295
+ url: LAUNCH_EDITOR_ENDPOINT,
296
+ query: {
297
+ filename: '',
298
+ },
299
+ res: {
300
+ end: (data: any) => {
301
+ response = data;
302
+ },
303
+ },
304
+ };
305
+ middleware(context, noop);
306
+ expect(context.status).toBe(500);
307
+ expect(typeof response === 'string').toBeTruthy();
308
+ });
309
+
310
+ it('should invoke next if not launch editor url', () => {
311
+ let response: any;
312
+ const context: any = {
313
+ url: '',
314
+ res: {
315
+ end: (data: any) => {
316
+ response = data;
317
+ },
318
+ },
319
+ };
320
+ middleware(context, noop);
321
+ expect(context.status).toBeUndefined();
322
+ expect(response).toBeUndefined();
323
+ });
324
+ });
325
+
326
+ test('should get http cert correctly', async () => {
327
+ // const options = await genHttpsOptions(true);
328
+ // expect(options.key).toBeDefined();
329
+ // expect(options.cert).toBeDefined();
330
+
331
+ const useOpt = await genHttpsOptions({
332
+ key: 'foo',
333
+ cert: 'baz',
334
+ });
335
+ expect(useOpt.key).toBe('foo');
336
+ expect(useOpt.cert).toBe('baz');
43
337
  });
44
338
  });
@@ -0,0 +1,11 @@
1
+ export default {
2
+ 'GET /api/getInfo': { data: [1, 2, 3, 4] },
3
+
4
+ '/api/getExample': { id: 1 },
5
+
6
+ 'GET /api/addInfo': (req: any, res: any) => {
7
+ setTimeout(() => {
8
+ res.end('delay 2000ms');
9
+ }, 2000);
10
+ },
11
+ };
@@ -0,0 +1 @@
1
+ export default {};
@@ -0,0 +1,13 @@
1
+ {
2
+ "routes": [
3
+ {
4
+ "urlPath": "/entry/:id",
5
+ "entryName": "entry",
6
+ "entryPath": "html/entry/index.html",
7
+ "isSPA": true,
8
+ "isSSR": true,
9
+ "enableModernMode": false,
10
+ "bundle": "bundles/entry.js"
11
+ }
12
+ ]
13
+ }
@@ -0,0 +1,5 @@
1
+ const { SERVER_RENDER_FUNCTION_NAME } = require('@modern-js/utils');
2
+
3
+ module.exports = {
4
+ [SERVER_RENDER_FUNCTION_NAME]: () => '<div>Modern.js</div>',
5
+ };
@@ -0,0 +1,3 @@
1
+ export default {
2
+ name: 'a',
3
+ };
@@ -0,0 +1,5 @@
1
+ import a from './a';
2
+
3
+ export default {
4
+ a,
5
+ };
@@ -0,0 +1 @@
1
+ 1
@@ -10,7 +10,7 @@ describe('test hook api', () => {
10
10
  manager.reset(spec.routes);
11
11
  const matcher = manager.match('/home');
12
12
 
13
- const routeAPI = createRouteAPI(matcher!, manager);
13
+ const routeAPI = createRouteAPI(matcher!, manager, '');
14
14
  expect(routeAPI.cur().entryName).toBe('home');
15
15
  expect(routeAPI.get('entry')?.entryPath).toBe('html/entry/index.html');
16
16
 
@@ -1,5 +1,6 @@
1
1
  import { RouteMatchManager, RouteMatcher } from '../src/libs/route';
2
2
  import spec from './fixtures/route-spec/index.json';
3
+ import dynamic from './fixtures/route-spec/dynamic.json';
3
4
 
4
5
  describe('test route', () => {
5
6
  describe('test route matcher', () => {
@@ -12,7 +13,7 @@ describe('test route', () => {
12
13
  expect(matcher.urlMatcher).toBeUndefined();
13
14
 
14
15
  const { isSSR, isApi, isSPA, urlPath, entryName, entryPath } =
15
- matcher.generate();
16
+ matcher.generate('');
16
17
 
17
18
  expect(isSSR).toBeTruthy();
18
19
  expect(isApi).toBeFalsy();
@@ -38,11 +39,11 @@ describe('test route', () => {
38
39
 
39
40
  const matchedByEntry = manager.matchEntry('home');
40
41
  expect(matchedByEntry).toBeDefined();
41
- expect(matchedByEntry?.generate().entryName).toBe('home');
42
+ expect(matchedByEntry?.generate('').entryName).toBe('home');
42
43
 
43
44
  const matchedByUrl = manager.match('/entry');
44
45
  expect(matchedByUrl).toBeDefined();
45
- expect(matchedByUrl?.generate().entryName).toBe('entry');
46
+ expect(matchedByUrl?.generate('').entryName).toBe('entry');
46
47
 
47
48
  const SSRUrlBundles = manager.getBundles();
48
49
  expect(SSRUrlBundles).toEqual(['bundles/entry.js', 'bundles/home.js']);
@@ -50,5 +51,27 @@ describe('test route', () => {
50
51
  manager.reset([]);
51
52
  expect(manager.matchers.length).toBe(0);
52
53
  });
54
+
55
+ test('should manager work correctly with dynamic spec', async () => {
56
+ const manager = new RouteMatchManager();
57
+ expect(manager.matchers.length).toBe(0);
58
+ manager.reset(dynamic.routes);
59
+ expect(manager.matchers.length).toBe(1);
60
+
61
+ const matched = manager.match('/entry/001');
62
+ expect(matched).toBeDefined();
63
+ const route = matched?.generate('/entry/001');
64
+ expect(route?.entryName).toBe('entry');
65
+ expect(route?.params).toEqual({ id: '001' });
66
+
67
+ const matchedWithTrail = manager.match('/entry/001/a');
68
+ expect(matchedWithTrail).toBeDefined();
69
+ const routeWithTrail = matchedWithTrail?.generate('/entry/001/a');
70
+ expect(routeWithTrail?.entryName).toBe('entry');
71
+ expect(routeWithTrail?.params).toEqual({ id: '001' });
72
+
73
+ const miss = manager.match('/entry');
74
+ expect(miss).toBeUndefined();
75
+ });
53
76
  });
54
77
  });
@@ -0,0 +1,34 @@
1
+ import path from 'path';
2
+ import { render } from '../src/libs/render/ssr';
3
+
4
+ describe('test ssr render function', () => {
5
+ test('should return content correctly ', async () => {
6
+ const renderResult = await render(
7
+ {
8
+ params: {},
9
+ pathname: '/foo',
10
+ host: 'localhost:8080',
11
+ query: {},
12
+ url: 'localhost:8080/foo',
13
+ cookieMap: {},
14
+ headers: {},
15
+ } as any,
16
+ {
17
+ urlPath: '/foo',
18
+ bundle: 'bundle.js',
19
+ distDir: path.join(__dirname, 'fixtures', 'ssr'),
20
+ template: 'tpl.html',
21
+ entryName: 'foo',
22
+ staticGenerate: false,
23
+ } as any,
24
+ {
25
+ extendSSRContext: () => {
26
+ // empty
27
+ },
28
+ } as any,
29
+ );
30
+
31
+ expect(renderResult.content).toMatch('Modern.js');
32
+ expect(renderResult.contentType).toMatch('text/html; charset=utf-8');
33
+ });
34
+ });
@@ -1,3 +1,4 @@
1
+ import { compile } from 'path-to-regexp';
1
2
  import {
2
3
  noop,
3
4
  mergeExtension,
@@ -68,4 +69,9 @@ describe('test server utils', () => {
68
69
  expect(after.api).toEqual([middleware]);
69
70
  });
70
71
  });
72
+
73
+ test('should return full path', () => {
74
+ const fn = compile('/home/:id', { encode: encodeURIComponent });
75
+ expect(fn({ id: 2 })).toBe('/home/2');
76
+ });
71
77
  });