Mailspring/spec/stores/database-setup-query-builder-spec.es6
Evan Morikawa d1c587a01c fix(spec): add support for async specs and disable misbehaving ones
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
2016-12-15 13:02:00 -05:00

72 lines
3.3 KiB
JavaScript

/* eslint quote-props: 0 */
import TestModel from '../fixtures/db-test-model';
import Attributes from '../../src/flux/attributes';
import DatabaseSetupQueryBuilder from '../../src/flux/stores/database-setup-query-builder';
xdescribe("DatabaseSetupQueryBuilder", function DatabaseSetupQueryBuilderSpecs() {
beforeEach(() => {
this.builder = new DatabaseSetupQueryBuilder();
});
describe("setupQueriesForTable", () => {
it("should return the queries for creating the table and the primary unique index", () => {
TestModel.attributes = {
'attrQueryable': Attributes.DateTime({
queryable: true,
modelKey: 'attrQueryable',
jsonKey: 'attr_queryable',
}),
'attrNonQueryable': Attributes.Collection({
modelKey: 'attrNonQueryable',
jsonKey: 'attr_non_queryable',
}),
};
const queries = this.builder.setupQueriesForTable(TestModel);
const expected = [
'CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,attr_queryable INTEGER)',
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`)',
];
queries.map((query, i) =>
expect(query).toBe(expected[i])
);
});
it("should correctly create join tables for models that have queryable collections", () => {
TestModel.configureWithCollectionAttribute();
const queries = this.builder.setupQueriesForTable(TestModel);
const expected = [
'CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,client_id TEXT,server_id TEXT,other TEXT)',
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`)',
'CREATE TABLE IF NOT EXISTS `TestModelCategory` (id TEXT KEY,`value` TEXT,other TEXT)',
'CREATE INDEX IF NOT EXISTS `TestModelCategory_id` ON `TestModelCategory` (`id` ASC)',
'CREATE UNIQUE INDEX IF NOT EXISTS `TestModelCategory_val_id` ON `TestModelCategory` (`value` ASC, `id` ASC)',
];
queries.map((query, i) =>
expect(query).toBe(expected[i])
);
});
it("should use the correct column type for each attribute", () => {
TestModel.configureWithAllAttributes();
const queries = this.builder.setupQueriesForTable(TestModel);
expect(queries[0]).toBe('CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,datetime INTEGER,string-json-key TEXT,boolean INTEGER,number INTEGER)');
});
describe("when the model provides additional sqlite config", () => {
it("the setup method should return these queries", () => {
TestModel.configureWithAdditionalSQLiteConfig();
spyOn(TestModel.additionalSQLiteConfig, 'setup').andCallThrough();
const queries = this.builder.setupQueriesForTable(TestModel);
expect(TestModel.additionalSQLiteConfig.setup).toHaveBeenCalledWith();
expect(queries.pop()).toBe('CREATE INDEX IF NOT EXISTS ThreadListIndex ON Thread(last_message_received_timestamp DESC, account_id, id)');
});
it("should not fail if additional config is present, but setup is undefined", () => {
delete TestModel.additionalSQLiteConfig.setup;
this.m = new TestModel({id: 'local-6806434c-b0cd', body: 'hello world'});
expect(() => this.builder.setupQueriesForTable(TestModel)).not.toThrow();
});
});
});
});