mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
d1c587a01c
More spec fixes replace process.nextTick with setTimeout(fn, 0) for specs Also added an unspy in the afterEach Temporarily disable specs fix(spec): start fixing specs Summary: This is the WIP fix to our spec runner. Several tests have been completely commented out that will require substantially more work to fix. These have been added to our sprint backlog. Other tests have been fixed to update to new APIs or to deal with genuine bugs that were introduced without our knowing! The most common non-trivial change relates to observing the `NylasAPI` and `NylasAPIRequest`. We used to observe the arguments to `makeRequest`. Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do: `NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the `options` passed into the object. the `.object` property grabs the context of the spy when it was last called. Fixing these tests uncovered several concerning issues with our test runner. I spent a while tracking down why our participant-text-field-spec was failling every so often. I chose that spec because it was the first spec to likely fail, thereby requiring looking at the least number of preceding files. I tried binary searching, turning on and off, several files beforehand only to realize that the failure rate was not determined by a particular preceding test, but rather the existing and quantity of preceding tests, AND the number of console.log statements I had. There is some processor-dependent race condition going on that needs further investigation. I also discovered an issue with the file-download-spec. We were getting errors about it accessing a file, which was very suspicious given the code stubs out all fs access. This was caused due to a spec that called an async function outside ot a `waitsForPromise` block or a `waitsFor` block. The test completed, the spies were cleaned up, but the downstream async chain was still running. By the time the async chain finished the runner was already working on the next spec and the spies had been restored (causing the real fs access to run). Juan had an idea to kill the specs once one fails to prevent cascading failures. I'll implement this in the next diff update Test Plan: npm test Reviewers: juan, halla, jackie Differential Revision: https://phab.nylas.com/D3501 Disable other specs Disable more broken specs All specs turned off till passing state Use async-safe versions of spec functions Add async test spec Remove unused package code Remove canary spec
72 lines
2.2 KiB
CoffeeScript
72 lines
2.2 KiB
CoffeeScript
{NylasAPI,
|
|
NylasAPIRequest,
|
|
Category,
|
|
AccountStore,
|
|
DatabaseStore,
|
|
SyncbackCategoryTask,
|
|
DatabaseTransaction} = require "nylas-exports"
|
|
|
|
xdescribe "SyncbackCategoryTask", ->
|
|
describe "performRemote", ->
|
|
pathOf = (fn) ->
|
|
fn.calls[0].args[0].path
|
|
|
|
accountIdOf = (fn) ->
|
|
fn.calls[0].args[0].accountId
|
|
|
|
nameOf = (fn) ->
|
|
fn.calls[0].args[0].body.display_name
|
|
|
|
makeAccount = ({usesFolders, usesLabels} = {}) ->
|
|
spyOn(AccountStore, "accountForId").andReturn {
|
|
usesFolders: -> usesFolders
|
|
usesLabels: -> usesLabels
|
|
}
|
|
|
|
makeTask = ->
|
|
category = new Category
|
|
displayName: "important emails"
|
|
accountId: "account 123"
|
|
clientId: "local-444"
|
|
new SyncbackCategoryTask
|
|
category: category
|
|
|
|
beforeEach ->
|
|
spyOn(NylasAPIRequest.prototype, "run").andCallFake ->
|
|
Promise.resolve(id: "server-444")
|
|
spyOn(DatabaseTransaction.prototype, "persistModel")
|
|
|
|
it "sends API req to /labels if the account uses labels", ->
|
|
makeAccount(usesLabels: true)
|
|
task = makeTask()
|
|
task.performRemote({})
|
|
expect(pathOf(NylasAPIRequest.prototype.run)).toBe "/labels"
|
|
|
|
it "sends API req to /folders if the account uses folders", ->
|
|
makeAccount(usesFolders: true)
|
|
task = makeTask()
|
|
task.performRemote({})
|
|
expect(pathOf(NylasAPIRequest.prototype.run)).toBe "/folders"
|
|
|
|
it "sends the account id", ->
|
|
makeAccount()
|
|
task = makeTask()
|
|
task.performRemote({})
|
|
expect(accountIdOf(NylasAPIRequest.prototype.run)).toBe "account 123"
|
|
|
|
it "sends the display name in the body", ->
|
|
makeAccount()
|
|
task = makeTask()
|
|
task.performRemote({})
|
|
expect(nameOf(NylasAPIRequest.prototype.run)).toBe "important emails"
|
|
|
|
it "adds server id to the category, then saves the category", ->
|
|
makeAccount()
|
|
waitsForPromise ->
|
|
task = makeTask()
|
|
task.performRemote({})
|
|
.then ->
|
|
expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled()
|
|
model = DatabaseTransaction.prototype.persistModel.calls[0].args[0]
|
|
expect(model.clientId).toBe "local-444"
|
|
expect(model.serverId).toBe "server-444"
|