Use a real clock and artificial file mtimes to work with nsfw

This commit is contained in:
Ash Wilson 2017-09-12 10:15:55 -04:00
parent 21e220cd5f
commit fa0bd1e049
No known key found for this signature in database
GPG Key ID: 81B1DDB704F69D2A

View File

@ -896,19 +896,15 @@ describe "Config", ->
describe ".observeUserConfig()", ->
updatedHandler = null
writeConfigFile = (data) ->
previousSetTimeoutCallCount = setTimeout.callCount
runs ->
fs.writeFileSync(atom.config.configFilePath, data)
# waitsFor "debounced config file load", ->
# setTimeout.callCount > previousSetTimeoutCallCount
waitsFor "file written", ->
fs.readFileSync(atom.config.configFilePath, 'utf8') is data
runs ->
advanceClock(1000)
writeConfigFile = (data, secondsInFuture = 0) ->
fs.writeFileSync(atom.config.configFilePath, data)
future = (Date.now() / 1000) + secondsInFuture
fs.utimesSync(atom.config.configFilePath, future, future)
beforeEach ->
console.log 'beforeEach'
jasmine.useRealClock()
atom.config.setSchema 'foo',
type: 'object'
properties:
@ -924,7 +920,7 @@ describe "Config", ->
default: 12
expect(fs.existsSync(atom.config.configDirPath)).toBeFalsy()
fs.writeFileSync atom.config.configFilePath, """
writeConfigFile """
'*':
foo:
bar: 'baz'
@ -955,9 +951,11 @@ describe "Config", ->
atom.config.unobserveUserConfig()
fs.removeSync(dotAtomPath)
fit "updates the config data", ->
writeConfigFile("foo: { bar: 'quux', baz: 'bar'}")
it "updates the config data", ->
writeConfigFile "foo: { bar: 'quux', baz: 'bar'}", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
expect(atom.config.get('foo.bar')).toBe 'quux'
expect(atom.config.get('foo.baz')).toBe 'bar'
@ -965,7 +963,7 @@ describe "Config", ->
it "does not fire a change event for paths that did not change", ->
atom.config.onDidChange 'foo.bar', noChangeSpy = jasmine.createSpy()
writeConfigFile("foo: { bar: 'baz', baz: 'ok'}")
writeConfigFile "foo: { bar: 'baz', baz: 'ok'}", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
@ -980,7 +978,8 @@ describe "Config", ->
items:
type: 'string'
writeConfigFile("foo: { bar: ['baz', 'ok']}")
updatedHandler.reset()
writeConfigFile "foo: { bar: ['baz', 'ok']}", 4
waitsFor 'update event', -> updatedHandler.callCount > 0
runs -> updatedHandler.reset()
@ -988,7 +987,7 @@ describe "Config", ->
noChangeSpy = jasmine.createSpy()
atom.config.onDidChange('foo.bar', noChangeSpy)
writeConfigFile("foo: { bar: ['baz', 'ok'], baz: 'another'}")
writeConfigFile "foo: { bar: ['baz', 'ok'], baz: 'another'}", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
@ -1005,7 +1004,7 @@ describe "Config", ->
'*':
foo:
scoped: false
"""
""", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
@ -1023,7 +1022,7 @@ describe "Config", ->
'.source.ruby':
foo:
scoped: true
"""
""", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
@ -1033,7 +1032,7 @@ describe "Config", ->
describe "when the config file changes to omit a setting with a default", ->
it "resets the setting back to the default", ->
writeConfigFile("foo: { baz: 'new'}")
writeConfigFile "foo: { baz: 'new'}", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
runs ->
expect(atom.config.get('foo.bar')).toBe 'def'
@ -1041,20 +1040,20 @@ describe "Config", ->
describe "when the config file changes to be empty", ->
beforeEach ->
writeConfigFile("")
updatedHandler.reset()
writeConfigFile "", 4
waitsFor 'update event', -> updatedHandler.callCount > 0
it "resets all settings back to the defaults", ->
expect(updatedHandler.callCount).toBe 1
expect(atom.config.get('foo.bar')).toBe 'def'
atom.config.set("hair", "blonde") # trigger a save
advanceClock(500)
expect(atom.config.save).toHaveBeenCalled()
waitsFor 'save', -> atom.config.save.callCount > 0
describe "when the config file subsequently changes again to contain configuration", ->
beforeEach ->
updatedHandler.reset()
writeConfigFile("foo: bar: 'newVal'")
writeConfigFile "foo: bar: 'newVal'", 2
waitsFor 'update event', -> updatedHandler.callCount > 0
it "sets the setting to the value specified in the config file", ->
@ -1064,24 +1063,25 @@ describe "Config", ->
addErrorHandler = null
beforeEach ->
atom.notifications.onDidAddNotification addErrorHandler = jasmine.createSpy()
writeConfigFile("}}}")
writeConfigFile "}}}", 4
waitsFor "error to be logged", -> addErrorHandler.callCount > 0
it "logs a warning and does not update config data", ->
expect(updatedHandler.callCount).toBe 0
expect(atom.config.get('foo.bar')).toBe 'baz'
atom.config.set("hair", "blonde") # trigger a save
expect(atom.config.save).not.toHaveBeenCalled()
describe "when the config file subsequently changes again to contain valid cson", ->
beforeEach ->
writeConfigFile("foo: bar: 'newVal'")
updatedHandler.reset()
writeConfigFile "foo: bar: 'newVal'", 6
waitsFor 'update event', -> updatedHandler.callCount > 0
it "updates the config data and resumes saving", ->
atom.config.set("hair", "blonde")
advanceClock(500)
expect(atom.config.save).toHaveBeenCalled()
waitsFor 'save', -> atom.config.save.callCount > 0
describe ".initializeConfigDirectory()", ->
beforeEach ->
@ -1757,6 +1757,7 @@ describe "Config", ->
expect(atom.config.set('foo.bar.str_options', 'One')).toBe false
expect(atom.config.get('foo.bar.str_options')).toEqual 'two'
describe "when .set/.unset is called prior to .loadUserConfig", ->
console.log 'this test'
beforeEach ->