<commit_before>const fs = require('fs-extra')

const {Fixture} = require('../helper')
const {EventMatcher} = require('../matcher');

[false, true].forEach(poll => {
  describe(`rapid events with poll = ${poll}`, function () {
    let fixture, matcher

    beforeEach(async function () {
      fixture = new Fixture()
      await fixture.before()
      await fixture.log()

      matcher = new EventMatcher(fixture)
      await matcher.watch([], {poll})
    })

    afterEach(async function () {
      await fixture.after(this.currentTest)
    })

    // The polling thread will never be able to distinguish rapid events
    if (!poll) {
      it.stress(500, 'understands coalesced creation and deletion events', async function () {
        const deletedPath = fixture.watchPath('deleted.txt')
        const recreatedPath = fixture.watchPath('recreated.txt')
        const createdPath = fixture.watchPath('created.txt')

        await fs.writeFile(deletedPath, 'initial contents\n')
        await until('file creation event arrives', matcher.allEvents(
          {action: 'created', kind: 'file', path: deletedPath}
        ))

        await fs.unlink(deletedPath)
        await fs.writeFile(recreatedPath, 'initial contents\n')
        await fs.unlink(recreatedPath)
        await fs.writeFile(recreatedPath, 'newly created\n')
        await fs.writeFile(createdPath, 'and another\n')

        await until('all events arrive', matcher.orderedEvents(
          {action: 'deleted', path: deletedPath},
          {action: 'created', kind: 'file', path: recreatedPath},
          {action: 'deleted', path: recreatedPath},
          {action: 'created', kind: 'file', path: recreatedPath},
          {action: 'created', kind: 'file', path: createdPath}
        ))
      })

      it('understands rapid creation and rename events', async function () {
        const originalPath = fixture.watchPath('created.txt')
        const finalPath = fixture.watchPath('final.txt')<commit_msg>Windows can't reliably infer the kind of recreatedPath<commit_after>const fs = require('fs-extra')

const {Fixture} = require('../helper')
const {EventMatcher} = require('../matcher');

[false, true].forEach(poll => {
  describe(`rapid events with poll = ${poll}`, function () {
    let fixture, matcher

    beforeEach(async function () {
      fixture = new Fixture()
      await fixture.before()
      await fixture.log()

      matcher = new EventMatcher(fixture)
      await matcher.watch([], {poll})
    })

    afterEach(async function () {
      await fixture.after(this.currentTest)
    })

    // The polling thread will never be able to distinguish rapid events
    if (!poll) {
      it.stress(500, 'understands coalesced creation and deletion events', async function () {
        const deletedPath = fixture.watchPath('deleted.txt')
        const recreatedPath = fixture.watchPath('recreated.txt')
        const createdPath = fixture.watchPath('created.txt')

        await fs.writeFile(deletedPath, 'initial contents\n')
        await until('file creation event arrives', matcher.allEvents(
          {action: 'created', kind: 'file', path: deletedPath}
        ))

        await fs.unlink(deletedPath)
        await fs.writeFile(recreatedPath, 'initial contents\n')
        await fs.unlink(recreatedPath)
        await fs.writeFile(recreatedPath, 'newly created\n')
        await fs.writeFile(createdPath, 'and another\n')

        await until('all events arrive', matcher.orderedEvents(
          {action: 'deleted', path: deletedPath},
          {action: 'created', path: recreatedPath},
          {action: 'deleted', path: recreatedPath},
          {action: 'created', kind: 'file', path: recreatedPath},
          {action: 'created', kind: 'file', path: createdPath}
        ))
      })

      it('understands rapid creation and rename events', async function () {
        const originalPath = fixture.watchPath('created.txt')
        const finalPath = fixture.watchPath('final.txt')
{'fraction_non_alphanumeric': 0.1284888106613025, 'fraction_numerical': 0.0015086748805632386, 'mean_word_length': 3.05091649694501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3594884', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1105, 'n_words': 298}