Fix a note-watcher error during deactivation

This commit is contained in:
Seongjae Lee
2016-07-03 10:44:32 -07:00
parent b22d94450c
commit 68c8b47ffb
3 changed files with 95 additions and 94 deletions
+2 -1
View File
@@ -19,6 +19,7 @@ class NoteWatcher extends EventEmitter
@_startWatcher()
save: ->
return unless @_state == 'ready'
cache = {
baseDirectory: @_baseDirectory,
extensions: @_extensions,
@@ -31,7 +32,7 @@ class NoteWatcher extends EventEmitter
zlib.deflateSync(JSON.stringify(cache)))
close: ->
@_watcher.close()
@_watcher?.close()
search: (query) ->
if query? and query.length > 0
+3 -3
View File
@@ -35,14 +35,14 @@ describe "nvAtom", ->
it "checks if we banned the default directory under packages directory", ->
noteDirectory = path.join(process.env.ATOM_HOME, 'packages', 'nvatom', 'notebook')
atom.config.set('nvatom.directory', noteDirectory)
waitsForPromise ->
atom.packages.activatePackage('nvatom')
runs ->
waitsForPromise ->
atom.packages.activatePackage('notifications')
runs ->
notificationContainer = workspaceElement.querySelector('atom-notifications')
notification = notificationContainer.querySelector('atom-notification.fatal')
+90 -90
View File
@@ -25,98 +25,98 @@ describe 'note-watcher', ->
afterEach ->
watcher.close()
# it 'handles a symbolic link note properly', ->
# spy = jasmine.createSpy()
# watcher.on 'update', spy
#
# anotherDirectoryPath = temp.mkdirSync()
# fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
# fs.symlinkSync(path.join(anotherDirectoryPath, 'baz.md'), path.join(directoryPath, 'baz.md'))
#
# waitsFor -> spy.wasCalled
#
# runs ->
# result = watcher.search('baz')
# expect(result.length).toBe(1)
# it 'handles a symbolic link directory properly', ->
# spy = jasmine.createSpy()
# watcher.on 'update', spy
#
# anotherDirectoryPath = temp.mkdirSync()
# fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
# fs.symlinkSync(anotherDirectoryPath, path.join(directoryPath, 'baz'))
#
# waitsFor -> spy.wasCalled
#
# runs ->
# result = watcher.search('baz')
# expect(result.length).toBe(1)
# expect(result[0].filePath).toBe(path.join(directoryPath, 'baz', 'baz.md'))
it 'handles a symbolic link note properly', ->
spy = jasmine.createSpy()
watcher.on 'update', spy
anotherDirectoryPath = temp.mkdirSync()
fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
fs.symlinkSync(path.join(anotherDirectoryPath, 'baz.md'), path.join(directoryPath, 'baz.md'))
waitsFor -> spy.wasCalled
runs ->
result = watcher.search('baz')
expect(result.length).toBe(1)
# it 'handles paired symbolic links properly without falling into an infinite loop', ->
# spy = jasmine.createSpy()
# watcher.on 'update', spy
#
# anotherDirectoryPath = temp.mkdirSync()
# fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
# fs.symlinkSync(anotherDirectoryPath, path.join(directoryPath, 'bazDir'))
# fs.symlinkSync(directoryPath, path.join(anotherDirectoryPath, 'fooDir'))
#
# waitsFor -> spy.wasCalled
#
# runs ->
# result = watcher.search('baz')
# expect(result.length).toBe(1)
# expect(result[0].filePath).toBe(path.join(directoryPath, 'bazDir', 'baz.md'))
it 'handles a symbolic link directory properly', ->
spy = jasmine.createSpy()
watcher.on 'update', spy
# it 'watches adding a file', ->
# spy = jasmine.createSpy()
# watcher.on 'update', spy
# fs.writeFileSync(path.join(directoryPath, 'note.md'), 'hello world')
#
# waitsFor -> spy.wasCalled
#
# it 'watches changing a file', ->
# spy = jasmine.createSpy()
# watcher.on 'update', spy
# filePath = path.join(directoryPath, 'note.md')
# fs.writeFileSync(filePath, 'hello world')
# waitsFor -> spy.callCount == 1
#
# runs -> fs.writeFileSync(filePath, 'hello world 2')
#
# waitsFor -> spy.callCount == 2
#
# it 'watches removing a file', ->
# spy = jasmine.createSpy()
# watcher.on('update', spy)
# filePath = path.join(directoryPath, 'note.md')
# fs.writeFileSync(filePath, 'hello world')
# waitsFor -> spy.callCount == 1
#
# runs -> fs.unlinkSync(filePath)
#
# waitsFor -> spy.callCount == 2
#
# it 'searches', ->
# result = watcher.search('programming')
# expect(result.length).toBe(1)
# expect(result[0].title).toBe('foo')
#
# it 'saves and loads', ->
# watcher.save()
# watcher.close()
# watcher = new NoteWatcher(directoryPath)
# spy = jasmine.createSpy()
# watcher.on 'ready', spy
#
# waitsFor -> spy.wasCalled
#
# runs ->
# result = watcher.search('programming')
# expect(result.length).toBe(1)
# expect(result[0].title).toBe('foo')
anotherDirectoryPath = temp.mkdirSync()
fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
fs.symlinkSync(anotherDirectoryPath, path.join(directoryPath, 'baz'))
waitsFor -> spy.wasCalled
runs ->
result = watcher.search('baz')
expect(result.length).toBe(1)
expect(result[0].filePath).toBe(path.join(directoryPath, 'baz', 'baz.md'))
it 'handles paired symbolic links properly without falling into an infinite loop', ->
spy = jasmine.createSpy()
watcher.on 'update', spy
anotherDirectoryPath = temp.mkdirSync()
fs.writeFileSync(path.join(anotherDirectoryPath, 'baz.md'), 'A common name for the foobar, also foobaz.')
fs.symlinkSync(anotherDirectoryPath, path.join(directoryPath, 'bazDir'))
fs.symlinkSync(directoryPath, path.join(anotherDirectoryPath, 'fooDir'))
waitsFor -> spy.wasCalled
runs ->
result = watcher.search('baz')
expect(result.length).toBe(1)
expect(result[0].filePath).toBe(path.join(directoryPath, 'bazDir', 'baz.md'))
it 'watches adding a file', ->
spy = jasmine.createSpy()
watcher.on 'update', spy
fs.writeFileSync(path.join(directoryPath, 'note.md'), 'hello world')
waitsFor -> spy.wasCalled
it 'watches changing a file', ->
spy = jasmine.createSpy()
watcher.on 'update', spy
filePath = path.join(directoryPath, 'note.md')
fs.writeFileSync(filePath, 'hello world')
waitsFor -> spy.callCount == 1
runs -> fs.writeFileSync(filePath, 'hello world 2')
waitsFor -> spy.callCount == 2
it 'watches removing a file', ->
spy = jasmine.createSpy()
watcher.on('update', spy)
filePath = path.join(directoryPath, 'note.md')
fs.writeFileSync(filePath, 'hello world')
waitsFor -> spy.callCount == 1
runs -> fs.unlinkSync(filePath)
waitsFor -> spy.callCount == 2
it 'searches', ->
result = watcher.search('programming')
expect(result.length).toBe(1)
expect(result[0].title).toBe('foo')
it 'saves and loads', ->
watcher.save()
watcher.close()
watcher = new NoteWatcher(directoryPath)
spy = jasmine.createSpy()
watcher.on 'ready', spy
waitsFor -> spy.wasCalled
runs ->
result = watcher.search('programming')
expect(result.length).toBe(1)
expect(result[0].title).toBe('foo')
it 'loads the modified contents correctly', ->
watcher.save()