Prepend a drive root to lookup paths on Windows

This commit is contained in:
Ash Wilson 2017-08-02 14:55:12 -04:00
parent b9080bcec5
commit 1e739aa891
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A

View File

@ -20,11 +20,16 @@ function findRootDirectory () {
}
const ROOT = findRootDirectory()
function absolute(...parts) {
function absolute (...parts) {
const candidate = path.join(...parts)
return path.isAbsolute(candidate) ? candidate : path.join(ROOT, candidate)
}
function prependRoot (...parts) {
const candidate = path.join(...parts)
return path.isAbsolute(candidate) ? parts : [ROOT].concat(parts)
}
class MockWatcher {
constructor (normalizedPath) {
this.normalizedPath = normalizedPath
@ -277,19 +282,19 @@ describe('NativeWatcherRegistry', function () {
expect(childWatcher0.native).toBe(CHILD0)
expect(childWatcher1.native).toBe(CHILD1)
expect(registry.tree.root.lookup(['parent']).when({
expect(registry.tree.root.lookup(prependRoot('parent')).when({
parent: () => false,
missing: () => false,
children: () => true
})).toBe(true)
expect(registry.tree.root.lookup(['parent', 'child0']).when({
expect(registry.tree.root.lookup(prependRoot('parent', 'child0')).when({
parent: () => true,
missing: () => false,
children: () => false
})).toBe(true)
expect(registry.tree.root.lookup(['parent', 'child1']).when({
expect(registry.tree.root.lookup(prependRoot('parent', 'child1')).when({
parent: () => true,
missing: () => false,
children: () => false
@ -336,19 +341,19 @@ describe('NativeWatcherRegistry', function () {
expect(childWatcher0.native).toBe(CHILD0)
expect(childWatcher1.native).toBe(CHILD0)
expect(registry.tree.root.lookup(['parent']).when({
expect(registry.tree.root.lookup(prependRoot('parent')).when({
parent: () => false,
missing: () => false,
children: () => true
})).toBe(true)
expect(registry.tree.root.lookup(['parent', 'child0']).when({
expect(registry.tree.root.lookup(prependRoot('parent', 'child0')).when({
parent: () => true,
missing: () => false,
children: () => false
})).toBe(true)
expect(registry.tree.root.lookup(['parent', 'child0', 'child1']).when({
expect(registry.tree.root.lookup(prependRoot('parent', 'child0', 'child1')).when({
parent: () => true,
missing: () => false,
children: () => false