Skip to content

Commit 8076211

Browse files
committed
Merge branch 'release/v0.8.0'
2 parents 96610eb + 3092a1b commit 8076211

File tree

5 files changed

+57
-36
lines changed

5 files changed

+57
-36
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
branches:
2+
except:
3+
- /^release/
14
language: node_js
25
node_js:
36
- "12"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "watcher",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "API and model watcher",
55
"engines": {
66
"node": ">=12"

test/tests/validations/stressValidator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ test('Stress validator by writing several files at once', async (): Promise<
4646
onEvent = jest.fn((eventName, eventPath): void => {
4747
validator.addFileToQueue({ targetPath: eventPath, type: eventName });
4848
});
49-
watcher.on('all', onEvent);
49+
watcher.on('all', (eventName, eventPath): void => {
50+
onEvent(eventName, eventPath);
51+
});
5052
};
5153
const jestOnReady = jest.fn(onReady);
5254
const watcherOptions: WatcherOptions = {

test/tests/validations/validator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ test('Basic validator flow', async (): Promise<void> => {
3838
onEvent = jest.fn((eventName, eventPath): void => {
3939
validator.addFileToQueue({ targetPath: eventPath, type: eventName });
4040
});
41-
watcher.on('all', onEvent);
41+
watcher.on('all', (eventName, eventPath): void => {
42+
onEvent(eventName, eventPath);
43+
});
4244
};
4345
const jestOnReady = jest.fn(onReady);
4446
const watcherOptions: WatcherOptions = {

test/tests/watcher/initWatchers.ts

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ const serverApiPath = path.resolve(serverPath, apiPath);
1111
const serverModelPath = path.resolve(serverPath, modelPath);
1212
const mainPath = path.resolve(__dirname, '../../mocks');
1313

14-
beforeEach(async (): Promise<void> => {
15-
await emptyFolder(serverPath);
16-
await ensureDir(serverApiPath);
17-
await ensureDir(serverModelPath);
18-
});
14+
beforeEach(
15+
async (): Promise<void> => {
16+
await emptyFolder(serverPath);
17+
await ensureDir(serverApiPath);
18+
await ensureDir(serverModelPath);
19+
},
20+
);
1921

2022
const apiFileContent = `import { Data } from '../model/ok';
2123
@@ -42,44 +44,47 @@ export interface Data {
4244
*/
4345
test('Unexisting server path will throw exception', async (): Promise<void> => {
4446
const wrongPath = '/wrong/path/to/server';
45-
await waitForExpect(async (): Promise<void> => {
46-
expect(initWatchers(wrongPath, wrongPath)).rejects.toBeInstanceOf(Error);
47-
});
47+
await waitForExpect(
48+
async (): Promise<void> => {
49+
expect(initWatchers(wrongPath, wrongPath)).rejects.toBeInstanceOf(Error);
50+
},
51+
);
4852
});
4953

5054
/**
5155
* Should work with existing server path and process files when added
5256
*/
5357
test('Basic watchers flow', async (): Promise<void> => {
5458
const watchers = await initWatchers(serverPath, mainPath);
55-
const handler = jest.fn((): void => {
59+
const handler: (
60+
eventName: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir',
61+
eventPath: string,
62+
) => void = jest.fn((): void => {
5663
// Empty function to check event handler
5764
});
5865
watchers.forEach((watcher): void => {
66+
watcher.on('all', (eventName, eventPath): void => {
67+
handler(eventName, eventPath);
68+
});
5969
watcher.on('all', handler);
6070
});
6171
const fileName = 'ok.ts';
6272
const serverApiFilePath = path.resolve(serverApiPath, fileName);
6373
const serverModelFilePath = path.resolve(serverModelPath, fileName);
6474
await writeFile(serverApiFilePath, apiFileContent);
6575
await writeFile(serverModelFilePath, modeFileContent);
66-
await waitForExpect(async (): Promise<void> => {
67-
expect(await exists(serverApiFilePath)).toBe(true);
68-
expect(await exists(serverModelFilePath)).toBe(true);
69-
expect(handler).toHaveBeenCalledWith(
70-
'add',
71-
serverApiFilePath,
72-
);
73-
expect(handler).toHaveBeenCalledWith(
74-
'add',
75-
serverModelFilePath,
76-
);
77-
});
76+
await waitForExpect(
77+
async (): Promise<void> => {
78+
expect(await exists(serverApiFilePath)).toBe(true);
79+
expect(await exists(serverModelFilePath)).toBe(true);
80+
expect(handler).toHaveBeenCalledWith('add', serverApiFilePath);
81+
expect(handler).toHaveBeenCalledWith('add', serverModelFilePath);
82+
},
83+
);
7884

79-
await Promise.all(watchers.map(w => w.close()));
85+
await Promise.all(watchers.map((w) => w.close()));
8086
});
8187

82-
8388
/**
8489
* When disabling jest, watchers should process files when added
8590
*/
@@ -91,19 +96,28 @@ test('Complete watchers flow', async (): Promise<void> => {
9196
const serverModelFilePath = path.resolve(serverModelPath, fileName);
9297
await writeFile(serverApiFilePath, apiFileContent);
9398
await writeFile(serverModelFilePath, modeFileContent);
94-
await waitForExpect(async (): Promise<void> => {
95-
expect(await exists(serverApiFilePath)).toBe(true);
96-
expect(await exists(serverModelFilePath)).toBe(true);
97-
});
99+
await waitForExpect(
100+
async (): Promise<void> => {
101+
expect(await exists(serverApiFilePath)).toBe(true);
102+
expect(await exists(serverModelFilePath)).toBe(true);
103+
},
104+
);
98105

99106
const proxyIndexPath = path.resolve(mainPath, proxyPath, 'api', 'index.ts');
100-
const modelResultingPath = path.resolve(mainPath, proxyPath, 'model', fileName);
107+
const modelResultingPath = path.resolve(
108+
mainPath,
109+
proxyPath,
110+
'model',
111+
fileName,
112+
);
101113

102-
await waitForExpect(async (): Promise<void> => {
103-
expect(await exists(proxyIndexPath)).toBe(true);
104-
expect(await exists(modelResultingPath)).toBe(true);
105-
});
114+
await waitForExpect(
115+
async (): Promise<void> => {
116+
expect(await exists(proxyIndexPath)).toBe(true);
117+
expect(await exists(modelResultingPath)).toBe(true);
118+
},
119+
);
106120

107121
setForceDisableJestDetection(false);
108-
await Promise.all(watchers.map(w => w.close()));
122+
await Promise.all(watchers.map((w) => w.close()));
109123
}, 10000);

0 commit comments

Comments
 (0)