<commit_before>import fs from 'fs-extra'

import syncGlob from '../src/index'
import { beforeEachSpec, afterAllSpecs, awaitMatch, compare, compareDir } from './helpers'

const watch = true

describe('node-sync-glob watch', () => {
  beforeEach(beforeEachSpec)
  afterAll(afterAllSpecs)

  it('should sync a file', (done) => {
    const close = syncGlob('tmp/mock/a.txt', 'tmp/sync/', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/a.txt', 'foobarbaz')
      },
      'copied', compare(() => {
        fs.removeSync('tmp/mock/a.txt')
      }),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/a.txt')).toBe(false)
        close()
        done()
      }
    ))
  })

  it('should sync an array of files', (done) => {
    const close = syncGlob(['tmp/mock/a.txt', 'tmp/mock/b.txt'], 'tmp/sync', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/b.txt', 'foobarbaz')
      },
      'copied', compare(() => {
        fs.removeSync('tmp/mock/b.txt')
      }),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/a.txt')).toBe(true)
        expect(fs.existsSync('tmp/sync/b.txt')).toBe(false)
        close()
        done()
      }
    ))
  })

  it('should sync a directory', (done) => {
    const close = syncGlob('tmp/mock/foo', 'tmp/sync/', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/foo/b.txt', 'foobarbaz')
      },
      'copied', compareDir(() => {
        setImmediate(() => {
          fs.removeSync('tmp/mock/foo/d.txt')
        })
      }, 'tmp/mock/foo', 'tmp/sync'),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/b.txt')).toBe(true)
        expect(fs.existsSync('tmp/sync/d.txt')).toBe(false)
        close()
        done()
      }
    ))
  })
})
<commit_msg>try some timeout<commit_after>import fs from 'fs-extra'

import syncGlob from '../src/index'
import { beforeEachSpec, afterAllSpecs, awaitMatch, compare, compareDir } from './helpers'

const watch = true

describe('node-sync-glob watch', () => {
  beforeEach(beforeEachSpec)
  afterAll(afterAllSpecs)

  it('should sync a file', (done) => {
    const close = syncGlob('tmp/mock/a.txt', 'tmp/sync/', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/a.txt', 'foobarbaz')
      },
      'copied', compare(() => {
        fs.removeSync('tmp/mock/a.txt')
      }),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/a.txt')).toBe(false)
        close()
        done()
      }
    ))
  })

  it('should sync an array of files', (done) => {
    const close = syncGlob(['tmp/mock/a.txt', 'tmp/mock/b.txt'], 'tmp/sync', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/b.txt', 'foobarbaz')
      },
      'copied', compare(() => {
        fs.removeSync('tmp/mock/b.txt')
      }),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/a.txt')).toBe(true)
        expect(fs.existsSync('tmp/sync/b.txt')).toBe(false)
        close()
        done()
      }
    ))
  })

  it('should sync a directory', (done) => {
    const close = syncGlob('tmp/mock/foo', 'tmp/sync/', { watch }, awaitMatch(
      'watch', () => {
        fs.appendFileSync('tmp/mock/foo/b.txt', 'foobarbaz')
      },
      'copied', compareDir(() => {
        setTimeout(() => {
          fs.removeSync('tmp/mock/foo/d.txt')
        })
      }, 'tmp/mock/foo', 'tmp/sync'),
      'removed', () => {
        expect(fs.existsSync('tmp/sync/b.txt')).toBe(true)
        expect(fs.existsSync('tmp/sync/d.txt')).toBe(false)
        close()
        done()
      }
    ))
  })
})

{'fraction_non_alphanumeric': 0.21017881705639616, 'fraction_numerical': 0.0, 'mean_word_length': 2.3266239707227814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '4356554', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1257, 'n_words': 190}