|
| 1 | +on: |
| 2 | + schedule: |
| 3 | + - cron: '0 */4 * * *' |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + paths: |
| 9 | + - .github/workflows/e2e-fsevents-workflow.yml |
| 10 | + - scripts/e2e-setup-ci.sh |
| 11 | + |
| 12 | +name: 'E2E FSEvents' |
| 13 | +jobs: |
| 14 | + chore: |
| 15 | + name: 'Validating FSEvents' |
| 16 | + runs-on: macos-latest |
| 17 | + |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@master |
| 20 | + |
| 21 | + - name: 'Use Node.js 10.x' |
| 22 | + uses: actions/setup-node@master |
| 23 | + with: |
| 24 | + node-version: 10.x |
| 25 | + |
| 26 | + - name: 'Build the standard bundle' |
| 27 | + run: | |
| 28 | + node ./scripts/run-yarn.js build:cli |
| 29 | +
|
| 30 | + - name: 'Running the integration test (FSEvents ^1)' |
| 31 | + run: | |
| 32 | + source scripts/e2e-setup-ci.sh |
| 33 | + yarn init |
| 34 | + yarn add fsevents@^1 |
| 35 | +
|
| 36 | + cat > test.js <<EOT |
| 37 | + const assert = require('assert'); |
| 38 | + const fsevents = require('fsevents'); |
| 39 | + const fs = require('fs'); |
| 40 | + const path = require('path'); |
| 41 | +
|
| 42 | + async function sleep(n) { |
| 43 | + return new Promise(resolve => { |
| 44 | + setTimeout(resolve, n); |
| 45 | + }); |
| 46 | + } |
| 47 | +
|
| 48 | + async function runTestOn(dir, fileName) { |
| 49 | + const file = path.join(dir, fileName); |
| 50 | +
|
| 51 | + const events = []; |
| 52 | + const watcher = fsevents(dir); |
| 53 | + watcher.on('change', (...args) => events.push(args)); |
| 54 | + watcher.start(); |
| 55 | +
|
| 56 | + async function main() { |
| 57 | + await sleep(1000); |
| 58 | + fs.writeFileSync(file, ''); |
| 59 | + await sleep(1000); |
| 60 | +
|
| 61 | + if (events.length === 0) |
| 62 | + throw new Error('No events recorded'); |
| 63 | +
|
| 64 | + for (const [p] of events) { |
| 65 | + if (!p.startsWith(dir)) { |
| 66 | + throw new Error(p); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | +
|
| 71 | + try { |
| 72 | + return await main(); |
| 73 | + } finally { |
| 74 | + watcher.stop(); |
| 75 | + } |
| 76 | + } |
| 77 | +
|
| 78 | + async function registerTest(dir, fileName) { |
| 79 | + try { |
| 80 | + await runTestOn(dir, fileName); |
| 81 | + console.log('Succeeded test for ' + dir); |
| 82 | + } catch (error) { |
| 83 | + console.log('Failed test for ' + dir + ': ' + error.message); |
| 84 | + process.exitCode = 1; |
| 85 | + } |
| 86 | + } |
| 87 | +
|
| 88 | + Promise.resolve().then(() => { |
| 89 | + return registerTest(process.cwd(), 'hello'); |
| 90 | + }).then(() => { |
| 91 | + return registerTest(process.cwd() + '/\$\$virtual/foo/0', 'world'); |
| 92 | + }); |
| 93 | + EOT |
| 94 | +
|
| 95 | + yarn node ./test.js |
| 96 | +
|
| 97 | + - name: 'Running the integration test (FSEvents latest)' |
| 98 | + run: | |
| 99 | + source scripts/e2e-setup-ci.sh |
| 100 | + yarn init |
| 101 | + yarn add fsevents@latest |
| 102 | +
|
| 103 | + cat > test.js <<EOT |
| 104 | + const assert = require('assert'); |
| 105 | + const fsevents = require('fsevents'); |
| 106 | + const fs = require('fs'); |
| 107 | + const path = require('path'); |
| 108 | +
|
| 109 | + async function sleep(n) { |
| 110 | + return new Promise(resolve => { |
| 111 | + setTimeout(resolve, n); |
| 112 | + }); |
| 113 | + } |
| 114 | +
|
| 115 | + async function runTestOn(dir, fileName) { |
| 116 | + const file = path.join(dir, fileName); |
| 117 | +
|
| 118 | + const events = []; |
| 119 | + const stop = fsevents.watch(dir, (...args) => events.push(args)); |
| 120 | +
|
| 121 | + async function main() { |
| 122 | + await sleep(1000); |
| 123 | + fs.writeFileSync(file, ''); |
| 124 | + await sleep(1000); |
| 125 | +
|
| 126 | + if (events.length === 0) |
| 127 | + throw new Error('No events recorded'); |
| 128 | +
|
| 129 | + for (const [p] of events) { |
| 130 | + if (!p.startsWith(dir)) { |
| 131 | + throw new Error(p); |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | +
|
| 136 | + try { |
| 137 | + return await main(); |
| 138 | + } finally { |
| 139 | + await stop(); |
| 140 | + } |
| 141 | + } |
| 142 | +
|
| 143 | + async function registerTest(dir, fileName) { |
| 144 | + try { |
| 145 | + await runTestOn(dir, fileName); |
| 146 | + console.log('Succeeded test for ' + dir); |
| 147 | + } catch (error) { |
| 148 | + console.log('Failed test for ' + dir + ': ' + error.message); |
| 149 | + process.exitCode = 1; |
| 150 | + } |
| 151 | + } |
| 152 | +
|
| 153 | + Promise.resolve().then(() => { |
| 154 | + return registerTest(process.cwd(), 'hello'); |
| 155 | + }).then(() => { |
| 156 | + return registerTest(process.cwd() + '/\$\$virtual/foo/0', 'world'); |
| 157 | + }); |
| 158 | + EOT |
| 159 | +
|
| 160 | + yarn node ./test.js |
0 commit comments