Best JavaScript code snippet using playwright-internal
test.js
Source:test.js
...134 await exec(`rm`, ["-rf", "/tmp/foo*"]);135});136test("spawn", async () => {137 const tmpDir = await getTmpDir();138 const watcher = await createWatcher([tmpDir]);139 watcher.dispose();140});141test("create file", async () => {142 const tmpDir = await getTmpDir();143 const watcher = await createWatcher([tmpDir]);144 await writeFile(`${tmpDir}/abc.txt`, "");145 await waitForExpect(() => {146 expect(watcher.stdout).toBe(`${tmpDir}/abc.txt,CREATE147${tmpDir}/abc.txt,CLOSE_WRITE148`);149 });150 watcher.dispose();151});152test("create file - nested", async () => {153 const tmpDir = await getTmpDir();154 await mkdir(`${tmpDir}/a`);155 const watcher = await createWatcher([tmpDir]);156 await writeFile(`${tmpDir}/a/abc.txt`, "");157 await waitForExpect(() => {158 expect(watcher.stdout).toBe(`${tmpDir}/a/abc.txt,CREATE159${tmpDir}/a/abc.txt,CLOSE_WRITE160`);161 });162 watcher.dispose();163});164test("create file - multiple", async () => {165 const tmpDir = await getTmpDir();166 const watcher = await createWatcher([tmpDir]);167 await writeFile(`${tmpDir}/1.txt`, "");168 await writeFile(`${tmpDir}/2.txt`, "");169 await waitForExpect(() => {170 expect(watcher.stdout).toBe(`${tmpDir}/1.txt,CREATE171${tmpDir}/1.txt,CLOSE_WRITE172${tmpDir}/2.txt,CREATE173${tmpDir}/2.txt,CLOSE_WRITE174`);175 });176 watcher.dispose();177});178test("modify file", async () => {179 const tmpDir = await getTmpDir();180 await writeFile(`${tmpDir}/abc.txt`, "");181 const watcher = await createWatcher([tmpDir]);182 await appendFile(`${tmpDir}/abc.txt`, "abc");183 await waitForExpect(() => {184 expect(watcher.stdout).toBe(`${tmpDir}/abc.txt,MODIFY185${tmpDir}/abc.txt,CLOSE_WRITE186`);187 });188 watcher.dispose();189});190test("modify file - nested", async () => {191 const tmpDir = await getTmpDir();192 await mkdir(`${tmpDir}/a`);193 await writeFile(`${tmpDir}/a/abc.txt`, "");194 const watcher = await createWatcher([tmpDir]);195 await writeFile(`${tmpDir}/a/abc.txt`, "");196 await waitForExpect(() => {197 expect(watcher.stdout).toBe(`${tmpDir}/a/abc.txt,MODIFY198${tmpDir}/a/abc.txt,CLOSE_WRITE199`);200 });201 watcher.dispose();202});203test("copy file", async () => {204 const tmpDir = await getTmpDir();205 await writeFile(`${tmpDir}/1.txt`, "");206 const watcher = await createWatcher([tmpDir]);207 await copyFile(`${tmpDir}/1.txt`, `${tmpDir}/2.txt`);208 await waitForExpect(() => {209 expect(watcher.stdout).toBe(`${tmpDir}/2.txt,CREATE210${tmpDir}/2.txt,MODIFY211${tmpDir}/2.txt,ATTRIB212${tmpDir}/2.txt,CLOSE_WRITE213`);214 });215 watcher.dispose();216});217test("remove file", async () => {218 const tmpDir = await getTmpDir();219 await writeFile(`${tmpDir}/abc.txt`, "");220 const watcher = await createWatcher([tmpDir]);221 await rm(`${tmpDir}/abc.txt`);222 await waitForExpect(() => {223 expect(watcher.stdout).toBe(`${tmpDir}/abc.txt,DELETE224`);225 });226 watcher.dispose();227});228test("remove file - nested", async () => {229 const tmpDir = await getTmpDir();230 await mkdir(`${tmpDir}/a`);231 await writeFile(`${tmpDir}/a/abc.txt`, "");232 const watcher = await createWatcher([tmpDir]);233 await rm(`${tmpDir}/a/abc.txt`);234 await waitForExpect(() => {235 expect(watcher.stdout).toBe(`${tmpDir}/a/abc.txt,DELETE236`);237 });238 watcher.dispose();239});240test("create folder", async () => {241 const tmpDir = await getTmpDir();242 const watcher = await createWatcher([tmpDir]);243 await mkdir(`${tmpDir}/a`);244 await waitForExpect(() => {245 expect(watcher.stdout).toBe(`${tmpDir}/a,CREATE_DIR246`);247 });248 watcher.dispose();249});250test("copy folder", async () => {251 const tmpDir = await getTmpDir();252 await mkdir(`${tmpDir}/1`);253 const watcher = await createWatcher([tmpDir]);254 await exec("cp", ["-r", `${tmpDir}/1`, `${tmpDir}/2`]);255 await waitForExpect(() => {256 expect(watcher.stdout).toContain(`${tmpDir}/2,CREATE_DIR`);257 });258 watcher.dispose();259});260test("remove folder", async () => {261 const tmpDir = await getTmpDir();262 await mkdir(`${tmpDir}/a`);263 const watcher = await createWatcher([tmpDir]);264 await rm(`${tmpDir}/a`, { recursive: true });265 await waitForExpect(() => {266 expect(watcher.stdout).toBe(`${tmpDir}/a,DELETE_DIR267`);268 });269 watcher.dispose();270});271test("remove nested folder", async () => {272 const tmpDir = await getTmpDir();273 await mkdir(`${tmpDir}/a/b`, { recursive: true });274 const watcher = await createWatcher([tmpDir]);275 await rm(`${tmpDir}/a/b`, { recursive: true });276 await waitForExpect(() => {277 expect(watcher.stdout).toBe(`${tmpDir}/a/b,DELETE_DIR278`);279 });280 watcher.dispose();281});282test("remove folder - nested deeply", async () => {283 const tmpDir = await getTmpDir();284 await mkdir(`${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1`, { recursive: true });285 const watcher = await createWatcher([tmpDir]);286 await rm(`${tmpDir}/1`, { recursive: true });287 await waitForExpect(() => {288 expect(watcher.stdout)289 .toBe(`${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,DELETE_DIR290${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1,DELETE_DIR291${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1,DELETE_DIR292${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1,DELETE_DIR293${tmpDir}/1/1/1/1/1/1/1/1/1/1/1,DELETE_DIR294${tmpDir}/1/1/1/1/1/1/1/1/1/1,DELETE_DIR295${tmpDir}/1/1/1/1/1/1/1/1/1,DELETE_DIR296${tmpDir}/1/1/1/1/1/1/1/1,DELETE_DIR297${tmpDir}/1/1/1/1/1/1/1,DELETE_DIR298${tmpDir}/1/1/1/1/1/1,DELETE_DIR299${tmpDir}/1/1/1/1/1,DELETE_DIR300${tmpDir}/1/1/1/1,DELETE_DIR301${tmpDir}/1/1/1,DELETE_DIR302${tmpDir}/1/1,DELETE_DIR303${tmpDir}/1,DELETE_DIR304`);305 });306 watcher.dispose();307});308test("add and remove file", async () => {309 const tmpDir = await getTmpDir();310 const watcher = await createWatcher([tmpDir]);311 await writeFile(`${tmpDir}/abc.txt`, "");312 await rm(`${tmpDir}/abc.txt`);313 await waitForExpect(() => {314 expect(watcher.stdout).toBe(`${tmpDir}/abc.txt,CREATE315${tmpDir}/abc.txt,CLOSE_WRITE316${tmpDir}/abc.txt,DELETE317`);318 });319 watcher.dispose();320});321test("file with spaces", async () => {322 const tmpDir = await getTmpDir();323 const watcher = await createWatcher([tmpDir]);324 await writeFile(`${tmpDir}/a b c.txt`, "");325 await waitForExpect(() => {326 expect(watcher.stdout).toBe(`"${tmpDir}/a b c.txt",CREATE327"${tmpDir}/a b c.txt",CLOSE_WRITE328`);329 });330 watcher.dispose();331});332test("csvWatcher: file with spaces", async () => {333 const tmpDir = await getTmpDir();334 const watcher = await createCsvWatcher([tmpDir]);335 await writeFile(`${tmpDir}/a b c.txt`, "");336 await waitForExpect(() => {337 expect(watcher.stdout).toEqual([338 {339 operation: "CREATE",340 path: `${tmpDir}/a b c.txt`,341 },342 {343 operation: "CLOSE_WRITE",344 path: `${tmpDir}/a b c.txt`,345 },346 ]);347 });348 watcher.dispose();349});350test("file with comma", async () => {351 const tmpDir = await getTmpDir();352 const watcher = await createWatcher([tmpDir]);353 await writeFile(`${tmpDir}/a,b,c.txt`, "");354 await waitForExpect(() => {355 expect(watcher.stdout).toBe(`"${tmpDir}/a,b,c.txt",CREATE356"${tmpDir}/a,b,c.txt",CLOSE_WRITE357`);358 });359 watcher.dispose();360});361test("csvWatcher: file with comma", async () => {362 const tmpDir = await getTmpDir();363 const watcher = await createCsvWatcher([tmpDir]);364 await writeFile(`${tmpDir}/a,b,c.txt`, "");365 await waitForExpect(() => {366 expect(watcher.stdout).toEqual([367 {368 operation: "CREATE",369 path: `${tmpDir}/a,b,c.txt`,370 },371 {372 operation: "CLOSE_WRITE",373 path: `${tmpDir}/a,b,c.txt`,374 },375 ]);376 });377 watcher.dispose();378});379test("file with unicode", async () => {380 const tmpDir = await getTmpDir();381 const watcher = await createWatcher([tmpDir]);382 await writeFile(`${tmpDir}/ã¯`, "");383 await waitForExpect(() => {384 expect(watcher.stdout).toBe(`${tmpDir}/ã¯,CREATE385${tmpDir}/ã¯,CLOSE_WRITE386`);387 });388 watcher.dispose();389});390test("file with emoji", async () => {391 const tmpDir = await getTmpDir();392 const watcher = await createWatcher([tmpDir]);393 await writeFile(`${tmpDir}/ðºï¸`, "");394 await waitForExpect(() => {395 expect(watcher.stdout).toBe(`${tmpDir}/ðºï¸,CREATE396${tmpDir}/ðºï¸,CLOSE_WRITE397`);398 });399 watcher.dispose();400});401test("csvWatcher: file with emoji", async () => {402 const tmpDir = await getTmpDir();403 const watcher = await createCsvWatcher([tmpDir]);404 await writeFile(`${tmpDir}/ðºï¸`, "");405 await waitForExpect(() => {406 expect(watcher.stdout).toEqual([407 {408 operation: "CREATE",409 path: `${tmpDir}/ðºï¸`,410 },411 {412 operation: "CLOSE_WRITE",413 path: `${tmpDir}/ðºï¸`,414 },415 ]);416 });417 watcher.dispose();418});419test("folder with greek letters", async () => {420 const tmpDir = await getTmpDir();421 const watcher = await createWatcher([tmpDir]);422 await mkdir(`${tmpDir}/Σ Τ Î¥ Φ Χ Ψ`);423 await waitForExpect(() => {424 expect(watcher.stdout).toBe(`"${tmpDir}/Σ Τ Î¥ Φ Χ Ψ",CREATE_DIR425`);426 });427 watcher.clear();428 await writeFile(`${tmpDir}/Σ Τ Î¥ Φ Χ Ψ/1.txt`, "");429 await waitForExpect(() => {430 expect(watcher.stdout).toBe(`"${tmpDir}/Σ Τ Î¥ Φ Χ Ψ/1.txt",CREATE431"${tmpDir}/Σ Τ Î¥ Φ Χ Ψ/1.txt",CLOSE_WRITE432`);433 });434 watcher.dispose();435});436test("file with newline", async () => {437 const tmpDir = await getTmpDir();438 const watcher = await createWatcher([tmpDir]);439 await writeFile(`${tmpDir}/a\nb\nc.txt`, "");440 await waitForExpect(() => {441 expect(watcher.stdout).toBe(`"${tmpDir}/a\nb\nc.txt",CREATE442"${tmpDir}/a\nb\nc.txt",CLOSE_WRITE443`);444 });445 watcher.dispose();446});447test("csvWatcher: file with newline", async () => {448 const tmpDir = await getTmpDir();449 const watcher = await createCsvWatcher([tmpDir]);450 await writeFile(`${tmpDir}/a\nb\nc.txt`, "");451 await waitForExpect(() => {452 expect(watcher.stdout).toEqual([453 {454 operation: "CREATE",455 path: `${tmpDir}/a\nb\nc.txt`,456 },457 {458 operation: "CLOSE_WRITE",459 path: `${tmpDir}/a\nb\nc.txt`,460 },461 ]);462 });463 watcher.dispose();464});465test("file with quotes", async () => {466 const tmpDir = await getTmpDir();467 const watcher = await createWatcher([tmpDir]);468 await writeFile(`${tmpDir}/a"b"c.txt`, "");469 await waitForExpect(() => {470 expect(watcher.stdout).toBe(`"${tmpDir}/a""b""c.txt",CREATE471"${tmpDir}/a""b""c.txt",CLOSE_WRITE472`);473 });474 watcher.dispose();475});476test("csvWatcher: file with quotes", async () => {477 const tmpDir = await getTmpDir();478 const watcher = await createCsvWatcher([tmpDir]);479 await writeFile(`${tmpDir}/a"b"c.txt`, "");480 await waitForExpect(() => {481 expect(watcher.stdout).toEqual([482 {483 operation: "CREATE",484 path: `${tmpDir}/a"b"c.txt`,485 },486 {487 operation: "CLOSE_WRITE",488 path: `${tmpDir}/a"b"c.txt`,489 },490 ]);491 });492 watcher.dispose();493});494test("file with dot at start", async () => {495 const tmpDir = await getTmpDir();496 const watcher = await createWatcher([tmpDir]);497 await writeFile(`${tmpDir}/.abc.txt`, "");498 await waitForExpect(() => {499 expect(watcher.stdout).toBe(`${tmpDir}/.abc.txt,CREATE500${tmpDir}/.abc.txt,CLOSE_WRITE501`);502 });503 watcher.dispose();504});505test("move in - file", async () => {506 const tmpDir = await getTmpDir();507 const tmpDir2 = await getTmpDir();508 await writeFile(`${tmpDir2}/old.txt`, "");509 const watcher = await createWatcher([tmpDir]);510 await rename(`${tmpDir2}/old.txt`, `${tmpDir}/new.txt`);511 await waitForExpect(() => {512 expect(watcher.stdout).toBe(`${tmpDir}/new.txt,MOVED_TO513`);514 });515 watcher.dispose();516});517test("move in - folder", async () => {518 const tmpDir = await getTmpDir();519 const tmpDir2 = await getTmpDir();520 await mkdir(`${tmpDir2}/old`);521 const watcher = await createWatcher([tmpDir]);522 await rename(`${tmpDir2}/old`, `${tmpDir}/new`);523 await waitForExpect(() => {524 expect(watcher.stdout).toBe(`${tmpDir}/new,MOVED_TO_DIR525`);526 });527 watcher.dispose();528});529// test("move file", async () => {530// const tmpDir = await getTmpDir();531// await writeFile(`${tmpDir}/1.txt`, "");532// const watcher = await createWatcher([tmpDir]);533// await rename(`${tmpDir}/1.txt`, `${tmpDir}/2.txt`);534// // TODO should emit rename event535// await waitForExpect(() => {536// expect(watcher.stdout).toBe(`${tmpDir}/1.txt MOVED_FROM537// ${tmpDir}/2.txt MOVED_TO538// `);539// });540// watcher.dispose();541// });542test("move - file", async () => {543 const tmpDir = await getTmpDir();544 await writeFile(`${tmpDir}/old.txt`, "");545 const watcher = await createWatcher([tmpDir]);546 await rename(`${tmpDir}/old.txt`, `${tmpDir}/new.txt`);547 await waitForExpect(() => {548 expect(watcher.stdout).toBe(`${tmpDir}/old.txt,MOVED_FROM549${tmpDir}/new.txt,MOVED_TO550`);551 });552 watcher.dispose();553});554test("move folder", async () => {555 const tmpDir = await getTmpDir();556 await mkdir(`${tmpDir}/old`);557 const watcher = await createWatcher([tmpDir]);558 await rename(`${tmpDir}/old`, `${tmpDir}/new`);559 await writeFile(`${tmpDir}/new/abc.txt`, "");560 await waitForExpect(() => {561 expect(watcher.stdout).toBe(`${tmpDir}/old,MOVED_FROM_DIR562${tmpDir}/new,MOVED_TO_DIR563${tmpDir}/new/abc.txt,CREATE564${tmpDir}/new/abc.txt,CLOSE_WRITE565`);566 });567 watcher.dispose();568});569test("move - nested folder", async () => {570 const tmpDir = await getTmpDir();571 await mkdir(`${tmpDir}/1/1/1/1`, { recursive: true });572 const watcher = await createWatcher([tmpDir]);573 await rename(`${tmpDir}/1`, `${tmpDir}/2`);574 await writeFile(`${tmpDir}/2/2.txt`, "");575 await writeFile(`${tmpDir}/2/1/2.txt`, "");576 await writeFile(`${tmpDir}/2/1/1/2.txt`, "");577 await writeFile(`${tmpDir}/2/1/1/1/2.txt`, "");578 await waitForExpect(() => {579 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR580${tmpDir}/2,MOVED_TO_DIR581${tmpDir}/2/2.txt,CREATE582${tmpDir}/2/2.txt,CLOSE_WRITE583${tmpDir}/2/1/2.txt,CREATE584${tmpDir}/2/1/2.txt,CLOSE_WRITE585${tmpDir}/2/1/1/2.txt,CREATE586${tmpDir}/2/1/1/2.txt,CLOSE_WRITE587${tmpDir}/2/1/1/1/2.txt,CREATE588${tmpDir}/2/1/1/1/2.txt,CLOSE_WRITE589`);590 });591 watcher.dispose();592});593test("misc - move in file, then remove file", async () => {594 const tmpDir = await getTmpDir();595 const tmpDir2 = await getTmpDir();596 await writeFile(`${tmpDir2}/old.txt`, "");597 const watcher = await createWatcher([tmpDir]);598 await rename(`${tmpDir2}/old.txt`, `${tmpDir}/new.txt`);599 await rm(`${tmpDir}/new.txt`);600 await waitForExpect(() => {601 expect(watcher.stdout).toBe(`${tmpDir}/new.txt,MOVED_TO602${tmpDir}/new.txt,DELETE603`);604 });605 watcher.dispose();606});607test("move in folder, then remove folder", async () => {608 const tmpDir = await getTmpDir();609 const tmpDir2 = await getTmpDir();610 await mkdir(`${tmpDir2}/old`);611 const watcher = await createWatcher([tmpDir]);612 await rename(`${tmpDir2}/old`, `${tmpDir}/new`);613 await rm(`${tmpDir}/new`, { recursive: true });614 await waitForExpect(() => {615 expect(watcher.stdout).toBe(`${tmpDir}/new,MOVED_TO_DIR616${tmpDir}/new,DELETE_DIR617`);618 });619 watcher.dispose();620});621test("move in folder, then create file in that folder", async () => {622 const tmpDir = await getTmpDir();623 const tmpDir2 = await getTmpDir();624 await mkdir(`${tmpDir2}/old`);625 const watcher = await createWatcher([tmpDir]);626 await rename(`${tmpDir2}/old`, `${tmpDir}/new`);627 await waitForExpect(() => {628 expect(watcher.stdout).toBe(`${tmpDir}/new,MOVED_TO_DIR629`);630 });631 watcher.clear();632 await writeFile(`${tmpDir}/new/abc.txt`, "");633 await waitForExpect(() => {634 expect(watcher.stdout).toBe(`${tmpDir}/new/abc.txt,CREATE635${tmpDir}/new/abc.txt,CLOSE_WRITE636`);637 });638 watcher.dispose();639});640test("move out folder, then create file in that folder", async () => {641 const tmpDir = await getTmpDir();642 const tmpDir2 = await getTmpDir();643 await mkdir(`${tmpDir}/old`);644 const watcher = await createWatcher([tmpDir]);645 await rename(`${tmpDir}/old`, `${tmpDir2}/new`);646 await writeFile(`${tmpDir2}/new/abc.txt`, "");647 await waitForExpect(() => {648 expect(watcher.stdout).toBe(`${tmpDir}/old,MOVED_FROM_DIR649`);650 });651 watcher.dispose();652});653test("move folder in and out multiple times", async () => {654 const tmpDir = await getTmpDir();655 const tmpDir2 = await getTmpDir();656 await mkdir(`${tmpDir}/old`);657 const watcher = await createWatcher([tmpDir]);658 await rename(`${tmpDir}/old`, `${tmpDir2}/new`);659 await waitForExpect(() => {660 expect(watcher.stdout).toBe(`${tmpDir}/old,MOVED_FROM_DIR661`);662 });663 watcher.clear();664 await rename(`${tmpDir2}/new`, `${tmpDir}/old`);665 await waitForExpect(() => {666 expect(watcher.stdout).toBe(`${tmpDir}/old,MOVED_TO_DIR667`);668 });669 watcher.clear();670 await writeFile(`${tmpDir}/old/abc.txt`, "");671 await waitForExpect(() => {672 expect(watcher.stdout).toBe(`${tmpDir}/old/abc.txt,CREATE673${tmpDir}/old/abc.txt,CLOSE_WRITE674`);675 });676 watcher.dispose();677});678test("misc - deeply nested folder", async () => {679 const tmpDir = await getTmpDir();680 const watcher = await createWatcher([tmpDir]);681 for (let i = 1; i < 20; i++) {682 const name = "/1".repeat(i);683 await mkdir(`${tmpDir}${name}`);684 await waitForExpect(() => {685 expect(watcher.stdout).toBe(`${tmpDir}${name},CREATE_DIR686`);687 watcher.clear();688 });689 }690 watcher.dispose();691});692test.skip("misc - watch deeply nested folder (fast)", async () => {693 const tmpDir = await getTmpDir();694 const watcher = await createWatcher([tmpDir]);695 await mkdir(696 `${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1`,697 { recursive: true }698 );699 await waitForExpect(() => {700 expect(watcher.stdout).toBe(`${tmpDir}/1,CREATE_DIR701${tmpDir}/1/1,CREATE_DIR702${tmpDir}/1/1/1,CREATE_DIR703${tmpDir}/1/1/1/1,CREATE_DIR704${tmpDir}/1/1/1/1/1,CREATE_DIR705${tmpDir}/1/1/1/1/1/1,CREATE_DIR706${tmpDir}/1/1/1/1/1/1/1,CREATE_DIR707${tmpDir}/1/1/1/1/1/1/1/1,CREATE_DIR708${tmpDir}/1/1/1/1/1/1/1/1/1,CREATE_DIR709${tmpDir}/1/1/1/1/1/1/1/1/1/1,CREATE_DIR710${tmpDir}/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR711${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR712${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR713${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR714${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR715${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR716${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR717${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR718${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR719${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR720${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR721${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR722${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR723${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR724${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR725${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR726${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR727${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR728${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR729${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR730${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR731${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR732${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR733${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR734${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR735${tmpDir}/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1/1,CREATE_DIR736`);737 });738 await waitForExpect(() => {739 expect(watcher.stdout).toBe(`${tmpDir}/old,MOVED_FROM_DIR740`);741 });742 watcher.dispose();743});744test("setup watchers for each folder inside deeply nested folder", async () => {745 const tmpDir = await getTmpDir();746 const watcher = await createWatcher([tmpDir]);747 const count = 17;748 await mkdir(`${tmpDir}${"/1".repeat(count)}`, { recursive: true });749 await writeFile(`${tmpDir}/abc.txt`, "");750 await waitForExpect(() => {751 expect(watcher.stdout).toContain(`${tmpDir}/abc.txt,CREATE752`);753 });754 watcher.clear();755 for (let i = 0; i < count; i++) {756 const name = `1/`.repeat(i) + "2";757 await writeFile(`${tmpDir}/${name}`, "");758 await waitForExpect(() => {759 expect(watcher.stdout).toBe(`${tmpDir}/${name},CREATE760${tmpDir}/${name},CLOSE_WRITE761`);762 });763 watcher.clear();764 }765 watcher.dispose();766});767test("change file attributes", async () => {768 const tmpDir = await getTmpDir();769 await writeFile(`${tmpDir}/1`, "");770 const watcher = await createWatcher([tmpDir]);771 await chmod(`${tmpDir}/1`, "555");772 await waitForExpect(() => {773 expect(watcher.stdout).toBe(`${tmpDir}/1,ATTRIB774`);775 });776 watcher.dispose();777});778test("misc - remove and recreate file", async () => {779 const tmpDir = await getTmpDir();780 await writeFile(`${tmpDir}/1`, "");781 const watcher = await createWatcher([tmpDir]);782 await rm(`${tmpDir}/1`);783 await writeFile(`${tmpDir}/1`, "");784 await waitForExpect(() => {785 expect(watcher.stdout).toBe(`${tmpDir}/1,DELETE786${tmpDir}/1,CREATE787${tmpDir}/1,CLOSE_WRITE788`);789 });790 watcher.dispose();791});792test("move out folder and move it back in", async () => {793 const tmpDir = await getTmpDir();794 const tmpDir2 = await getTmpDir();795 await mkdir(`${tmpDir}/1`);796 const watcher = await createWatcher([tmpDir]);797 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);798 await writeFile(`${tmpDir2}/1/a.txt`, "");799 await rename(`${tmpDir2}/1`, `${tmpDir}/1`);800 await writeFile(`${tmpDir}/b.txt`, "");801 await waitForExpect(() => {802 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR803${tmpDir}/1,MOVED_TO_DIR804${tmpDir}/b.txt,CREATE805${tmpDir}/b.txt,CLOSE_WRITE806`);807 });808 watcher.dispose();809});810test("rename file multiple times", async () => {811 const tmpDir = await getTmpDir();812 await writeFile(`${tmpDir}/1.txt`, "");813 const watcher = await createWatcher([tmpDir]);814 await rename(`${tmpDir}/1.txt`, `${tmpDir}/2.txt`);815 await rename(`${tmpDir}/2.txt`, `${tmpDir}/3.txt`);816 await rename(`${tmpDir}/3.txt`, `${tmpDir}/4.txt`);817 await waitForExpect(() => {818 expect(watcher.stdout).toBe(`${tmpDir}/1.txt,MOVED_FROM819${tmpDir}/2.txt,MOVED_TO820${tmpDir}/2.txt,MOVED_FROM821${tmpDir}/3.txt,MOVED_TO822${tmpDir}/3.txt,MOVED_FROM823${tmpDir}/4.txt,MOVED_TO824`);825 });826 watcher.dispose();827});828test("rename folder multiple times", async () => {829 const tmpDir = await getTmpDir();830 await mkdir(`${tmpDir}/1`);831 const watcher = await createWatcher([tmpDir]);832 await rename(`${tmpDir}/1`, `${tmpDir}/2`);833 await rename(`${tmpDir}/2`, `${tmpDir}/3`);834 await rename(`${tmpDir}/3`, `${tmpDir}/4`);835 await waitForExpect(() => {836 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR837${tmpDir}/2,MOVED_TO_DIR838${tmpDir}/2,MOVED_FROM_DIR839${tmpDir}/3,MOVED_TO_DIR840${tmpDir}/3,MOVED_FROM_DIR841${tmpDir}/4,MOVED_TO_DIR842`);843 });844 watcher.dispose();845});846test("move in folder, move out another folder", async () => {847 const tmpDir = await getTmpDir();848 const tmpDir2 = await getTmpDir();849 await mkdir(`${tmpDir}/1`);850 await mkdir(`${tmpDir2}/2`);851 const watcher = await createWatcher([tmpDir]);852 await rename(`${tmpDir2}/2`, `${tmpDir}/2`);853 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);854 await waitForExpect(() => {855 expect(watcher.stdout).toBe(`${tmpDir}/2,MOVED_TO_DIR856${tmpDir}/1,MOVED_FROM_DIR857`);858 });859 watcher.dispose();860});861test("move out folder, move in another folder", async () => {862 const tmpDir = await getTmpDir();863 const tmpDir2 = await getTmpDir();864 await mkdir(`${tmpDir}/1`);865 await mkdir(`${tmpDir2}/2`);866 const watcher = await createWatcher([tmpDir]);867 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);868 await rename(`${tmpDir2}/2`, `${tmpDir}/2`);869 await waitForExpect(() => {870 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR871${tmpDir}/2,MOVED_TO_DIR872`);873 });874 watcher.dispose();875});876test("nested rename", async () => {877 const tmpDir = await getTmpDir();878 await mkdir(`${tmpDir}/1/2/3/4/5`, { recursive: true });879 const watcher = await createWatcher([tmpDir]);880 await rename(`${tmpDir}/1/2/3/4/5`, `${tmpDir}/1/6`);881 await rename(`${tmpDir}/1/2/3`, `${tmpDir}/1/6/3`);882 await waitForExpect(() => {883 expect(watcher.stdout).toBe(`${tmpDir}/1/2/3/4/5,MOVED_FROM_DIR884${tmpDir}/1/6,MOVED_TO_DIR885${tmpDir}/1/2/3,MOVED_FROM_DIR886${tmpDir}/1/6/3,MOVED_TO_DIR887`);888 });889 watcher.clear();890 await writeFile(`${tmpDir}/a.txt`, "");891 await writeFile(`${tmpDir}/1/b.txt`, "");892 await writeFile(`${tmpDir}/1/2/c.txt`, "");893 await writeFile(`${tmpDir}/1/6/d.txt`, "");894 await writeFile(`${tmpDir}/1/6/3/e.txt`, "");895 await waitForExpect(() => {896 expect(watcher.stdout).toBe(`${tmpDir}/a.txt,CREATE897${tmpDir}/a.txt,CLOSE_WRITE898${tmpDir}/1/b.txt,CREATE899${tmpDir}/1/b.txt,CLOSE_WRITE900${tmpDir}/1/2/c.txt,CREATE901${tmpDir}/1/2/c.txt,CLOSE_WRITE902${tmpDir}/1/6/d.txt,CREATE903${tmpDir}/1/6/d.txt,CLOSE_WRITE904${tmpDir}/1/6/3/e.txt,CREATE905${tmpDir}/1/6/3/e.txt,CLOSE_WRITE906`);907 });908 watcher.dispose();909});910test("rename subtree", async () => {911 const tmpDir = await getTmpDir();912 await mkdir(`${tmpDir}/1/2/3/4/5/6/7/8/9`, { recursive: true });913 const watcher = await createWatcher([tmpDir]);914 await rename(`${tmpDir}/1/2/3/4/5`, `${tmpDir}/1/5`);915 await writeFile(`${tmpDir}/1/5/6/7/a.txt`, "");916 await waitForExpect(() => {917 expect(watcher.stdout).toBe(`${tmpDir}/1/2/3/4/5,MOVED_FROM_DIR918${tmpDir}/1/5,MOVED_TO_DIR919${tmpDir}/1/5/6/7/a.txt,CREATE920${tmpDir}/1/5/6/7/a.txt,CLOSE_WRITE921`);922 });923 watcher.dispose();924});925// TODO test nested rename const tmpDir = await getTmpDir();926// // const tmpDir2 = await getTmpDir();927// await mkdir(`${tmpDir}/1`);928// await mkdir(`${tmpDir}/2`);929// await writeFile(`${tmpDir}/1/a.txt`, "");930// // await rename(`${tmpDir}/1`, `${tmpDir}/2`);931// const watcher = await createWatcher([tmpDir]);932// await rename(`${tmpDir}/1/a.txt`, `${tmpDir}/2/b.txt`);933test("move out and move folder", async () => {934 const tmpDir = await getTmpDir();935 const tmpDir2 = await getTmpDir();936 await mkdir(`${tmpDir}/1`);937 await mkdir(`${tmpDir2}/2`);938 const watcher = await createWatcher([tmpDir]);939 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);940 await rename(`${tmpDir2}/1`, `${tmpDir2}/2`);941 await waitForExpect(() => {942 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR943`);944 });945 watcher.dispose();946});947test("move and move out folder", async () => {948 const tmpDir = await getTmpDir();949 const tmpDir2 = await getTmpDir();950 await mkdir(`${tmpDir}/1`);951 await mkdir(`${tmpDir2}/2`);952 const watcher = await createWatcher([tmpDir]);953 await rename(`${tmpDir}/1`, `${tmpDir}/2`);954 await rename(`${tmpDir}/2`, `${tmpDir2}/2`);955 await waitForExpect(() => {956 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR957${tmpDir}/2,MOVED_TO_DIR958${tmpDir}/2,MOVED_FROM_DIR959`);960 });961 watcher.dispose();962});963test("move and move in folder", async () => {964 const tmpDir = await getTmpDir();965 const tmpDir2 = await getTmpDir();966 await mkdir(`${tmpDir}/1`);967 await mkdir(`${tmpDir2}/3`);968 const watcher = await createWatcher([tmpDir]);969 await rename(`${tmpDir}/1`, `${tmpDir}/2`);970 await rename(`${tmpDir2}/3`, `${tmpDir}/3`);971 await waitForExpect(() => {972 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR973${tmpDir}/2,MOVED_TO_DIR974${tmpDir}/3,MOVED_TO_DIR975`);976 });977 watcher.dispose();978});979test("move in and move folder", async () => {980 const tmpDir = await getTmpDir();981 const tmpDir2 = await getTmpDir();982 await mkdir(`${tmpDir2}/1`);983 const watcher = await createWatcher([tmpDir]);984 await rename(`${tmpDir2}/1`, `${tmpDir}/1`);985 await waitForExpect(() => {986 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_TO_DIR987`);988 });989 watcher.clear();990 await rename(`${tmpDir}/1`, `${tmpDir}/2`);991 await waitForExpect(() => {992 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR993${tmpDir}/2,MOVED_TO_DIR994`);995 });996 watcher.dispose();997});998test("move in nested folder", async () => {999 const tmpDir = await getTmpDir();1000 const tmpDir2 = await getTmpDir();1001 await mkdir(`${tmpDir2}/1/2/3/4/5/6/7/8/9`, { recursive: true });1002 const watcher = await createWatcher([tmpDir]);1003 await rename(`${tmpDir2}/1`, `${tmpDir}/1`);1004 await waitForExpect(() => {1005 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_TO_DIR1006`);1007 });1008 watcher.clear();1009 await writeFile(`${tmpDir}/1/2/3/4/5/6/7/8/9/new.txt`, "");1010 await waitForExpect(() => {1011 expect(watcher.stdout).toBe(`${tmpDir}/1/2/3/4/5/6/7/8/9/new.txt,CREATE1012${tmpDir}/1/2/3/4/5/6/7/8/9/new.txt,CLOSE_WRITE1013`);1014 });1015 watcher.dispose();1016});1017test.skip("folder move race condition", async () => {1018 waitForExpect.defaults.timeout = 100;1019 // this tests a very specific bug when a folder is moved in1020 // it can happen that the watch for is not yet established1021 // and the folder is renamed. When the renamed folder is renamed again1022 // since there has been no watcher, the path is not in storage and1023 // the full path for the event is not known (which is very unusual).1024 // Usually the watcher would be removed but since it is not in storage1025 // there is no watcher to remove.1026 for (let i = 0; i < 100; i++) {1027 const tmpDir = await getTmpDir();1028 const tmpDir2 = await getTmpDir();1029 await mkdir(`${tmpDir2}/1`);1030 const watcher = await createWatcher([tmpDir]);1031 await rename(`${tmpDir2}/1`, `${tmpDir}/1`);1032 await waitForExpect(() => {1033 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_TO_DIR1034`);1035 });1036 watcher.clear();1037 await rename(`${tmpDir}/1`, `${tmpDir}/3`);1038 await rename(`${tmpDir}/3`, `${tmpDir2}/4`);1039 await writeFile(`${tmpDir2}/4/a.txt`, ``);1040 await waitForExpect(() => {1041 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR1042${tmpDir}/3,MOVED_TO_DIR1043${tmpDir}/3,MOVED_FROM_DIR1044`);1045 });1046 watcher.dispose();1047 }1048}, 10_000);1049// TODO bug1050// for (let i = 0; i < 100; i++) {1051// const tmpDir = await getTmpDir();1052// const tmpDir2 = await getTmpDir();1053// await mkdir(`${tmpDir2}/1`);1054// const watcher = await createWatcher([tmpDir]);1055// await rename(`${tmpDir2}/1`, `${tmpDir}/1`);1056// await rename(`${tmpDir}/1`, `${tmpDir}/3`);1057// await rename(`${tmpDir}/3`, `${tmpDir2}/4`);1058// await writeFile(`${tmpDir2}/4/a.txt`, ``);1059// await waitForExpect(() => {1060// expect(watcher.stdout).toBe(`${tmpDir}/1 ISDIR,MOVED_TO1061// ${tmpDir}/1 ISDIR,MOVED_FROM1062// ${tmpDir}/3 ISDIR,MOVED_TO1063// ${tmpDir}/3 ISDIR,MOVED_FROM1064// `);1065// });1066// watcher.dispose();1067// }1068test("rename short path to long path", async () => {1069 const tmpDir = await getTmpDir();1070 await mkdir(`${tmpDir}/1`);1071 const watcher = await createWatcher([tmpDir]);1072 await rename(1073 `${tmpDir}/1`,1074 `${tmpDir}/22222222222222222222222222222222222222222222222222222222222222222222222222`1075 );1076 await waitForExpect(() => {1077 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR1078${tmpDir}/22222222222222222222222222222222222222222222222222222222222222222222222222,MOVED_TO_DIR1079`);1080 });1081 watcher.dispose();1082});1083test("rename long path to short path", async () => {1084 const tmpDir = await getTmpDir();1085 await mkdir(1086 `${tmpDir}/22222222222222222222222222222222222222222222222222222222222222222222222222`1087 );1088 const watcher = await createWatcher([tmpDir]);1089 await rename(1090 `${tmpDir}/22222222222222222222222222222222222222222222222222222222222222222222222222`,1091 `${tmpDir}/1`1092 );1093 await waitForExpect(() => {1094 expect(watcher.stdout)1095 .toBe(`${tmpDir}/22222222222222222222222222222222222222222222222222222222222222222222222222,MOVED_FROM_DIR1096${tmpDir}/1,MOVED_TO_DIR1097`);1098 });1099 watcher.dispose();1100});1101test("renaming folders from top 1/1/1 -> -> 2/1/1 -> 2/3/1 -> 2/3/4", async () => {1102 const tmpDir = await getTmpDir();1103 await mkdir(`${tmpDir}/1/1/1`, { recursive: true });1104 const watcher = await createWatcher([tmpDir]);1105 await rename(`${tmpDir}/1`, `${tmpDir}/2`);1106 await rename(`${tmpDir}/2/1`, `${tmpDir}/2/3`);1107 await rename(`${tmpDir}/2/3/1`, `${tmpDir}/2/3/4`);1108 await waitForExpect(() => {1109 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR1110${tmpDir}/2,MOVED_TO_DIR1111${tmpDir}/2/1,MOVED_FROM_DIR1112${tmpDir}/2/3,MOVED_TO_DIR1113${tmpDir}/2/3/1,MOVED_FROM_DIR1114${tmpDir}/2/3/4,MOVED_TO_DIR1115`);1116 });1117 watcher.dispose();1118});1119test("renaming folders from bottom 1/1/1 -> 1/1/4 -> 1/3/4 -> 2/3/4", async () => {1120 const tmpDir = await getTmpDir();1121 await mkdir(`${tmpDir}/1/1/1`, { recursive: true });1122 const watcher = await createWatcher([tmpDir]);1123 await rename(`${tmpDir}/1/1/1`, `${tmpDir}/1/1/4`);1124 await rename(`${tmpDir}/1/1`, `${tmpDir}/1/3`);1125 await rename(`${tmpDir}/1`, `${tmpDir}/2`);1126 await waitForExpect(() => {1127 expect(watcher.stdout).toBe(`${tmpDir}/1/1/1,MOVED_FROM_DIR1128${tmpDir}/1/1/4,MOVED_TO_DIR1129${tmpDir}/1/1,MOVED_FROM_DIR1130${tmpDir}/1/3,MOVED_TO_DIR1131${tmpDir}/1,MOVED_FROM_DIR1132${tmpDir}/2,MOVED_TO_DIR1133`);1134 });1135 watcher.dispose();1136});1137test("renaming folders from middle 1/1/1 -> 1/3/1 -> 2/3/1 -> 2/3/4", async () => {1138 const tmpDir = await getTmpDir();1139 await mkdir(`${tmpDir}/1/1/1`, { recursive: true });1140 const watcher = await createWatcher([tmpDir]);1141 await rename(`${tmpDir}/1/1`, `${tmpDir}/1/3`);1142 await rename(`${tmpDir}/1`, `${tmpDir}/2`);1143 await rename(`${tmpDir}/2/3/1`, `${tmpDir}/2/3/4`);1144 await waitForExpect(() => {1145 expect(watcher.stdout).toBe(`${tmpDir}/1/1,MOVED_FROM_DIR1146${tmpDir}/1/3,MOVED_TO_DIR1147${tmpDir}/1,MOVED_FROM_DIR1148${tmpDir}/2,MOVED_TO_DIR1149${tmpDir}/2/3/1,MOVED_FROM_DIR1150${tmpDir}/2/3/4,MOVED_TO_DIR1151`);1152 });1153 watcher.dispose();1154});1155test("move out child folder, remove parent folder, move child folder back in", async () => {1156 const tmpDir = await getTmpDir();1157 const tmpDir2 = await getTmpDir();1158 await mkdir(`${tmpDir}/1/2`, { recursive: true });1159 const watcher = await createWatcher([tmpDir]);1160 await rename(`${tmpDir}/1/2`, `${tmpDir2}/2`);1161 await rm(`${tmpDir}/1`, { recursive: true });1162 await rename(`${tmpDir2}/2`, `${tmpDir}/2`);1163 await waitForExpect(() => {1164 expect(watcher.stdout).toBe(`${tmpDir}/1/2,MOVED_FROM_DIR1165${tmpDir}/1,DELETE_DIR1166${tmpDir}/2,MOVED_TO_DIR1167`);1168 });1169 watcher.clear();1170 await writeFile(`${tmpDir}/2/a.txt`, "");1171 await waitForExpect(() => {1172 expect(watcher.stdout).toBe(`${tmpDir}/2/a.txt,CREATE1173${tmpDir}/2/a.txt,CLOSE_WRITE1174`);1175 });1176 watcher.dispose();1177});1178test("replace file with folder", async () => {1179 const tmpDir = await getTmpDir();1180 await writeFile(`${tmpDir}/1`, "");1181 const watcher = await createWatcher([tmpDir]);1182 await rm(`${tmpDir}/1`);1183 await mkdir(`${tmpDir}/1`);1184 await waitForExpect(() => {1185 expect(watcher.stdout).toBe(`${tmpDir}/1,DELETE1186${tmpDir}/1,CREATE_DIR1187`);1188 });1189 watcher.dispose();1190});1191test("replace folder with file", async () => {1192 const tmpDir = await getTmpDir();1193 await mkdir(`${tmpDir}/1`);1194 const watcher = await createWatcher([tmpDir]);1195 await rm(`${tmpDir}/1`, { recursive: true });1196 await writeFile(`${tmpDir}/1`, "");1197 await waitForExpect(() => {1198 expect(watcher.stdout).toBe(`${tmpDir}/1,DELETE_DIR1199${tmpDir}/1,CREATE1200${tmpDir}/1,CLOSE_WRITE1201`);1202 });1203 watcher.dispose();1204});1205test("create multiple files in parallel", async () => {1206 const tmpDir = await getTmpDir();1207 const watcher = await createWatcher([tmpDir]);1208 await Promise.all([1209 writeFile(`${tmpDir}/1`, ""),1210 writeFile(`${tmpDir}/2`, ""),1211 writeFile(`${tmpDir}/3`, ""),1212 ]);1213 await waitForExpect(() => {1214 expect(watcher.stdout).toContain(`${tmpDir}/1,CREATE`);1215 expect(watcher.stdout).toContain(`${tmpDir}/1,CLOSE_WRITE`);1216 expect(watcher.stdout).toContain(`${tmpDir}/2,CREATE`);1217 expect(watcher.stdout).toContain(`${tmpDir}/2,CLOSE_WRITE`);1218 expect(watcher.stdout).toContain(`${tmpDir}/3,CREATE`);1219 expect(watcher.stdout).toContain(`${tmpDir}/3,CLOSE_WRITE`);1220 });1221 watcher.dispose();1222});1223test("remove multiple files in parallel", async () => {1224 const tmpDir = await getTmpDir();1225 await Promise.all([1226 writeFile(`${tmpDir}/1`, ""),1227 writeFile(`${tmpDir}/2`, ""),1228 writeFile(`${tmpDir}/3`, ""),1229 ]);1230 const watcher = await createWatcher([tmpDir]);1231 await Promise.all([rm(`${tmpDir}/1`), rm(`${tmpDir}/2`), rm(`${tmpDir}/3`)]);1232 await waitForExpect(() => {1233 expect(watcher.stdout).toContain(`${tmpDir}/1,DELETE`);1234 expect(watcher.stdout).toContain(`${tmpDir}/2,DELETE`);1235 expect(watcher.stdout).toContain(`${tmpDir}/3,DELETE`);1236 });1237 watcher.dispose();1238});1239test("move out multiple files in parallel", async () => {1240 const tmpDir = await getTmpDir();1241 const tmpDir2 = await getTmpDir();1242 await writeFile(`${tmpDir}/1`, "");1243 await writeFile(`${tmpDir}/2`, "");1244 await writeFile(`${tmpDir}/3`, "");1245 const watcher = await createWatcher([tmpDir]);1246 await Promise.all([1247 rename(`${tmpDir}/1`, `${tmpDir2}/1`),1248 rename(`${tmpDir}/2`, `${tmpDir2}/2`),1249 rename(`${tmpDir}/3`, `${tmpDir2}/3`),1250 ]);1251 await waitForExpect(() => {1252 expect(watcher.stdout).toContain(`${tmpDir}/1,MOVED_FROM`);1253 expect(watcher.stdout).toContain(`${tmpDir}/2,MOVED_FROM`);1254 expect(watcher.stdout).toContain(`${tmpDir}/3,MOVED_FROM`);1255 });1256 watcher.dispose();1257});1258test("move out some files and folders", async () => {1259 const tmpDir = await getTmpDir();1260 const tmpDir2 = await getTmpDir();1261 await mkdir(`${tmpDir}/1`);1262 await mkdir(`${tmpDir}/2`);1263 await writeFile(`${tmpDir}/2/3.txt`, "");1264 const watcher = await createWatcher([tmpDir]);1265 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);1266 await rename(`${tmpDir}/2/3.txt`, `${tmpDir2}/3.txt`);1267 await rename(`${tmpDir}/2`, `${tmpDir2}/2`);1268 await waitForExpect(() => {1269 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR1270${tmpDir}/2/3.txt,MOVED_FROM1271${tmpDir}/2,MOVED_FROM_DIR1272`);1273 });1274 watcher.dispose();1275});1276test("move out many folders", async () => {1277 const tmpDir = await getTmpDir();1278 const tmpDir2 = await getTmpDir();1279 const watcher = await createWatcher([tmpDir]);1280 for (let i = 0; i < 100; i++) {1281 await mkdir(`${tmpDir}/${i}`);1282 }1283 await waitForExpect(() => {1284 expect(watcher.stdout.split("\n").length).toBe(101);1285 });1286 for (let i = 0; i < 100; i++) {1287 await rename(`${tmpDir}/${i}`, `${tmpDir2}/${i}`);1288 }1289 await waitForExpect(() => {1290 expect(watcher.stdout).toContain(`${tmpDir}/1,MOVED_FROM_DIR`);1291 expect(watcher.stdout).toContain(`${tmpDir}/99,MOVED_FROM_DIR`);1292 });1293 watcher.dispose();1294});1295test("create nine files in one directory", async () => {1296 const tmpDir = await getTmpDir();1297 const watcher = await createWatcher([tmpDir]);1298 await Promise.all([1299 writeFile(`${tmpDir}/0`, ""),1300 writeFile(`${tmpDir}/1`, ""),1301 writeFile(`${tmpDir}/2`, ""),1302 writeFile(`${tmpDir}/3`, ""),1303 writeFile(`${tmpDir}/4`, ""),1304 ]);1305 await Promise.all([1306 writeFile(`${tmpDir}/5`, ""),1307 writeFile(`${tmpDir}/6`, ""),1308 ]);1309 await Promise.all([1310 writeFile(`${tmpDir}/7`, ""),1311 writeFile(`${tmpDir}/8`, ""),1312 ]);1313 await writeFile(`${tmpDir}/9`, "");1314 await waitForExpect(() => {1315 expect(watcher.stdout).toContain(`${tmpDir}/1,CREATE`);1316 expect(watcher.stdout).toContain(`${tmpDir}/1,CLOSE_WRITE`);1317 expect(watcher.stdout).toContain(`${tmpDir}/2,CREATE`);1318 expect(watcher.stdout).toContain(`${tmpDir}/3,CLOSE_WRITE`);1319 expect(watcher.stdout).toContain(`${tmpDir}/3,CREATE`);1320 expect(watcher.stdout).toContain(`${tmpDir}/3,CLOSE_WRITE`);1321 expect(watcher.stdout).toContain(`${tmpDir}/4,CREATE`);1322 expect(watcher.stdout).toContain(`${tmpDir}/4,CLOSE_WRITE`);1323 expect(watcher.stdout).toContain(`${tmpDir}/5,CREATE`);1324 expect(watcher.stdout).toContain(`${tmpDir}/5,CLOSE_WRITE`);1325 expect(watcher.stdout).toContain(`${tmpDir}/6,CREATE`);1326 expect(watcher.stdout).toContain(`${tmpDir}/6,CLOSE_WRITE`);1327 expect(watcher.stdout).toContain(`${tmpDir}/7,CREATE`);1328 expect(watcher.stdout).toContain(`${tmpDir}/7,CLOSE_WRITE`);1329 expect(watcher.stdout).toContain(`${tmpDir}/8,CREATE`);1330 expect(watcher.stdout).toContain(`${tmpDir}/8,CLOSE_WRITE`);1331 expect(watcher.stdout).toContain(`${tmpDir}/9,CREATE`);1332 expect(watcher.stdout).toContain(`${tmpDir}/9,CLOSE_WRITE`);1333 });1334 watcher.dispose();1335});1336test("create thirtythree files in nine folders", async () => {1337 const tmpDir = await getTmpDir();1338 const test1Path = `${tmpDir}/add1.txt`;1339 const testb1Path = `${tmpDir}/b/add1.txt`;1340 const testc1Path = `${tmpDir}/c/add1.txt`;1341 const testd1Path = `${tmpDir}/d/add1.txt`;1342 const teste1Path = `${tmpDir}/e/add1.txt`;1343 const testf1Path = `${tmpDir}/f/add1.txt`;1344 const testg1Path = `${tmpDir}/g/add1.txt`;1345 const testh1Path = `${tmpDir}/h/add1.txt`;1346 const testi1Path = `${tmpDir}/i/add1.txt`;1347 const test2Path = `${tmpDir}/add2.txt`;1348 const testb2Path = `${tmpDir}/b/add2.txt`;1349 const testc2Path = `${tmpDir}/c/add2.txt`;1350 const test3Path = `${tmpDir}/add3.txt`;1351 const testb3Path = `${tmpDir}/b/add3.txt`;1352 const testc3Path = `${tmpDir}/c/add3.txt`;1353 const test4Path = `${tmpDir}/add4.txt`;1354 const testb4Path = `${tmpDir}/b/add4.txt`;1355 const testc4Path = `${tmpDir}/c/add4.txt`;1356 const test5Path = `${tmpDir}/add5.txt`;1357 const testb5Path = `${tmpDir}/b/add5.txt`;1358 const testc5Path = `${tmpDir}/c/add5.txt`;1359 const test6Path = `${tmpDir}/add6.txt`;1360 const testb6Path = `${tmpDir}/b/add6.txt`;1361 const testc6Path = `${tmpDir}/c/add6.txt`;1362 const test7Path = `${tmpDir}/add7.txt`;1363 const testb7Path = `${tmpDir}/b/add7.txt`;1364 const testc7Path = `${tmpDir}/c/add7.txt`;1365 const test8Path = `${tmpDir}/add8.txt`;1366 const testb8Path = `${tmpDir}/b/add8.txt`;1367 const testc8Path = `${tmpDir}/c/add8.txt`;1368 const test9Path = `${tmpDir}/add9.txt`;1369 const testb9Path = `${tmpDir}/b/add9.txt`;1370 const testc9Path = `${tmpDir}/c/add9.txt`;1371 await Promise.all([1372 mkdir(`${tmpDir}/b`),1373 mkdir(`${tmpDir}/c`),1374 mkdir(`${tmpDir}/d`),1375 mkdir(`${tmpDir}/e`),1376 mkdir(`${tmpDir}/f`),1377 mkdir(`${tmpDir}/g`),1378 mkdir(`${tmpDir}/h`),1379 mkdir(`${tmpDir}/i`),1380 ]);1381 const watcher = await createWatcher([tmpDir]);1382 await writeFile(test1Path, "");1383 await writeFile(test2Path, "");1384 await writeFile(test3Path, "");1385 await writeFile(test4Path, "");1386 await writeFile(test5Path, "");1387 await writeFile(test6Path, "");1388 await writeFile(test7Path, "");1389 await writeFile(test8Path, "");1390 await writeFile(test9Path, "");1391 await writeFile(testb1Path, "");1392 await writeFile(testb2Path, "");1393 await writeFile(testb3Path, "");1394 await writeFile(testb4Path, "");1395 await writeFile(testb5Path, "");1396 await writeFile(testb6Path, "");1397 await writeFile(testb7Path, "");1398 await writeFile(testb8Path, "");1399 await writeFile(testb9Path, "");1400 await writeFile(testc1Path, "");1401 await writeFile(testc2Path, "");1402 await writeFile(testc3Path, "");1403 await writeFile(testc4Path, "");1404 await writeFile(testc5Path, "");1405 await writeFile(testc6Path, "");1406 await writeFile(testc7Path, "");1407 await writeFile(testc8Path, "");1408 await writeFile(testc9Path, "");1409 await writeFile(testd1Path, "");1410 await writeFile(teste1Path, "");1411 await writeFile(testf1Path, "");1412 await writeFile(testg1Path, "");1413 await writeFile(testh1Path, "");1414 await writeFile(testi1Path, "");1415 await waitForExpect(() => {1416 expect(watcher.stdout).toBe(`${tmpDir}/add1.txt,CREATE1417${tmpDir}/add1.txt,CLOSE_WRITE1418${tmpDir}/add2.txt,CREATE1419${tmpDir}/add2.txt,CLOSE_WRITE1420${tmpDir}/add3.txt,CREATE1421${tmpDir}/add3.txt,CLOSE_WRITE1422${tmpDir}/add4.txt,CREATE1423${tmpDir}/add4.txt,CLOSE_WRITE1424${tmpDir}/add5.txt,CREATE1425${tmpDir}/add5.txt,CLOSE_WRITE1426${tmpDir}/add6.txt,CREATE1427${tmpDir}/add6.txt,CLOSE_WRITE1428${tmpDir}/add7.txt,CREATE1429${tmpDir}/add7.txt,CLOSE_WRITE1430${tmpDir}/add8.txt,CREATE1431${tmpDir}/add8.txt,CLOSE_WRITE1432${tmpDir}/add9.txt,CREATE1433${tmpDir}/add9.txt,CLOSE_WRITE1434${tmpDir}/b/add1.txt,CREATE1435${tmpDir}/b/add1.txt,CLOSE_WRITE1436${tmpDir}/b/add2.txt,CREATE1437${tmpDir}/b/add2.txt,CLOSE_WRITE1438${tmpDir}/b/add3.txt,CREATE1439${tmpDir}/b/add3.txt,CLOSE_WRITE1440${tmpDir}/b/add4.txt,CREATE1441${tmpDir}/b/add4.txt,CLOSE_WRITE1442${tmpDir}/b/add5.txt,CREATE1443${tmpDir}/b/add5.txt,CLOSE_WRITE1444${tmpDir}/b/add6.txt,CREATE1445${tmpDir}/b/add6.txt,CLOSE_WRITE1446${tmpDir}/b/add7.txt,CREATE1447${tmpDir}/b/add7.txt,CLOSE_WRITE1448${tmpDir}/b/add8.txt,CREATE1449${tmpDir}/b/add8.txt,CLOSE_WRITE1450${tmpDir}/b/add9.txt,CREATE1451${tmpDir}/b/add9.txt,CLOSE_WRITE1452${tmpDir}/c/add1.txt,CREATE1453${tmpDir}/c/add1.txt,CLOSE_WRITE1454${tmpDir}/c/add2.txt,CREATE1455${tmpDir}/c/add2.txt,CLOSE_WRITE1456${tmpDir}/c/add3.txt,CREATE1457${tmpDir}/c/add3.txt,CLOSE_WRITE1458${tmpDir}/c/add4.txt,CREATE1459${tmpDir}/c/add4.txt,CLOSE_WRITE1460${tmpDir}/c/add5.txt,CREATE1461${tmpDir}/c/add5.txt,CLOSE_WRITE1462${tmpDir}/c/add6.txt,CREATE1463${tmpDir}/c/add6.txt,CLOSE_WRITE1464${tmpDir}/c/add7.txt,CREATE1465${tmpDir}/c/add7.txt,CLOSE_WRITE1466${tmpDir}/c/add8.txt,CREATE1467${tmpDir}/c/add8.txt,CLOSE_WRITE1468${tmpDir}/c/add9.txt,CREATE1469${tmpDir}/c/add9.txt,CLOSE_WRITE1470${tmpDir}/d/add1.txt,CREATE1471${tmpDir}/d/add1.txt,CLOSE_WRITE1472${tmpDir}/e/add1.txt,CREATE1473${tmpDir}/e/add1.txt,CLOSE_WRITE1474${tmpDir}/f/add1.txt,CREATE1475${tmpDir}/f/add1.txt,CLOSE_WRITE1476${tmpDir}/g/add1.txt,CREATE1477${tmpDir}/g/add1.txt,CLOSE_WRITE1478${tmpDir}/h/add1.txt,CREATE1479${tmpDir}/h/add1.txt,CLOSE_WRITE1480${tmpDir}/i/add1.txt,CREATE1481${tmpDir}/i/add1.txt,CLOSE_WRITE1482`);1483 });1484 watcher.dispose();1485});1486test("remove and recreate file", async () => {1487 const tmpDir = await getTmpDir();1488 await writeFile(`${tmpDir}/1.txt`, "");1489 const watcher = await createWatcher([tmpDir]);1490 await rm(`${tmpDir}/1.txt`);1491 await writeFile(`${tmpDir}/1.txt`, "");1492 await waitForExpect(() => {1493 expect(watcher.stdout).toBe(`${tmpDir}/1.txt,DELETE1494${tmpDir}/1.txt,CREATE1495${tmpDir}/1.txt,CLOSE_WRITE1496`);1497 });1498 watcher.dispose();1499});1500test("move in folder, then create folder inside that folder, remove outer folder and create file in inner folder", async () => {1501 const tmpDir = await getTmpDir();1502 const tmpDir2 = await getTmpDir();1503 await mkdir(`${tmpDir2}/1`);1504 const watcher = await createWatcher([tmpDir]);1505 await rename(`${tmpDir2}/1`, `${tmpDir}/1`);1506 await waitForExpect(() => {1507 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_TO_DIR1508`);1509 });1510 watcher.clear();1511 // TODO test with fast creation of nested folder 1/2/3/4/5/6/7/8/9/10/11/121512 await mkdir(`${tmpDir}/1/2`);1513 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);1514 await writeFile(`${tmpDir2}/1/2/3.txt`, "");1515 await waitForExpect(() => {1516 expect(watcher.stdout).toBe(`${tmpDir}/1/2,CREATE_DIR1517${tmpDir}/1,MOVED_FROM_DIR1518`);1519 });1520 watcher.dispose();1521});1522test("create and remove deeply nested folder", async () => {1523 const tmpDir = await getTmpDir();1524 await mkdir(`${tmpDir}/1`);1525 const watcher = await createWatcher([tmpDir]);1526 await mkdir(`${tmpDir}/1/1/1/1/1/1`, { recursive: true });1527 await rm(`${tmpDir}/1`, { recursive: true });1528 await writeFile(`${tmpDir}/2.txt`, "");1529 await waitForExpect(() => {1530 expect(watcher.stdout).toContain(`${tmpDir}/1/1,CREATE_DIR`);1531 expect(watcher.stdout).toContain(`${tmpDir}/1,DELETE_DIR`);1532 expect(watcher.stdout).toContain(`${tmpDir}/2.txt,CREATE`);1533 });1534 watcher.dispose();1535});1536test("inner watcher should be removed when parent folder is moved out", async () => {1537 const tmpDir = await getTmpDir();1538 const tmpDir2 = await getTmpDir();1539 await mkdir(`${tmpDir}/1/2`, { recursive: true });1540 const watcher = await createWatcher([tmpDir]);1541 await rename(`${tmpDir}/1`, `${tmpDir2}/1`);1542 await writeFile(`${tmpDir2}/1/2/3.txt`, "");1543 await waitForExpect(() => {1544 expect(watcher.stdout).toBe(`${tmpDir}/1,MOVED_FROM_DIR1545`);1546 });1547 watcher.dispose();1548});1549test("rename deeply nested folder (https://github.com/inotify-tools/inotify-tools/issues/130)", async () => {1550 const tmpDir = await getTmpDir();1551 await mkdir(`${tmpDir}/a1/a2/a3/a4/a5/a6/a7/a8/a9`, { recursive: true });1552 const watcher = await createWatcher([tmpDir]);1553 await rename(`${tmpDir}/a1`, `${tmpDir}/b1`);1554 await writeFile(`${tmpDir}/b1/a2/a3/a4/a5/a6/a7/a8/a9/new.txt`, "");1555 await waitForExpect(() => {1556 expect(watcher.stdout).toBe(`${tmpDir}/a1,MOVED_FROM_DIR1557${tmpDir}/b1,MOVED_TO_DIR1558${tmpDir}/b1/a2/a3/a4/a5/a6/a7/a8/a9/new.txt,CREATE1559${tmpDir}/b1/a2/a3/a4/a5/a6/a7/a8/a9/new.txt,CLOSE_WRITE1560`);1561 });1562 watcher.dispose();1563});1564test("move some files around (https://github.com/inotify-tools/inotify-tools/issues/137)", async () => {1565 const tmpDir = await getTmpDir();1566 const tmpDir2 = await getTmpDir();1567 await mkdir(`${tmpDir}/to_move/dir`, { recursive: true });1568 const watcher = await createWatcher([tmpDir]);1569 await writeFile(`${tmpDir}/to_move/dir/test_file.txt`, "");1570 await rename(`${tmpDir}/to_move`, `${tmpDir2}/to_move`);1571 await writeFile(`${tmpDir2}/to_move/dir/test_file.txt`, "");1572 await waitForExpect(() => {1573 expect(watcher.stdout).toBe(`${tmpDir}/to_move/dir/test_file.txt,CREATE1574${tmpDir}/to_move/dir/test_file.txt,CLOSE_WRITE1575${tmpDir}/to_move,MOVED_FROM_DIR1576`);1577 });1578 watcher.dispose();1579});1580test("move and delete some folders (https://github.com/Axosoft/nsfw/pull/63)", async () => {1581 const tmpDir = await getTmpDir();1582 await mkdir(`${tmpDir}/a/b`, { recursive: true });1583 await mkdir(`${tmpDir}/a/c`, { recursive: true });1584 await mkdir(`${tmpDir}/d`);1585 const watcher = await createWatcher([tmpDir]);1586 await rename(`${tmpDir}/a/b`, `${tmpDir}/d/b`);1587 await rename(`${tmpDir}/a/c`, `${tmpDir}/a/b`);1588 await rm(`${tmpDir}/a`, { recursive: true });1589 await rm(`${tmpDir}/d`, { recursive: true });1590 await waitForExpect(() => {1591 expect(watcher.stdout).toBe(`${tmpDir}/a/b,MOVED_FROM_DIR1592${tmpDir}/d/b,MOVED_TO_DIR1593${tmpDir}/a/c,MOVED_FROM_DIR1594${tmpDir}/a/b,MOVED_TO_DIR1595${tmpDir}/a/b,DELETE_DIR1596${tmpDir}/a,DELETE_DIR1597${tmpDir}/d/b,DELETE_DIR1598${tmpDir}/d,DELETE_DIR1599`);1600 });1601 watcher.dispose();1602});1603// TODO test move in folder then create folder inside that folder, remove outer folder and create file in inner folder1604// TODO test remove lowest wd1605// TODO test remove highest wd1606// TODO this results in bug -> investigate1607// const tmpDir = await getTmpDir();1608// const tmpDir2 = await getTmpDir();1609// await mkdir(`${tmpDir}/old`);1610// const watcher = await createWatcher([tmpDir]);1611// await rename(`${tmpDir}/old`, `${tmpDir2}/new`);1612// await setTimeout(100);1613// await rename(`${tmpDir2}/new`, `${tmpDir}/old`);1614// await writeFile(`${tmpDir}/old/abc.txt`, "");1615// TODO misc test1616// const tmpDir = await getTmpDir();1617// const tmpDir2 = await getTmpDir();1618// const n = 100;1619// for (let i = 0; i < n; i++) {1620// await mkdir(`${tmpDir}/${i}`);1621// }1622// // await mkdir(`${tmpDir}/2`);1623// const watcher = await createWatcher([tmpDir]);1624// for (let i = 0; i < n; i++) {1625// await rename(`${tmpDir}/${i}`, `${tmpDir2}/${i}`);1626// await writeFile(`${tmpDir}/${i}.txt`, "");1627// // await mkdir(`${tmpDir}/${i}`);1628// }1629test("change folder attribute", async () => {1630 const tmpDir = await getTmpDir();1631 await mkdir(`${tmpDir}/a`);1632 const watcher = await createWatcher([tmpDir]);1633 await exec("chmod", ["-R", "g+s", `${tmpDir}/a`]);1634 await waitForExpect(() => {1635 expect(watcher.stdout).toBe(`${tmpDir}/a,ATTRIB_DIR1636`);1637 });1638 watcher.dispose();1639});1640// TODO test softlink and hardlinks1641// TODO test exclude1642test("exclude node_modules", async () => {1643 const tmpDir = await getTmpDir();1644 await mkdir(`${tmpDir}/node_modules`);1645 const watcher = await createWatcher([tmpDir, "--exclude", "node_modules"]);1646 await mkdir(`${tmpDir}/node_modules/lodash`);1647 await writeFile(`${tmpDir}/a.txt`, "");1648 await waitForExpect(() => {1649 expect(watcher.stdout).toBe(`${tmpDir}/a.txt,CREATE1650${tmpDir}/a.txt,CLOSE_WRITE1651`);1652 });1653 watcher.dispose();1654});1655test("exclude .git", async () => {1656 const tmpDir = await getTmpDir();1657 await mkdir(`${tmpDir}/.git/objects`, { recursive: true });1658 const watcher = await createWatcher([tmpDir, "--exclude", ".git"]);1659 await writeFile(`${tmpDir}/.git/objects/1`, "");1660 await writeFile(`${tmpDir}/a.txt`, "");1661 await waitForExpect(() => {1662 expect(watcher.stdout).toBe(`${tmpDir}/a.txt,CREATE1663${tmpDir}/a.txt,CLOSE_WRITE1664`);1665 });1666 watcher.dispose();1667});1668test("creating folder that is excluded", async () => {1669 const tmpDir = await getTmpDir();1670 const watcher = await createWatcher([tmpDir, "--exclude", "a"]);1671 await mkdir(`${tmpDir}/a`);1672 await writeFile(`${tmpDir}/b.txt`, "");1673 await waitForExpect(() => {1674 expect(watcher.stdout).toBe(`${tmpDir}/a,CREATE_DIR1675${tmpDir}/b.txt,CREATE1676${tmpDir}/b.txt,CLOSE_WRITE1677`);1678 });1679 watcher.clear();1680 await writeFile(`${tmpDir}/a/a.txt`, "");1681 await writeFile(`${tmpDir}/c.txt`, "");1682 await waitForExpect(() => {1683 expect(watcher.stdout).toBe(`${tmpDir}/c.txt,CREATE1684${tmpDir}/c.txt,CLOSE_WRITE1685`);1686 });1687 watcher.dispose();1688});1689test("move out excluded folder", async () => {1690 const tmpDir = await getTmpDir();1691 const tmpDir2 = await getTmpDir();1692 await mkdir(`${tmpDir}/a`);1693 const watcher = await createWatcher([tmpDir, "--exclude", "a"]);1694 await rename(`${tmpDir}/a`, `${tmpDir2}/a`);1695 await writeFile(`${tmpDir}/b.txt`, ``);1696 await waitForExpect(() => {1697 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_FROM_DIR1698${tmpDir}/b.txt,CREATE1699${tmpDir}/b.txt,CLOSE_WRITE1700`);1701 });1702 watcher.dispose();1703});1704test("move in excluded folder", async () => {1705 const tmpDir = await getTmpDir();1706 const tmpDir2 = await getTmpDir();1707 await mkdir(`${tmpDir2}/a`);1708 const watcher = await createWatcher([tmpDir, "--exclude", "a"]);1709 await rename(`${tmpDir2}/a`, `${tmpDir}/a`);1710 await waitForExpect(() => {1711 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_TO_DIR1712`);1713 });1714 watcher.clear();1715 await writeFile(`${tmpDir}/a/a.txt`, "");1716 await writeFile(`${tmpDir}/b.txt`, "");1717 await waitForExpect(() => {1718 expect(watcher.stdout).toBe(`${tmpDir}/b.txt,CREATE1719${tmpDir}/b.txt,CLOSE_WRITE1720`);1721 });1722 watcher.dispose();1723});1724test("rename excluded folder to non-excluded folder", async () => {1725 const tmpDir = await getTmpDir();1726 await mkdir(`${tmpDir}/a`);1727 const watcher = await createWatcher([tmpDir, "--exclude", "a"]);1728 await rename(`${tmpDir}/a`, `${tmpDir}/b`);1729 await waitForExpect(() => {1730 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_FROM_DIR1731${tmpDir}/b,MOVED_TO_DIR1732`);1733 });1734 watcher.clear();1735 await writeFile(`${tmpDir}/b/b.txt`, "");1736 await waitForExpect(() => {1737 expect(watcher.stdout).toBe(`${tmpDir}/b/b.txt,CREATE1738${tmpDir}/b/b.txt,CLOSE_WRITE1739`);1740 });1741 watcher.dispose();1742});1743test("rename non-excluded folder to excluded folder", async () => {1744 const tmpDir = await getTmpDir();1745 await mkdir(`${tmpDir}/b`);1746 const watcher = await createWatcher([tmpDir, "--exclude", "a"]);1747 await rename(`${tmpDir}/b`, `${tmpDir}/a`);1748 await waitForExpect(() => {1749 expect(watcher.stdout).toBe(`${tmpDir}/b,MOVED_FROM_DIR1750${tmpDir}/a,MOVED_TO_DIR1751`);1752 });1753 watcher.clear();1754 await writeFile(`${tmpDir}/a/a.txt`, "");1755 await writeFile(`${tmpDir}/c.txt`, "");1756 await waitForExpect(() => {1757 expect(watcher.stdout).toBe(`${tmpDir}/c.txt,CREATE1758${tmpDir}/c.txt,CLOSE_WRITE1759`);1760 });1761 watcher.dispose();1762});1763test("exclude multiple folders", async () => {1764 const tmpDir = await getTmpDir();1765 await Promise.all([1766 mkdir(`${tmpDir}/a`),1767 mkdir(`${tmpDir}/b`),1768 mkdir(`${tmpDir}/c`),1769 mkdir(`${tmpDir}/d`),1770 ]);1771 const watcher = await createWatcher([1772 tmpDir,1773 "--exclude",1774 "a",1775 "--exclude",1776 "b",1777 "--exclude",1778 "c",1779 ]);1780 await Promise.all([1781 writeFile(`${tmpDir}/a/1.txt`, ""),1782 writeFile(`${tmpDir}/b/1.txt`, ""),1783 writeFile(`${tmpDir}/c/1.txt`, ""),1784 writeFile(`${tmpDir}/d/1.txt`, ""),1785 ]);1786 await waitForExpect(() => {1787 expect(watcher.stdout).toBe(`${tmpDir}/d/1.txt,CREATE1788${tmpDir}/d/1.txt,CLOSE_WRITE1789`);1790 });1791 watcher.dispose();1792});1793// TODO test is failing in ci sometimes https://github.com/levivilet/c-watcher/runs/4059024632?check_suite_focus=true1794test.skip("symlinked file", async () => {1795 const tmpDir = await getTmpDir();1796 await writeFile(`${tmpDir}/a.txt`, "");1797 await symlink(`${tmpDir}/a.txt`, `${tmpDir}/b.txt`);1798 const watcher = await createWatcher([tmpDir]);1799 await writeFile(`${tmpDir}/a.txt`, "aaa");1800 await waitForExpect(() => {1801 expect(watcher.stdout).toBe(`${tmpDir}/a.txt,MODIFY1802${tmpDir}/a.txt,MODIFY1803${tmpDir}/a.txt,CLOSE_WRITE1804`);1805 });1806 watcher.dispose();1807});1808test("symlinked folder", async () => {1809 const tmpDir = await getTmpDir();1810 await mkdir(`${tmpDir}/a`);1811 await symlink(`${tmpDir}/a`, `${tmpDir}/b`);1812 const watcher = await createWatcher([tmpDir]);1813 await writeFile(`${tmpDir}/b/1.txt`, "");1814 await waitForExpect(() => {1815 expect(watcher.stdout).toBe(`${tmpDir}/a/1.txt,CREATE1816${tmpDir}/a/1.txt,CLOSE_WRITE1817`);1818 });1819 watcher.dispose();1820});1821// TODO test hardlink1822test.skip("delete watched folder", async () => {1823 const tmpDir = await getTmpDir();1824 const watcher = await createWatcher([tmpDir]);1825 await rm(tmpDir, { recursive: true });1826 await waitForExpect(() => {1827 expect(watcher.stdout).toBe(``);1828 expect(watcher.status).toBe("normal");1829 });1830 watcher.dispose();1831});1832test("cli help", async () => {1833 const watcher = await createCliWatcher(["--help"]);1834 await waitForExpect(() => {1835 expect(watcher.stdout.split("\n")).toEqual([1836 expect.stringMatching(/hello \d+\.\d+\.\d+/),1837 "Recursively watch a folder for changes",1838 "Usage: hello [ options ] sample-folder",1839 "Options:",1840 "\t-h|--help \tShow this help text.",1841 "\t--exclude <name>",1842 "\t \tExclude all events on files matching <name>",1843 "",1844 ]);1845 });1846 watcher.dispose();1847});1848test("cli version", async () => {1849 const watcher = await createCliWatcher(["--version"]);1850 await waitForExpect(() => {1851 expect(watcher.stdout).toMatch(/hello \d+\.\d+\.\d+/);1852 });1853 watcher.dispose();1854});1855test("cli missing arguments", async () => {1856 const watcher = await createCliWatcher([]);1857 await waitForExpect(() => {1858 expect(watcher.stderr).toBe(`No files specified to watch!1859`);1860 });1861 watcher.dispose();1862});1863test("cli invalid option", async () => {1864 const watcher = await createCliWatcher(["--exclude "]);1865 await waitForExpect(() => {1866 expect(watcher.stdout).toBe(`Usage: hello [ options ] sample-folder1867`);1868 });1869 watcher.dispose();1870});1871test("cli unknown option", async () => {1872 const watcher = await createCliWatcher(["-k"]);1873 await waitForExpect(() => {1874 expect(watcher.stdout).toBe(`Usage: hello [ options ] sample-folder1875`);1876 });1877 watcher.dispose();1878});1879// TODO move folder inside out1880test("rename when moved_to folder name is longer than moved_from", async () => {1881 const tmpDir = await getTmpDir();1882 await mkdir(`${tmpDir}/a/b/c`, { recursive: true });1883 await mkdir(`${tmpDir}/f`);1884 const watcher = await createWatcher([tmpDir]);1885 await rename(`${tmpDir}/a`, `${tmpDir}/f2`);1886 await waitForExpect(() => {1887 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_FROM_DIR1888${tmpDir}/f2,MOVED_TO_DIR1889`);1890 });1891 watcher.clear();1892 await writeFile(`${tmpDir}/f2/g.txt`, "");1893 await waitForExpect(() => {1894 expect(watcher.stdout).toBe(`${tmpDir}/f2/g.txt,CREATE1895${tmpDir}/f2/g.txt,CLOSE_WRITE1896`);1897 });1898 watcher.dispose();1899});1900test("rename when moved_from folder name is longer than moved_to", async () => {1901 const tmpDir = await getTmpDir();1902 await mkdir(`${tmpDir}/f2`);1903 await mkdir(`${tmpDir}/a/b/c`, { recursive: true });1904 const watcher = await createWatcher([tmpDir]);1905 await rename(`${tmpDir}/a`, `${tmpDir}/f`);1906 await waitForExpect(() => {1907 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_FROM_DIR1908${tmpDir}/f,MOVED_TO_DIR1909`);1910 });1911 watcher.clear();1912 await writeFile(`${tmpDir}/f/g.txt`, "");1913 await waitForExpect(() => {1914 expect(watcher.stdout).toBe(`${tmpDir}/f/g.txt,CREATE1915${tmpDir}/f/g.txt,CLOSE_WRITE1916`);1917 });1918 watcher.dispose();1919});1920// TODO test moved_from and unrelated moved_to event1921test.skip("moved_from and unrelated moved_to event", async () => {1922 const tmpDir = await getTmpDir();1923 const tmpDir2 = await getTmpDir();1924 await mkdir(`${tmpDir2}/f2`);1925 await mkdir(`${tmpDir}/a/b/c`, { recursive: true });1926 const watcher = await createWatcher([tmpDir]);1927 await rename(`${tmpDir}/a`, `${tmpDir2}/a`);1928 await rename(`${tmpDir2}/f2`, `${tmpDir}/a`);1929 await rename(`${tmpDir2}/a`, `${tmpDir}/b`);1930 await waitForExpect(() => {1931 expect(watcher.stdout).toBe(`${tmpDir}/a,MOVED_FROM_DIR1932${tmpDir}/a,MOVED_TO_DIR1933${tmpDir}/b,MOVED_TO_DIR1934`);1935 });1936 watcher.clear();1937 await writeFile(`${tmpDir}/a/g.txt`, "");1938 await writeFile(`${tmpDir}/b/h.txt`, "");1939 await waitForExpect(() => {1940 expect(watcher.stdout).toBe(`${tmpDir}/a/g.txt,CREATE...
watcher.js
Source:watcher.js
...19 it('break on change', function() {20 var obj = {},21 property = 'prop';22 obj[property] = true;23 var watcher = createWatcher({24 obj: obj,25 property: property26 });27 var spy = sinon.spy(watcher, '_break');28 obj[property] = true;29 expect(spy.callCount).to.be(0);30 obj[property] = false;31 expect(spy.callCount).to.be(1);32 obj[property] = false;33 expect(spy.callCount).to.be(1);34 obj[property] = true;35 expect(spy.callCount).to.be(2);36 });37 it('configed beforeSet', function() {38 var obj = {},39 property = 'prop',40 retValue = true,41 beforeSet = function() {42 return retValue;43 };44 var watcher = createWatcher({45 obj: obj,46 property: property,47 beforeSet: beforeSet48 });49 var spy = sinon.spy(watcher, 'beforeSet');50 obj[property] = 'aaa';51 var junk = obj[property];52 junk = obj[property];53 expect(spy.callCount).to.be(1);54 expect(spy.firstCall.returnValue).to.be(retValue);55 obj[property] = 'aaa';56 expect(spy.callCount).to.be(2);57 });58 it('configed beforeGet', function() {59 var obj = {},60 property = 'prop',61 retValue = true,62 beforeGet = function() {63 return retValue;64 };65 var watcher = createWatcher({66 obj: obj,67 property: property,68 beforeGet: beforeGet69 });70 var spy = sinon.spy(watcher, 'beforeGet');71 obj[property] = 'aaa';72 obj[property] = 'aaa';73 var junk = obj[property];74 expect(spy.callCount).to.be(1);75 expect(spy.firstCall.returnValue).to.be(retValue);76 junk = obj[property];77 expect(spy.callCount).to.be(2);78 });79 it('beforeSet call args', function() {80 var obj = {},81 property = 'prop',82 startValue = 1,83 firstChange = 2,84 secondChange = 3;85 obj[property] = startValue;86 var watcher = createWatcher({87 obj: obj,88 property: property89 });90 var spy = sinon.spy(watcher, 'beforeSet');91 obj[property] = firstChange;92 obj[property] = secondChange;93 expect(spy.firstCall.args).to.be.eql([firstChange, startValue, obj]);94 expect(spy.secondCall.args).to.be.eql([secondChange, firstChange, obj]);95 });96 it('beforeGet call args', function() {97 var obj = {},98 property = 'prop',99 startValue = 1,100 firstChange = 2;101 obj[property] = startValue;102 var watcher = createWatcher({103 obj: obj,104 property: property105 });106 var spy = sinon.spy(watcher, 'beforeGet');107 var get = obj[property];108 obj[property] = firstChange;109 get = obj[property];110 expect(spy.firstCall.args).to.be.eql([startValue, obj]);111 expect(spy.secondCall.args).to.be.eql([firstChange, obj]);112 });113 it('restore', function() {114 var obj = {},115 property = 'prop',116 firstValue = true;117 obj[property] = firstValue;118 var watcher = createWatcher({119 obj: obj,120 property: property121 });122 var spy = sinon.spy(watcher, 'beforeSet');123 watcher.restore();124 var get = obj[property];125 get = obj[property];126 expect(spy.callCount).to.be(0);127 expect(obj[property]).to.be(firstValue);128 });129 it('beforeSet', function() {130 var obj = {},131 property = 'prop',132 firstValue = true;133 obj[property] = firstValue;134 var watcher = createWatcher({135 obj: obj,136 property: property137 });138 var spy = sinon.spy(watcher, 'beforeSet');139 watcher.restore();140 var get = obj[property];141 get = obj[property];142 expect(spy.callCount).to.be(0);143 expect(obj[property]).to.be(firstValue);144 });145 it('pausing', function() {146 var obj = {},147 property = 'prop';148 var watcher = createWatcher({149 obj: obj,150 property: property151 });152 var spy = sinon.spy(watcher, '_break');153 obj[property] = true;154 expect(spy.callCount).to.be(1);155 watcher.pause();156 obj[property] = false;157 expect(spy.callCount).to.be(1);158 watcher.resume();159 obj[property] = true;160 expect(spy.callCount).to.be(2);161 });162 it('doBreakIf', function() {163 var obj = {},164 property = 'prop';165 var watcher = createWatcher({166 obj: obj,167 doBreakIf: function(val1, val2) {168 //do break if there is two trues in a row169 if (val2 !== undefined) {170 return val1 === true && val2 === true;171 }172 return true;173 },174 property: property175 });176 var spy = sinon.spy(watcher, '_break');177 obj[property] = true;178 expect(spy.callCount).to.be(1);179 obj[property] = true;180 expect(spy.callCount).to.be(2);181 obj[property] = true;182 expect(spy.callCount).to.be(3);183 obj[property] = false;184 obj[property] = true;185 expect(spy.callCount).to.be(3);186 });187 it('doBreak false', function() {188 var obj = {},189 property = 'prop';190 var watcher = createWatcher({191 obj: obj,192 doBreak: false,193 property: property194 });195 var spy = sinon.spy(watcher, '_break');196 obj[property] = true;197 expect(spy.callCount).to.be(0);198 });199 });200 describe('static methods', function() {201 it('pause/resume all', function() {202 var obj = {},203 property = 'prop';204 var watcher = createWatcher({205 obj: obj,206 property: property207 });208 Watcher.pauseAll();209 expect(watcher.isPaused()).to.be(true);210 Watcher.resumeAll();211 expect(watcher.isPaused()).to.be(false);212 });213 it('restoreAll', function() {214 var obj = {},215 property = 'prop';216 var watcher = createWatcher({217 obj: obj,218 property: property219 });220 var spy = sinon.spy(watcher, '_break');221 222 Watcher.restoreAll();223 obj[property] = true;224 expect(spy.callCount).to.be(0);225 expect(Watcher.getAll()).to.be.eql([]);226 });227 });228 });...
eos.js
Source:eos.js
...13const getProducersWorker = createWorker(getProducers.sagaAction, getProducersApi);14const stakeWorker = createWorker(stake.sagaAction, delegatebwApi);15const unstakeWorker = createWorker(unstake.sagaAction, undelegatebwApi);16const voteWorker = createWorker(vote.sagaAction, voteApi);17const watchLoginScatter = createWatcher(loginScatter.sagaTriggerType, loginScatterWorker);18const watchLogoutScatter = createWatcher(logoutScatter.sagaTriggerType, logoutScatterWorker);19const watchGetInfo = createWatcher(getInfo.sagaTriggerType, getInfoWorker);20const watchGetGState = createWatcher(getGState.sagaTriggerType, getGStateWorker);21const watchNewAccount = createWatcher(newAccount.sagaTriggerType, newAccountWorker);22const watchGetAccount = createWatcher(getAccount.sagaTriggerType, getAccountWorker);23const watchGetBalance = createWatcher(getBalance.sagaTriggerType, getBalanceWorker);24const watchGetVoter = createWatcher(getVoter.sagaTriggerType, getVoterWorker);25const watchGetProducers = createWatcher(getProducers.sagaTriggerType, getProducersWorker);26const watchStake = createWatcher(stake.sagaTriggerType, stakeWorker);27const watchUnstake = createWatcher(unstake.sagaTriggerType, unstakeWorker);28const watchVote = createWatcher(vote.sagaTriggerType, voteWorker);29export default [watchLoginScatter, watchLogoutScatter, watchGetInfo, watchGetGState, watchNewAccount,...
canReadAttributes.unit.mjs
Source:canReadAttributes.unit.mjs
...12 return container.firstChild;13};14test('throws if config is invalid', async(t) => {15 const { window, document, errors } = await setup(true);16 window.createWatcher([{}]);17 document.createElement('test-watcher');18 t.is(errors.length, 1);19 t.is(errors[0].message.includes('you passed [{}] instead'), true);20});21test('sets properties with defaults', async(t) => {22 const { window, document, errors } = await setup(true);23 window.createWatcher([{24 name: 'test',25 }]);26 const watcher = createElement(document, '<test-watcher test="no"></test-watcher>');27 t.is(watcher.test, 'no');28 t.is(errors.length, 0);29});30test('sets properties', async(t) => {31 const { window, document, errors } = await setup(true);32 window.createWatcher([{33 name: 'test',34 property: 'prop',35 transform: value => parseInt(value, 10),36 validate: () => true,37 }]);38 const watcher = createElement(document, '<test-watcher test="7"></test-watcher>');39 t.is(watcher.prop, 7);40 t.is(errors.length, 0);41});42test('validates properties', async(t) => {43 const { window, document, errors } = await setup(true);44 window.createWatcher([{45 name: 'test',46 validate: () => false,47 }]);48 createElement(document, '<test-watcher test="7"></test-watcher>');49 t.is(errors.length, 1);50 t.is(errors[0].message.includes('Attribute test does not match'), true);...
post.js
Source:post.js
...18const fetchPostList = createIterator(actions.fetchPostList, fetchPostListApi);19const deletePost = createIterator(actions.deletePost, deletePostApi);20const restorePost = createIterator(actions.restorePost, restorePostApi);21/******************************* WATCHERS *************************************/22const watchImageUpload = createWatcher(actions.UPLOAD_IMAGE_TRIGGER, uploadImage);23const watchReplaceImageSrc = createWatcher(actions.REPLACE_IMAGE_SRC_TRIGGER, replaceImageSrc);24const watchUploadPost = createWatcher(actions.UPLOAD_POST_TRIGGER, uploadPost);25const watchRemoveState = createWatcher(actions.REMOVE_STATE_TRIGGER, removeState);26const watchFetchPostList = createWatcher(actions.FETCH_POST_LIST_TRIGGER, fetchPostList);27const watchDeletePost = createWatcher(actions.DELETE_POST_TRIGGER, deletePost);28const watchRestorePost = createWatcher(actions.RESTORE_POST_TRIGGER, restorePost);29export default [30 watchImageUpload,31 watchReplaceImageSrc,32 watchUploadPost,33 watchRemoveState,34 watchFetchPostList,35 watchDeletePost,36 watchRestorePost...
app.js
Source:app.js
...8const downloadConfig = createWorker(actions.downloadSagaAction, downloadConfigApi);9const downloadScript = createWorker(actions.downloadScriptSagaAction, downloadScriptApi);10const get = createWorker(actions.getSagaAction, getApi);11const update = createWorker(actions.updateSagaAction, updateApi);12const watchRegister = createWatcher(actions.REGISTER_SAGA_TRIGGER, register);13const watchLogin = createWatcher(actions.LOGIN_SAGA_TRIGGER, login);14const watchValidate = createWatcher(actions.VALIDATE_SAGA_TRIGGER, validate);15const watchDownload = createWatcher(actions.DOWNLOAD_CONFIG_SAGA_TRIGGER, downloadConfig);16const watchDownloadScript = createWatcher(actions.DOWNLOAD_SCRIPT_SAGA_TRIGGER, downloadScript);17const watchGet = createWatcher(actions.GET_SAGA_TRIGGER, get);18const watchUpdate = createWatcher(actions.UPDATE_SAGA_TRIGGER, update);...
account.js
Source:account.js
...7const logout = createIterator(actions.logout, logoutApi);8const authCheck = createIterator(actions.authCheck, authCheckApi);9const getAllAdmin = createIterator(actions.getAllAdmin, getAdminAllApi);10/******************************* WATCHERS *************************************/11const watchLogin = createWatcher(actions.LOGIN_TRIGGER, login);12const watchLogout = createWatcher(actions.LOGOUT_TRIGGER, logout);13const watchAuthCheck = createWatcher(actions.AUTH_CHECK_TRIGGER, authCheck);14const watchGetAllAdmin = createWatcher(actions.GET_ALL_ADMIN_TRIGGER, getAllAdmin);15export default [16 watchLogin,17 watchLogout,18 watchAuthCheck,19 watchGetAllAdmin...
index.js
Source:index.js
1// --------------------------------------------------------------------- Require2var chokidar = require('chokidar');3var grammarBuilder = require('grammar-builder');4// ---------------------------------------------------------------------- Define5function createWatcher(grammar) {6 var watcher = chokidar.watch('src/node_modules/modes/' + grammar + '/parser/grammar.pegjs', {7 persistent: true8 });9 watcher.on('change', function(path) {10 grammarBuilder.build(grammar);11 });12 return watcher;13}14function exec() {15 createWatcher('html');16 createWatcher('at');17 createWatcher('at-html');18}19// ---------------------------------------------------------------------- Export20exports.createWatcher = createWatcher;21exports.exec = exec;22// ------------------------------------------------------------- Standalone exec23if (require.main === module) {24 exec();...
Using AI Code Generation
1const fs = require('fs');2const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');3const watcher = createWatcher();4watcher.on('fileChanged', (path) => {5 console.log(path);6});7watcher.watchFile('myFile');8const fs = require('fs');9const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');10const watcher = createWatcher();11watcher.on('fileChanged', (path) => {12 console.log(path);13});14watcher.watchFile('myFile');15const fs = require('fs');16const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');17const watcher = createWatcher();18watcher.on('fileChanged', (path) => {19 console.log(path);20});21watcher.watchFile('myFile');22const fs = require('fs');23const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');24const watcher = createWatcher();25watcher.on('fileChanged', (path) => {26 console.log(path);27});28watcher.watchFile('myFile');29const fs = require('fs');30const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');31const watcher = createWatcher();32watcher.on('fileChanged', (path) => {33 console.log(path);34});35watcher.watchFile('myFile');36const fs = require('fs');37const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');38const watcher = createWatcher();39watcher.on('fileChanged', (path) => {40 console.log(path);41});42watcher.watchFile('myFile');43const fs = require('fs');44const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderApp');45const watcher = createWatcher();46watcher.on('fileChanged', (path) => {47 console.log(path);48});49watcher.watchFile('myFile');
Using AI Code Generation
1const { createWatcher } = require('playwright/lib/server/watcher');2const watcher = createWatcher();3watcher.on('file-changed', (filePath) => {4 console.log('File changed: ' + filePath);5});6watcher.addPath('c:/temp');7watcher.start();8{9 "dependencies": {10 }11}
Using AI Code Generation
1const { createWatcher } = require('playwright/lib/server/playwright');2const watcher = createWatcher();3watcher.on('filechanged', (file) => {4 console.log('File changed: ' + file);5});6watcher.watchFile('test.txt');
Using AI Code Generation
1const { createWatcher } = require('@playwright/test/lib/utils/testrunner/TestRunner');2const { createTestTypeInProject } = require('@playwright/test/lib/utils/testrunner/TestType');3const { createTestType } = require('@playwright/test/lib/utils/testrunner/TestType');4const { createProject } = require('@playwright/test/lib/utils/testrunner/Project');5const { createTestTypeInProject } = require('@playwright/test/lib/utils/testrunner/TestType');6const test = createTestTypeInProject('test', createProject(__dirname, {}));7test('test', async ({ page }) => {8 const watcher = createWatcher();9 watcher.on('test', (test) => {10 console.log('test', test);11 });12 watcher.on('testEnd', (test) => {13 console.log('testEnd', test);14 });15 watcher.on('testStdOut', (test, chunk) => {16 console.log('testStdOut', test, chunk);17 });18 watcher.on('testStdErr', (test, chunk) => {19 console.log('testStdErr', test, chunk);20 });21 watcher.on('testFailed', (test, error) => {22 console.log('testFailed', test, error);23 });24 watcher.on('testTimedOut', (test) => {25 console.log('testTimedOut', test);26 });27 const result = await test.run(page);28 console.log('result', result);29});30const { test } = require('./test');31test('test', async ({ page }) => {32 console.log('test');33});34const { test } = require('./test');35test('test', async ({ page }) => {36 console.log('test');37 throw new Error('error');38});39const { test } = require('./test');40test('test', async ({ page }) => {41 console.log('test');42 await new Promise((resolve) => setTimeout(resolve, 10000));43});44testEnd {
Using AI Code Generation
1const { createWatcher } = require('playwright-core/lib/server/browserContext');2const watcher = createWatcher();3watcher.on('close', () => console.log('Browser closed'));4await browser.newContext();5await browser.close();6await watcher.waitForEvent('close');7 at Timeout._onTimeout (/Users/abc/Downloads/playwright-test/node_modules/playwright-core/lib/server/browserContext.js:112:26)8 at listOnTimeout (internal/timers.js:554:17)9 at processTimers (internal/timers.js:497:7)
Using AI Code Generation
1const { createWatcher } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');2const watcher = createWatcher();3watcher.on('selector', (selector, frame) => {4 console.log(`selector: ${selector}, frame: ${frame}`);5});6watcher.on('frameattached', (frame) => {7 console.log(`frameattached: ${frame}`);8});9watcher.on('framenavigated', (frame) => {10 console.log(`framenavigated: ${frame}`);11});12watcher.start();13watcher.stop();14const { createRecorder } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');15const recorder = createRecorder();16recorder.on('recordingstarted', () => {17 console.log('recordingstarted');18});19recorder.on('recordingstopped', () => {20 console.log('recordingstopped');21});22recorder.on('recordingerror', (error) => {23 console.log(`recordingerror: ${error}`);24});25recorder.start();26recorder.stop();27const { createRecorder } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');28const recorder = createRecorder();29recorder.on('recordingstarted', () => {30 console.log('recordingstarted');31});32recorder.on('recordingstopped', () => {33 console.log('recordingstopped');34});35recorder.on('recordingerror', (error) => {36 console.log(`recordingerror: ${error}`);37});38recorder.start();39recorder.stop();40const { createRecorder } = require('playwright/lib/server/supplements/recorder/recorderSupplement.js');41const recorder = createRecorder();42recorder.on('recordingstarted', () => {43 console.log('recordingstarted');44});45recorder.on('recordingstopped', () => {46 console.log('recordingstopped');47});48recorder.on('recordingerror',
Using AI Code Generation
1const { createWatcher } = require('playwright-core/lib/server/watcher');2const path = require('path');3const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {4});5watcher.on('change', () => {6 console.log('File changed!');7});8watcher.close();9const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {10});11watcher.on('change', () => {12 console.log('File changed!');13});14watcher.close();15const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {16});17watcher.on('change', () => {18 console.log('File changed!');19});20watcher.close();21const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {22});23watcher.on('change', () => {24 console.log('File changed!');25});26watcher.close();27const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {28});29watcher.on('change', () => {30 console.log('File changed!');31});32watcher.close();33const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {34});35watcher.on('change', () => {36 console.log('File changed!');37});38watcher.close();39const watcher = createWatcher(path.resolve(__dirname, 'test.html'), {40});41watcher.on('change', () => {42 console.log('File changed!');43});44watcher.close();45const watcher = createWatcher(path.resolve(__dirname, 'test
Using AI Code Generation
1const { createWatcher } = require('playwright/lib/server/watcher');2const watcher = createWatcher();3watcher.watchFile('file1.txt', (event, filename) => {4 console.log(`${event}: ${filename}`);5});6watcher.watchFile('file2.txt', (event, filename) => {7 console.log(`${event}: ${filename}`);8});9watcher.watchFile('file3.txt', (event, filename) => {10 console.log(`${event}: ${filename}`);11});12watcher.start();13watcher.stop();14watcher.addFile('file4.txt');15watcher.addFile('file5.txt');16watcher.addFile('file6.txt');17watcher.removeFile('file4.txt');18watcher.removeFile('file5.txt');19watcher.removeFile('file6.txt');20watcher.close();21watcher.getWatchedFiles();22watcher.getWatchedDirectories();23watcher.getWatchedFilesForDirectory('path/to/dir');24watcher.getWatchedDirectoriesForDirectory('path/to/dir');25watcher.getWatchedFilesForAllDirectories();26watcher.getWatchedDirectoriesForAllDirectories();27watcher.getWatchedFilesForAllDirectoriesInDirectory('path/to/dir');28watcher.getWatchedDirectoriesForAllDirectoriesInDirectory('path/to/dir');29watcher.getWatchedFilesForAllDirectoriesInDirectoryRecursively('path/to/dir');30watcher.getWatchedDirectoriesForAllDirectoriesInDirectoryRecursively('path/to/dir');
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!