-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
185 lines (146 loc) Β· 5.53 KB
/
e2e-fsevents-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
on:
schedule:
- cron: '0 */4 * * *'
push:
branches:
- master
- mael/fsevents-fix
pull_request:
paths:
- .github/actions/prepare/action.yml
- .github/workflows/e2e-fsevents-workflow.yml
- scripts/e2e-setup-ci.sh
name: 'E2E FSEvents'
jobs:
chore:
name: 'Validating FSEvents'
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: 'Running the integration test (FSEvents ^1)'
run: |
source scripts/e2e-setup-ci.sh
yarn init -w
mkdir packages/foo
yarn packages/foo init
yarn packages/foo add -P lodash
yarn add fsevents@^1 node-gyp foo@workspace:0.0.0
cat > test.js <<EOT
const assert = require('assert');
const fsevents = require('fsevents');
const fs = require('fs');
const path = require('path');
async function sleep(n) {
return new Promise(resolve => {
setTimeout(resolve, n);
});
}
async function runTestOn(dir, fileName, expectation) {
expectation.sort();
const file = path.join(dir, fileName);
const events = [];
const watcher = fsevents(dir);
watcher.on('change', (...args) => events.push(args));
watcher.start();
async function main() {
await sleep(1000);
fs.writeFileSync(file, '');
await sleep(1000);
if (events.length === 0)
throw new Error('No events recorded');
const pList = events.map(pEntry => pEntry[0]);
pList.sort();
const currentJson = JSON.stringify(pList);
const expectedJson = JSON.stringify(expectation);
if (currentJson !== expectedJson) {
throw new Error('Expectation mismatch:\n - ' + currentJson + '\n - ' + expectedJson);
}
}
try {
return await main();
} finally {
watcher.stop();
}
}
async function registerTest(dir, fileName, expectation) {
try {
await runTestOn(dir, fileName, expectation);
console.log('Succeeded test for ' + dir);
} catch (error) {
console.log('Failed test for ' + dir + ': ' + error.message);
process.exitCode = 1;
}
}
const rootDir = __dirname;
const virtualFooDir = path.dirname(require.resolve('foo/package.json'));
Promise.resolve().then(async () => {
await registerTest(rootDir, 'hello', [rootDir + '/hello']);
await registerTest(rootDir + '/__virtual__/1234/0', 'world', [rootDir + '/__virtual__/1234/0/world']);
await registerTest(rootDir, 'packages/foo/hello', [rootDir + '/packages/foo/hello', virtualFooDir + '/hello']);
});
EOT
yarn node ./test.js
- name: 'Running the integration test (FSEvents latest)'
run: |
source scripts/e2e-setup-ci.sh
yarn init -w
mkdir packages/foo
yarn packages/foo init
yarn packages/foo add -P lodash
yarn add fsevents@latest foo@workspace:0.0.0
cat > test.js <<EOT
const assert = require('assert');
const fsevents = require('fsevents');
const fs = require('fs');
const path = require('path');
async function sleep(n) {
return new Promise(resolve => {
setTimeout(resolve, n);
});
}
async function runTestOn(dir, fileName, expectation) {
expectation.sort();
const file = path.join(dir, fileName);
const events = [];
const stop = fsevents.watch(dir, (...args) => events.push(args));
async function main() {
await sleep(1000);
fs.writeFileSync(file, '');
await sleep(1000);
if (events.length === 0)
throw new Error('No events recorded');
const pList = events.map(pEntry => pEntry[0]);
pList.sort();
const currentJson = JSON.stringify(pList);
const expectedJson = JSON.stringify(expectation);
if (currentJson !== expectedJson) {
throw new Error('Expectation mismatch:\n - ' + currentJson + '\n - ' + expectedJson);
}
}
try {
return await main();
} finally {
await stop();
}
}
async function registerTest(dir, fileName, expectation) {
try {
await runTestOn(dir, fileName, expectation);
console.log('Succeeded test for ' + dir);
} catch (error) {
console.log('Failed test for ' + dir + ': ' + error.message);
process.exitCode = 1;
}
}
const rootDir = __dirname;
const virtualFooDir = path.dirname(require.resolve('foo/package.json'));
Promise.resolve().then(async () => {
await registerTest(rootDir, 'hello', [rootDir + '/hello']);
await registerTest(rootDir + '/__virtual__/1234/0', 'world', [rootDir + '/__virtual__/1234/0/world']);
await registerTest(rootDir, 'packages/foo/hello', [rootDir + '/packages/foo/hello', virtualFooDir + '/hello']);
});
EOT
yarn node ./test.js
if: |
success() || failure()