@modern-js/server 1.4.9 → 1.4.12
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 +56 -0
- package/dist/js/modern/constants.js +1 -1
- 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-split.js +4 -4
- package/dist/js/modern/server/dev-server.js +2 -3
- package/dist/js/node/constants.js +1 -1
- 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-split.js +4 -4
- package/dist/js/node/server/dev-server.js +2 -3
- package/dist/types/dev-tools/watcher/index.d.ts +2 -2
- package/dist/types/server/dev-server-split.d.ts +2 -2
- package/dist/types/types.d.ts +1 -1
- package/package.json +10 -10
- 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 -231
package/tests/watcher.test.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { fs } from '@modern-js/utils';
|
|
3
|
-
import Watcher, { getWatchedFiles } from '../src/dev-tools/watcher';
|
|
4
|
-
import { StatsCache } from '../src/dev-tools/watcher/stats-cache';
|
|
5
|
-
|
|
6
|
-
jest.useRealTimers();
|
|
7
|
-
|
|
8
|
-
describe('watcher', () => {
|
|
9
|
-
jest.setTimeout(25000);
|
|
10
|
-
const pwd = path.join(__dirname, './fixtures/watch');
|
|
11
|
-
const serverDir = path.normalize(path.join(pwd, './tmp-server'));
|
|
12
|
-
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
if (fs.existsSync(serverDir)) {
|
|
15
|
-
fs.removeSync(serverDir);
|
|
16
|
-
}
|
|
17
|
-
fs.mkdirSync(serverDir);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterAll(() => {
|
|
21
|
-
fs.removeSync(serverDir);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// const writeFiles = (content: string, filepath: string) => {
|
|
25
|
-
// fs.writeFileSync(path.normalize(filepath), content, 'utf8');
|
|
26
|
-
// };
|
|
27
|
-
|
|
28
|
-
// TODO 容易导致 timeout,暂时注释掉
|
|
29
|
-
// test('should emit add', done => {
|
|
30
|
-
// const watcher = new Watcher();
|
|
31
|
-
// const callback = jest.fn();
|
|
32
|
-
|
|
33
|
-
// const watchDir = path.join(serverDir, 'add');
|
|
34
|
-
// fs.mkdirSync(watchDir);
|
|
35
|
-
|
|
36
|
-
// watcher.listen(
|
|
37
|
-
// [`${watchDir}/**/*`],
|
|
38
|
-
// {
|
|
39
|
-
// ignoreInitial: true,
|
|
40
|
-
// ignored: /api\/typings\/.*/,
|
|
41
|
-
// },
|
|
42
|
-
// async () => {
|
|
43
|
-
// try {
|
|
44
|
-
// callback();
|
|
45
|
-
// expect(callback).toHaveBeenCalledTimes(1);
|
|
46
|
-
// await watcher.close();
|
|
47
|
-
// } catch (e) {
|
|
48
|
-
// console.error(e);
|
|
49
|
-
// }
|
|
50
|
-
// done();
|
|
51
|
-
// },
|
|
52
|
-
// );
|
|
53
|
-
|
|
54
|
-
// setTimeout(() => writeFiles('test', path.join(watchDir, 'index.js')), 100);
|
|
55
|
-
// });
|
|
56
|
-
|
|
57
|
-
// TODO 容易导致 timeout,暂时注释掉
|
|
58
|
-
// test('should emit unlink', done => {
|
|
59
|
-
// const watcher = new Watcher();
|
|
60
|
-
|
|
61
|
-
// const callback = jest.fn();
|
|
62
|
-
// const watchDir = path.join(serverDir, 'unlink');
|
|
63
|
-
// fs.mkdirSync(watchDir);
|
|
64
|
-
|
|
65
|
-
// const filepath = path.join(watchDir, 'index.js');
|
|
66
|
-
// writeFiles('unlink', filepath);
|
|
67
|
-
|
|
68
|
-
// watcher.listen(
|
|
69
|
-
// [`${watchDir}/**/*`],
|
|
70
|
-
// {
|
|
71
|
-
// ignoreInitial: true,
|
|
72
|
-
// ignored: /api\/typings\/.*/,
|
|
73
|
-
// },
|
|
74
|
-
// async () => {
|
|
75
|
-
// callback();
|
|
76
|
-
// expect(callback).toHaveBeenCalledTimes(1);
|
|
77
|
-
// await watcher.close();
|
|
78
|
-
// done();
|
|
79
|
-
// },
|
|
80
|
-
// );
|
|
81
|
-
|
|
82
|
-
// setTimeout(() => {
|
|
83
|
-
// fs.removeSync(filepath);
|
|
84
|
-
// }, 100);
|
|
85
|
-
// });
|
|
86
|
-
|
|
87
|
-
// TODO 容易导致 timeout,暂时注释掉
|
|
88
|
-
// test('should emit change', done => {
|
|
89
|
-
// const watcher = new Watcher();
|
|
90
|
-
|
|
91
|
-
// const callback = jest.fn();
|
|
92
|
-
// const watchDir = path.join(serverDir, 'change');
|
|
93
|
-
// fs.mkdirSync(watchDir);
|
|
94
|
-
|
|
95
|
-
// const filepath = path.join(watchDir, 'index.js');
|
|
96
|
-
// writeFiles('start', filepath);
|
|
97
|
-
|
|
98
|
-
// watcher.listen(
|
|
99
|
-
// [`${watchDir}/**/*`],
|
|
100
|
-
// {
|
|
101
|
-
// ignoreInitial: true,
|
|
102
|
-
// ignored: /api\/typings\/.*/,
|
|
103
|
-
// },
|
|
104
|
-
// async () => {
|
|
105
|
-
// callback();
|
|
106
|
-
// expect(callback).toHaveBeenCalledTimes(1);
|
|
107
|
-
// await watcher.close();
|
|
108
|
-
// done();
|
|
109
|
-
// },
|
|
110
|
-
// );
|
|
111
|
-
|
|
112
|
-
// setTimeout(() => writeFiles('end', filepath), 100);
|
|
113
|
-
// });
|
|
114
|
-
|
|
115
|
-
test('should not emit change when typings file changed', done => {
|
|
116
|
-
const watcher = new Watcher();
|
|
117
|
-
const apiDir = path.normalize(path.join(pwd, './api'));
|
|
118
|
-
|
|
119
|
-
const callback = jest.fn();
|
|
120
|
-
|
|
121
|
-
if (fs.pathExistsSync(apiDir)) {
|
|
122
|
-
fs.removeSync(apiDir);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const clear = () => {
|
|
126
|
-
fs.removeSync(apiDir);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
fs.mkdirSync(path.normalize(path.join(apiDir, 'typings')), {
|
|
130
|
-
recursive: true,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
watcher.listen(
|
|
134
|
-
[`${apiDir}/**/*`],
|
|
135
|
-
{
|
|
136
|
-
ignoreInitial: true,
|
|
137
|
-
ignored: /api\/typings\/.*/,
|
|
138
|
-
},
|
|
139
|
-
callback,
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
setTimeout(async () => {
|
|
143
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
144
|
-
await watcher.close();
|
|
145
|
-
clear();
|
|
146
|
-
done();
|
|
147
|
-
}, 1000);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('test watcher', () => {
|
|
152
|
-
let watcher: any;
|
|
153
|
-
const baseDir = path.join(__dirname, 'fixtures');
|
|
154
|
-
const watchDir = path.join(baseDir, 'watch/**');
|
|
155
|
-
const filepath = path.join(baseDir, 'watch', 'index.ts');
|
|
156
|
-
const filepatha = path.join(baseDir, 'watch', 'a.ts');
|
|
157
|
-
const txt = path.join(baseDir, 'watch', 'stats.txt');
|
|
158
|
-
|
|
159
|
-
afterEach(() => {
|
|
160
|
-
if (watcher) {
|
|
161
|
-
watcher.close();
|
|
162
|
-
}
|
|
163
|
-
fs.writeFileSync(txt, '1');
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should create watcher instance correctly', resolve => {
|
|
167
|
-
watcher = new Watcher();
|
|
168
|
-
expect(watcher.dependencyTree).toBeNull();
|
|
169
|
-
watcher.createDepTree();
|
|
170
|
-
expect(watcher.dependencyTree).not.toBeNull();
|
|
171
|
-
|
|
172
|
-
expect(watcher.watcher).toBeUndefined();
|
|
173
|
-
watcher.listen([watchDir], {}, () => {
|
|
174
|
-
// empty
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(watcher.watcher).toBeDefined();
|
|
178
|
-
require(filepath);
|
|
179
|
-
expect(watcher.dependencyTree.getNode(filepath)).toBeUndefined();
|
|
180
|
-
watcher.updateDepTree();
|
|
181
|
-
expect(watcher.dependencyTree.getNode(filepath)).toBeDefined();
|
|
182
|
-
watcher.cleanDepCache(filepath);
|
|
183
|
-
expect(watcher.dependencyTree.getNode(filepath)).toBeDefined();
|
|
184
|
-
|
|
185
|
-
jest.resetModules();
|
|
186
|
-
watcher.updateDepTree();
|
|
187
|
-
expect(watcher.dependencyTree.getNode(filepath)).toBeUndefined();
|
|
188
|
-
|
|
189
|
-
setTimeout(() => {
|
|
190
|
-
const fl = getWatchedFiles(watcher.watcher);
|
|
191
|
-
expect(fl.includes(filepatha)).toBeTruthy();
|
|
192
|
-
expect(fl.includes(filepath)).toBeTruthy();
|
|
193
|
-
expect(fl.includes(txt)).toBeTruthy();
|
|
194
|
-
resolve();
|
|
195
|
-
}, 1000);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
it('should stats cache instance work correctly', () => {
|
|
199
|
-
const statsCache = new StatsCache();
|
|
200
|
-
|
|
201
|
-
// should not exist false before add
|
|
202
|
-
expect(statsCache.has(txt)).toBeFalsy();
|
|
203
|
-
|
|
204
|
-
// should exist true after add
|
|
205
|
-
statsCache.add([txt]);
|
|
206
|
-
expect(statsCache.has(txt)).toBeTruthy();
|
|
207
|
-
|
|
208
|
-
// should diff correctly
|
|
209
|
-
fs.writeFileSync(txt, 'foo');
|
|
210
|
-
expect(statsCache.isDiff(txt)).toBeTruthy();
|
|
211
|
-
|
|
212
|
-
// should not diff if not refresh
|
|
213
|
-
fs.writeFileSync(txt, '1');
|
|
214
|
-
expect(statsCache.isDiff(txt)).toBeFalsy();
|
|
215
|
-
|
|
216
|
-
// should diff after refresh
|
|
217
|
-
fs.writeFileSync(txt, 'foo');
|
|
218
|
-
statsCache.refresh(txt);
|
|
219
|
-
fs.writeFileSync(txt, '1');
|
|
220
|
-
expect(statsCache.isDiff(txt)).toBeTruthy();
|
|
221
|
-
|
|
222
|
-
// should diff when content change
|
|
223
|
-
statsCache.refresh(txt);
|
|
224
|
-
fs.writeFileSync(txt, '2');
|
|
225
|
-
expect(statsCache.isDiff(txt)).toBeTruthy();
|
|
226
|
-
|
|
227
|
-
// should not exist after del
|
|
228
|
-
statsCache.del(txt);
|
|
229
|
-
expect(statsCache.has(txt)).toBeFalsy();
|
|
230
|
-
});
|
|
231
|
-
});
|