@modern-js/server 1.4.7-canary.2 → 1.4.9-beta.peer.1
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.
- package/.eslintrc.js +8 -0
- package/CHANGELOG.md +41 -0
- package/dist/js/modern/dev-tools/babel/register.js +1 -0
- package/dist/js/modern/dev-tools/dev-server-plugin.js +2 -5
- package/dist/js/modern/dev-tools/watcher/index.js +1 -2
- package/dist/js/modern/server/dev-server.js +49 -2
- package/dist/js/node/dev-tools/babel/register.js +1 -0
- package/dist/js/node/dev-tools/dev-server-plugin.js +2 -5
- package/dist/js/node/dev-tools/watcher/index.js +1 -3
- package/dist/js/node/server/dev-server.js +49 -2
- package/dist/types/dev-tools/watcher/index.d.ts +2 -2
- package/dist/types/server/dev-server.d.ts +2 -0
- package/jest.config.js +0 -1
- package/package.json +23 -25
- package/tests/.eslintrc.js +0 -6
- package/tests/dev.test.ts +0 -130
- package/tests/fixtures/mock/exist/config/mock/index.ts +0 -11
- package/tests/fixtures/mock/module-error/config/mock/index.ts +0 -1
- package/tests/fixtures/mock/type-error/config/mock/index.ts +0 -3
- package/tests/fixtures/mock/zero/config/mock/index.ts +0 -1
- package/tests/fixtures/pure/config/mock/index.ts +0 -11
- package/tests/fixtures/pure/modern.config.js +0 -5
- package/tests/fixtures/pure/package.json +0 -21
- package/tests/fixtures/pure/src/App.css +0 -119
- package/tests/fixtures/pure/src/App.tsx +0 -43
- package/tests/fixtures/pure/tsconfig.json +0 -12
- package/tests/fixtures/watch/a.ts +0 -3
- package/tests/fixtures/watch/index.ts +0 -5
- package/tests/fixtures/watch/stats.txt +0 -1
- package/tests/helper.ts +0 -3
- package/tests/https.test.ts +0 -17
- package/tests/launch-editor.test.ts +0 -58
- package/tests/mock.test.ts +0 -150
- package/tests/server.test.ts +0 -238
- package/tests/tsconfig.json +0 -12
- package/tests/watcher.test.ts +0 -228
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
html,
|
|
2
|
-
body {
|
|
3
|
-
padding: 0;
|
|
4
|
-
margin: 0;
|
|
5
|
-
font-family: nunito_for_arco, Helvetica Neue, Helvetica, PingFang SC,
|
|
6
|
-
Hiragino Sans GB, Microsoft YaHei, 微软雅黑, Arial, sans-serif;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
* {
|
|
10
|
-
-webkit-font-smoothing: antialiased;
|
|
11
|
-
-moz-osx-font-smoothing: grayscale;
|
|
12
|
-
box-sizing: border-box;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.container {
|
|
16
|
-
min-height: 100vh;
|
|
17
|
-
max-width: 100%;
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-direction: column;
|
|
20
|
-
justify-content: center;
|
|
21
|
-
align-items: center;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
main {
|
|
25
|
-
padding: 5rem 0;
|
|
26
|
-
flex: 1;
|
|
27
|
-
display: flex;
|
|
28
|
-
flex-direction: column;
|
|
29
|
-
justify-content: center;
|
|
30
|
-
align-items: center;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.footer {
|
|
34
|
-
width: 100%;
|
|
35
|
-
height: 80px;
|
|
36
|
-
border-top: 1px solid #eaeaea;
|
|
37
|
-
display: flex;
|
|
38
|
-
justify-content: center;
|
|
39
|
-
align-items: center;
|
|
40
|
-
background-color: #470000;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.footer a {
|
|
44
|
-
display: flex;
|
|
45
|
-
justify-content: center;
|
|
46
|
-
align-items: center;
|
|
47
|
-
flex-grow: 1;
|
|
48
|
-
color: #f4f4f4;
|
|
49
|
-
text-decoration: none;
|
|
50
|
-
font-size: 1.1rem;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
.logo {
|
|
54
|
-
margin-bottom: 2rem;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.logo svg {
|
|
58
|
-
width: 450px;
|
|
59
|
-
height: 132px;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
.description {
|
|
63
|
-
text-align: center;
|
|
64
|
-
line-height: 1.5;
|
|
65
|
-
font-size: 1.5rem;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.code {
|
|
69
|
-
background: #fafafa;
|
|
70
|
-
border-radius: 5px;
|
|
71
|
-
padding: 0.75rem;
|
|
72
|
-
font-size: 1.1rem;
|
|
73
|
-
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
|
|
74
|
-
Bitstream Vera Sans Mono, Courier New, monospace;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
@media (max-width: 600px) {
|
|
78
|
-
.grid {
|
|
79
|
-
width: 100%;
|
|
80
|
-
flex-direction: column;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.grid {
|
|
85
|
-
display: flex;
|
|
86
|
-
align-items: center;
|
|
87
|
-
justify-content: center;
|
|
88
|
-
flex-wrap: wrap;
|
|
89
|
-
width: 800px;
|
|
90
|
-
margin-top: 3rem;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.card {
|
|
94
|
-
margin: 1rem;
|
|
95
|
-
padding: 1.5rem;
|
|
96
|
-
display: flex;
|
|
97
|
-
align-items: center;
|
|
98
|
-
justify-content: center;
|
|
99
|
-
height: 100px;
|
|
100
|
-
color: inherit;
|
|
101
|
-
text-decoration: none;
|
|
102
|
-
border: 1px solid #470000;
|
|
103
|
-
color: #470000;
|
|
104
|
-
transition: color 0.15s ease, border-color 0.15s ease;
|
|
105
|
-
width: 45%;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.card:hover,
|
|
109
|
-
.card:focus,
|
|
110
|
-
.card:active {
|
|
111
|
-
transform: scale(1.05);
|
|
112
|
-
transition: 0.1s ease-in-out;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.card h2 {
|
|
116
|
-
font-size: 1.5rem;
|
|
117
|
-
margin: 0;
|
|
118
|
-
padding: 0;
|
|
119
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import './App.css';
|
|
2
|
-
|
|
3
|
-
const App = () => (
|
|
4
|
-
<div className="container">
|
|
5
|
-
<main>
|
|
6
|
-
<div className="logo">
|
|
7
|
-
<img
|
|
8
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png"
|
|
9
|
-
width="300"
|
|
10
|
-
alt="Modern.js Logo"
|
|
11
|
-
/>
|
|
12
|
-
</div>
|
|
13
|
-
<p className="description">
|
|
14
|
-
Get started by editing <code className="code">src/home/App.tsx</code>
|
|
15
|
-
</p>
|
|
16
|
-
<div className="grid">
|
|
17
|
-
<a href="https://modernjs.dev/docs/start" className="card">
|
|
18
|
-
<h2>Quick Start Tencent</h2>
|
|
19
|
-
</a>
|
|
20
|
-
<a href="https://modernjs.dev/docs/guides" className="card">
|
|
21
|
-
<h2>Handbook</h2>
|
|
22
|
-
</a>
|
|
23
|
-
<a href="https://modernjs.dev/docs/apis" className="card">
|
|
24
|
-
<h2>API Reference </h2>
|
|
25
|
-
</a>
|
|
26
|
-
<a
|
|
27
|
-
href="https://modernjs.dev/coming-soon"
|
|
28
|
-
target="_blank"
|
|
29
|
-
rel="noopener noreferrer"
|
|
30
|
-
className="card">
|
|
31
|
-
<h2>Community </h2>
|
|
32
|
-
</a>
|
|
33
|
-
</div>
|
|
34
|
-
</main>
|
|
35
|
-
<footer className="footer">
|
|
36
|
-
<a href="https://modernjs.dev" target="_blank" rel="noopener noreferrer">
|
|
37
|
-
Powered by Modern.js
|
|
38
|
-
</a>
|
|
39
|
-
</footer>
|
|
40
|
-
</div>
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
export default App;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1
|
package/tests/helper.ts
DELETED
package/tests/https.test.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { genHttpsOptions } from '../src/dev-tools/https';
|
|
2
|
-
|
|
3
|
-
describe('test dev tools', () => {
|
|
4
|
-
test('should get http cert correctly', async () => {
|
|
5
|
-
// Todo Interaction in CI
|
|
6
|
-
// const options = await genHttpsOptions(true);
|
|
7
|
-
// expect(options.key).toBeDefined();
|
|
8
|
-
// expect(options.cert).toBeDefined();
|
|
9
|
-
|
|
10
|
-
const useOpt = await genHttpsOptions({
|
|
11
|
-
key: 'foo',
|
|
12
|
-
cert: 'baz',
|
|
13
|
-
});
|
|
14
|
-
expect(useOpt.key).toBe('foo');
|
|
15
|
-
expect(useOpt.cert).toBe('baz');
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { LAUNCH_EDITOR_ENDPOINT } from '@modern-js/utils';
|
|
2
|
-
import { createLaunchEditorHandler } from '../src/dev-tools/launch-editor';
|
|
3
|
-
import { noop } from './helper';
|
|
4
|
-
|
|
5
|
-
describe('should createLaunchEditorHandler work correctly', () => {
|
|
6
|
-
const middleware = createLaunchEditorHandler();
|
|
7
|
-
|
|
8
|
-
it('should return 200 if filename exist', () => {
|
|
9
|
-
let response: any;
|
|
10
|
-
const context: any = {
|
|
11
|
-
url: LAUNCH_EDITOR_ENDPOINT,
|
|
12
|
-
query: {
|
|
13
|
-
filename: 'test.ts',
|
|
14
|
-
},
|
|
15
|
-
res: {
|
|
16
|
-
end: (data: any) => {
|
|
17
|
-
response = data;
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
middleware(context, noop);
|
|
22
|
-
expect(context.status).toBe(200);
|
|
23
|
-
expect(response).toBeUndefined();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should return 500 if filename not exist', () => {
|
|
27
|
-
let response: any;
|
|
28
|
-
const context: any = {
|
|
29
|
-
url: LAUNCH_EDITOR_ENDPOINT,
|
|
30
|
-
query: {
|
|
31
|
-
filename: '',
|
|
32
|
-
},
|
|
33
|
-
res: {
|
|
34
|
-
end: (data: any) => {
|
|
35
|
-
response = data;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
middleware(context, noop);
|
|
40
|
-
expect(context.status).toBe(500);
|
|
41
|
-
expect(typeof response === 'string').toBeTruthy();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should invoke next if not launch editor url', () => {
|
|
45
|
-
let response: any;
|
|
46
|
-
const context: any = {
|
|
47
|
-
url: '',
|
|
48
|
-
res: {
|
|
49
|
-
end: (data: any) => {
|
|
50
|
-
response = data;
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
middleware(context, noop);
|
|
55
|
-
expect(context.status).toBeUndefined();
|
|
56
|
-
expect(response).toBeUndefined();
|
|
57
|
-
});
|
|
58
|
-
});
|
package/tests/mock.test.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createMockHandler } from '../src/dev-tools/mock';
|
|
3
|
-
import getMockData, { getMatched } from '../src/dev-tools/mock/getMockData';
|
|
4
|
-
import { noop } from './helper';
|
|
5
|
-
|
|
6
|
-
describe('test dev tools', () => {
|
|
7
|
-
describe('should mock middleware work correctly', () => {
|
|
8
|
-
const pwd = path.join(__dirname, './fixtures/mock');
|
|
9
|
-
|
|
10
|
-
it('should return null if no config mock dir', () => {
|
|
11
|
-
expect(createMockHandler({ pwd: path.join(pwd, 'empty') })).toBeNull();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should return null if no api dir', () => {
|
|
15
|
-
expect(createMockHandler({ pwd: path.join(pwd, 'zero') })).toBeNull();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should return middleware if mock api exist', async () => {
|
|
19
|
-
const middleware = createMockHandler({ pwd: path.join(pwd, 'exist') });
|
|
20
|
-
|
|
21
|
-
expect(middleware).not.toBeNull();
|
|
22
|
-
|
|
23
|
-
let response: any;
|
|
24
|
-
const context: any = {
|
|
25
|
-
path: '/api/getInfo',
|
|
26
|
-
method: 'get',
|
|
27
|
-
res: {
|
|
28
|
-
setHeader: noop,
|
|
29
|
-
end: (data: any) => {
|
|
30
|
-
response = JSON.parse(data);
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
await middleware?.(context, noop);
|
|
35
|
-
expect(response).toEqual({
|
|
36
|
-
data: [1, 2, 3, 4],
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should not return middleware if mock api exist', async () => {
|
|
41
|
-
const middleware = createMockHandler({ pwd: path.join(pwd, 'exist') });
|
|
42
|
-
|
|
43
|
-
expect(middleware).not.toBeNull();
|
|
44
|
-
|
|
45
|
-
let response: any;
|
|
46
|
-
const context: any = {
|
|
47
|
-
path: '/api/getInfp',
|
|
48
|
-
method: 'get',
|
|
49
|
-
res: {
|
|
50
|
-
setHeader: noop,
|
|
51
|
-
end: (data: any) => {
|
|
52
|
-
response = JSON.parse(data);
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
await middleware?.(context, noop);
|
|
57
|
-
expect(response).toBeUndefined();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should get api list correctly', resolve => {
|
|
61
|
-
const apiList = getMockData(path.join(pwd, 'exist/config/mock/index.ts'));
|
|
62
|
-
expect(apiList.length).toBe(3);
|
|
63
|
-
|
|
64
|
-
const pathList = apiList.map(api => api.path);
|
|
65
|
-
expect(pathList).toEqual([
|
|
66
|
-
'/api/getInfo',
|
|
67
|
-
'/api/getExample',
|
|
68
|
-
'/api/addInfo',
|
|
69
|
-
]);
|
|
70
|
-
|
|
71
|
-
let response: any;
|
|
72
|
-
const context: any = {
|
|
73
|
-
res: {
|
|
74
|
-
setHeader: noop,
|
|
75
|
-
end: (data: any) => {
|
|
76
|
-
try {
|
|
77
|
-
response = JSON.parse(data);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
response = data;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
apiList[0].handler(context, noop as any);
|
|
86
|
-
expect(response).toEqual({
|
|
87
|
-
data: [1, 2, 3, 4],
|
|
88
|
-
});
|
|
89
|
-
apiList[1].handler(context, noop as any);
|
|
90
|
-
expect(response).toEqual({ id: 1 });
|
|
91
|
-
|
|
92
|
-
apiList[2].handler(context, noop as any);
|
|
93
|
-
setTimeout(() => {
|
|
94
|
-
expect(response).toBe('delay 2000ms');
|
|
95
|
-
resolve();
|
|
96
|
-
}, 3000);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('should match api correctly', () => {
|
|
100
|
-
const apiList = [
|
|
101
|
-
{
|
|
102
|
-
method: 'get',
|
|
103
|
-
path: '/api/getInfo',
|
|
104
|
-
handler: noop,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
method: 'get',
|
|
108
|
-
path: '/api/getExample',
|
|
109
|
-
handler: noop,
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
method: 'get',
|
|
113
|
-
path: '/api/addInfo',
|
|
114
|
-
handler: noop,
|
|
115
|
-
},
|
|
116
|
-
];
|
|
117
|
-
const matched = getMatched(
|
|
118
|
-
{ path: '/api/getInfo', method: 'get' } as any,
|
|
119
|
-
apiList,
|
|
120
|
-
);
|
|
121
|
-
expect(matched).toBe(apiList[0]);
|
|
122
|
-
|
|
123
|
-
const missMethod = getMatched(
|
|
124
|
-
{ path: '/api/getModern', method: 'post' } as any,
|
|
125
|
-
apiList,
|
|
126
|
-
);
|
|
127
|
-
expect(missMethod).toBeUndefined();
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should throw error if get mock file fail', resolve => {
|
|
131
|
-
try {
|
|
132
|
-
createMockHandler({ pwd: path.join(pwd, 'module-error') });
|
|
133
|
-
} catch (e: any) {
|
|
134
|
-
expect(e.message).toMatch('parsed failed!');
|
|
135
|
-
resolve();
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should throw error if get mock api has wrong type', resolve => {
|
|
140
|
-
try {
|
|
141
|
-
createMockHandler({ pwd: path.join(pwd, 'type-error') });
|
|
142
|
-
} catch (e: any) {
|
|
143
|
-
expect(e.message).toMatch(
|
|
144
|
-
'should be object or function, but got string',
|
|
145
|
-
);
|
|
146
|
-
resolve();
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
package/tests/server.test.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { defaultsConfig, NormalizedConfig } from '@modern-js/core';
|
|
3
|
-
import { ModernServerContext, NextFunction } from '@modern-js/types';
|
|
4
|
-
import { webpack } from 'webpack';
|
|
5
|
-
import { AGGRED_DIR, RUN_MODE } from '@modern-js/prod-server';
|
|
6
|
-
import createServer, { Server } from '../src';
|
|
7
|
-
import Watcher from '../src/dev-tools/watcher';
|
|
8
|
-
import { ModernDevServer } from '../src/server/dev-server';
|
|
9
|
-
|
|
10
|
-
jest.useFakeTimers();
|
|
11
|
-
(global as any).setImmediate = () => false;
|
|
12
|
-
const appDirectory = path.join(__dirname, './fixtures/pure');
|
|
13
|
-
describe('test dev server', () => {
|
|
14
|
-
test('should throw error when ', resolve => {
|
|
15
|
-
try {
|
|
16
|
-
createServer(null as any);
|
|
17
|
-
} catch (e: any) {
|
|
18
|
-
expect((e as Error).message).toBe(
|
|
19
|
-
'can not start mserver without options',
|
|
20
|
-
);
|
|
21
|
-
resolve();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('shoule get modern server instance', async () => {
|
|
26
|
-
const server = await createServer({
|
|
27
|
-
config: {
|
|
28
|
-
...defaultsConfig,
|
|
29
|
-
tools: {
|
|
30
|
-
devServer: {
|
|
31
|
-
proxy: {
|
|
32
|
-
'/simple': `http://localhost:8080`,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
} as any,
|
|
37
|
-
pwd: appDirectory,
|
|
38
|
-
dev: true,
|
|
39
|
-
});
|
|
40
|
-
expect(server instanceof Server).toBe(true);
|
|
41
|
-
await server.close();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('shoule get dev modern server instance', () => {
|
|
45
|
-
test('should init server correctly', async () => {
|
|
46
|
-
const server = await createServer({
|
|
47
|
-
config: defaultsConfig as NormalizedConfig,
|
|
48
|
-
pwd: appDirectory,
|
|
49
|
-
dev: true,
|
|
50
|
-
});
|
|
51
|
-
const modernServer = (server as any).server;
|
|
52
|
-
|
|
53
|
-
const {
|
|
54
|
-
pwd,
|
|
55
|
-
distDir,
|
|
56
|
-
workDir,
|
|
57
|
-
conf,
|
|
58
|
-
handlers,
|
|
59
|
-
isDev,
|
|
60
|
-
staticGenerate,
|
|
61
|
-
presetRoutes,
|
|
62
|
-
} = modernServer;
|
|
63
|
-
expect(pwd).toBe(appDirectory);
|
|
64
|
-
expect(distDir).toBe(path.join(appDirectory, 'dist'));
|
|
65
|
-
expect(workDir).toBe(appDirectory);
|
|
66
|
-
expect(conf).toBe(defaultsConfig);
|
|
67
|
-
expect(handlers).toBeDefined();
|
|
68
|
-
expect(isDev).toBeFalsy();
|
|
69
|
-
expect(staticGenerate).toBeFalsy();
|
|
70
|
-
expect(presetRoutes).toBeUndefined();
|
|
71
|
-
await server.close();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('should add handler correctly', async () => {
|
|
75
|
-
const server = await createServer({
|
|
76
|
-
config: defaultsConfig as NormalizedConfig,
|
|
77
|
-
pwd: appDirectory,
|
|
78
|
-
dev: true,
|
|
79
|
-
});
|
|
80
|
-
const modernServer = (server as any).server;
|
|
81
|
-
|
|
82
|
-
const len = modernServer.handlers.length;
|
|
83
|
-
|
|
84
|
-
const syncHandler = (ctx: ModernServerContext, next: NextFunction) => {
|
|
85
|
-
console.info(ctx.url);
|
|
86
|
-
next();
|
|
87
|
-
};
|
|
88
|
-
modernServer.addHandler(syncHandler);
|
|
89
|
-
|
|
90
|
-
const newLen = modernServer.handlers.length;
|
|
91
|
-
expect(len + 1).toBe(newLen);
|
|
92
|
-
expect(modernServer.handlers[newLen - 1]).not.toBe(syncHandler);
|
|
93
|
-
|
|
94
|
-
const asyncHandler = async (
|
|
95
|
-
ctx: ModernServerContext,
|
|
96
|
-
next: NextFunction,
|
|
97
|
-
) => {
|
|
98
|
-
console.info(ctx.url);
|
|
99
|
-
next();
|
|
100
|
-
};
|
|
101
|
-
modernServer.addHandler(asyncHandler);
|
|
102
|
-
const nextLen = modernServer.handlers.length;
|
|
103
|
-
|
|
104
|
-
expect(newLen + 1).toBe(nextLen);
|
|
105
|
-
expect(modernServer.handlers[nextLen - 1]).toBe(asyncHandler);
|
|
106
|
-
await server.close();
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('should get request handler correctly', async () => {
|
|
110
|
-
const server = await createServer({
|
|
111
|
-
config: defaultsConfig as NormalizedConfig,
|
|
112
|
-
pwd: appDirectory,
|
|
113
|
-
dev: true,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const modernServer: any = (server as any).server;
|
|
117
|
-
const handler = modernServer.getRequestHandler();
|
|
118
|
-
expect(typeof handler === 'function').toBeTruthy();
|
|
119
|
-
await server.close();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('should get request handler correctly', async () => {
|
|
123
|
-
const server = await createServer({
|
|
124
|
-
config: defaultsConfig as NormalizedConfig,
|
|
125
|
-
pwd: appDirectory,
|
|
126
|
-
dev: true,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const modernServer: any = (server as any).server;
|
|
130
|
-
const handler = modernServer.getRequestHandler();
|
|
131
|
-
expect(typeof handler === 'function').toBeTruthy();
|
|
132
|
-
await server.close();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should invoke onrepack correctly', async () => {
|
|
136
|
-
const server = await createServer({
|
|
137
|
-
config: defaultsConfig as NormalizedConfig,
|
|
138
|
-
pwd: appDirectory,
|
|
139
|
-
dev: true,
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
const modernServer: ModernDevServer = (server as any).server;
|
|
143
|
-
modernServer.onRepack({ routes: [] });
|
|
144
|
-
|
|
145
|
-
expect((modernServer as any).router.matchers.length).toBe(0);
|
|
146
|
-
server.close();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('should invoke onserver change correctly', async () => {
|
|
150
|
-
const server = await createServer({
|
|
151
|
-
config: defaultsConfig as NormalizedConfig,
|
|
152
|
-
pwd: appDirectory,
|
|
153
|
-
dev: true,
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
const modernServer = (server as any).server;
|
|
157
|
-
modernServer.onServerChange({
|
|
158
|
-
filepath: path.join(appDirectory, AGGRED_DIR.mock),
|
|
159
|
-
});
|
|
160
|
-
expect(modernServer.mockHandler).not.toBeNull();
|
|
161
|
-
|
|
162
|
-
modernServer.onServerChange({
|
|
163
|
-
filepath: path.join(appDirectory, 'index.js'),
|
|
164
|
-
});
|
|
165
|
-
expect(modernServer.mockHandler).not.toBeNull();
|
|
166
|
-
server.close();
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('should compiler work correctly', async () => {
|
|
170
|
-
const compiler = webpack({});
|
|
171
|
-
const server = await createServer({
|
|
172
|
-
config: defaultsConfig as NormalizedConfig,
|
|
173
|
-
pwd: appDirectory,
|
|
174
|
-
dev: true,
|
|
175
|
-
compiler,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
expect(server).toBeDefined();
|
|
179
|
-
server.close();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
test('should multi compiler work correctly', async () => {
|
|
183
|
-
const compiler = webpack([{}, { name: 'client' }]);
|
|
184
|
-
const server = await createServer({
|
|
185
|
-
config: defaultsConfig as NormalizedConfig,
|
|
186
|
-
pwd: appDirectory,
|
|
187
|
-
dev: true,
|
|
188
|
-
compiler,
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
expect(server).toBeDefined();
|
|
192
|
-
server.close();
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
test('should watcher work well', async () => {
|
|
196
|
-
const devServer = await createServer({
|
|
197
|
-
config: defaultsConfig as NormalizedConfig,
|
|
198
|
-
pwd: appDirectory,
|
|
199
|
-
dev: true,
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
203
|
-
// @ts-expect-error
|
|
204
|
-
expect(devServer.server.watcher).toBeInstanceOf(Watcher);
|
|
205
|
-
await devServer.close();
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
describe('should split server work correctly', () => {
|
|
210
|
-
test('should init api server correctly', async () => {
|
|
211
|
-
const server = await createServer({
|
|
212
|
-
config: defaultsConfig as NormalizedConfig,
|
|
213
|
-
pwd: appDirectory,
|
|
214
|
-
dev: true,
|
|
215
|
-
apiOnly: true,
|
|
216
|
-
runMode: RUN_MODE.FULL,
|
|
217
|
-
});
|
|
218
|
-
const modernServer = (server as any).server;
|
|
219
|
-
modernServer.emitRouteHook('reset', {});
|
|
220
|
-
expect(modernServer.prepareWebHandler()).toBe(null);
|
|
221
|
-
await server.close();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('should init ssr server correctly', async () => {
|
|
225
|
-
const server = await createServer({
|
|
226
|
-
config: defaultsConfig as NormalizedConfig,
|
|
227
|
-
pwd: appDirectory,
|
|
228
|
-
dev: true,
|
|
229
|
-
ssrOnly: true,
|
|
230
|
-
runMode: RUN_MODE.FULL,
|
|
231
|
-
});
|
|
232
|
-
const modernServer = (server as any).server;
|
|
233
|
-
modernServer.emitRouteHook('reset', {});
|
|
234
|
-
expect(modernServer.prepareAPIHandler()).toBe(null);
|
|
235
|
-
await server.close();
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
});
|
package/tests/tsconfig.json
DELETED