Use a private utility function to wait for all native watchers to stop

This commit is contained in:
Ash Wilson 2017-06-21 10:24:06 -04:00
parent 12c961c8b9
commit be681d1324
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A
3 changed files with 12 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import fsCb from 'fs-plus'
import path from 'path'
import {CompositeDisposable} from 'event-kit'
import FileSystemManager from '../src/filesystem-manager'
import FileSystemManager, {stopAllWatchers} from '../src/filesystem-manager'
tempCb.track()
@ -24,12 +24,8 @@ describe('FileSystemManager', function () {
afterEach(async function () {
subs.dispose()
const cleanup = [temp.cleanup()]
const nativeWatchers = manager.nativeWatchers.tree.leaves().map(node => node.getNativeWatcher())
for (const native of nativeWatchers) {
cleanup.push(native.stop())
}
await Promise.all(cleanup)
await stopAllWatchers(manager)
await temp.cleanup()
})
function waitForEvent (fn) {

View File

@ -46,7 +46,7 @@ TextBuffer = require 'text-buffer'
Gutter = require './gutter'
TextEditorRegistry = require './text-editor-registry'
AutoUpdateManager = require './auto-update-manager'
FileSystemManager = require './filesystem-manager'
FileSystemManager = require('./filesystem-manager').default
# Essential: Atom global for dealing with packages, themes, menus, and the window.
#

View File

@ -222,3 +222,11 @@ export default class FileSystemManager {
return watcher
}
}
// Private: Return a Promise that resolves when all {NativeWatcher} instances associated with a FileSystemManager
// have stopped listening. This is useful for `afterEach()` blocks in unit tests.
export function stopAllWatchers (manager) {
return Promise.all(
Array.from(manager.liveWatchers, watcher => watcher.stop())
)
}