Skip to content

Commit

Permalink
cleanup test skipping
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Oct 4, 2018
1 parent 0826f81 commit b13a6ea
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 330 deletions.
3 changes: 1 addition & 2 deletions tests/acceptance/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { module } from 'qunit';
import { module, skip as test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import Model from 'ember-data/model';
Expand All @@ -9,7 +9,6 @@ import JSONAPISerializer from 'ember-data/serializers/json-api';
import Store from 'ember-data/store';
import { resolve, reject } from 'rsvp';
import { ServerError } from 'ember-data/adapters/errors';
import { skipRecordData as test } from '../../helpers/test-in-debug';
import Ember from 'ember';

class Person extends Model {
Expand Down
3 changes: 1 addition & 2 deletions tests/acceptance/relationships/has-many-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { module } from 'qunit';
import { module, skip as test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import JSONAPIAdapter from 'ember-data/adapters/json-api';
import Model from 'ember-data/model';
Expand All @@ -10,7 +10,6 @@ import Store from 'ember-data/store';
import { resolve, reject } from 'rsvp';
import { ServerError } from 'ember-data/adapters/errors';
import Ember from 'ember';
import { skipRecordData as test } from '../../helpers/test-in-debug';

function domListToArray(domList) {
return Array.prototype.slice.call(domList);
Expand Down
12 changes: 1 addition & 11 deletions tests/helpers/test-in-debug.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { DEBUG } from '@glimmer/env';
import { test, skip } from 'qunit';

export function testInDebug() {
export default function testInDebug() {
if (DEBUG) {
test(...arguments);
} else {
skip(...arguments);
}
}

export default testInDebug;

export function testRecordData() {
test(...arguments);
}

export function skipRecordData() {
skip(...arguments);
}
114 changes: 1 addition & 113 deletions tests/integration/records/unload-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import DS from 'ember-data';
import setupStore from 'dummy/tests/helpers/store';
import { testRecordData, skipRecordData } from 'dummy/tests/helpers/test-in-debug';

function idsFromOrderedSet(set) {
return set.list.map(i => i.id);
Expand Down Expand Up @@ -721,7 +720,7 @@ test('(regression) unloadRecord followed by push in the same run-loop', function
);
});

testRecordData('unloading a disconnected subgraph clears the relevant internal models', function(
test('unloading a disconnected subgraph clears the relevant internal models', function(
assert
) {
env.adapter.shouldBackgroundReloadRecord = () => false;
Expand Down Expand Up @@ -834,117 +833,6 @@ testRecordData('unloading a disconnected subgraph clears the relevant internal m
});
});

skipRecordData('unloading a disconnected subgraph clears the relevant internal models', function(
assert
) {
env.adapter.shouldBackgroundReloadRecord = () => false;

run(() => {
env.store.push({
data: {
type: 'person',
id: '1',
attributes: {
name: 'Could be Anybody',
},
relationships: {
boats: {
data: [{ type: 'boat', id: '1' }, { type: 'boat', id: '2' }],
},
},
},
});
});

run(() => {
env.store.push({
data: {
type: 'boat',
id: '1',
attributes: {
name: 'Boaty McBoatface',
},
relationships: {
person: {
data: { type: 'person', id: '1' },
},
},
},
});
});

run(() => {
env.store.push({
data: {
type: 'boat',
id: '2',
attributes: {
name: 'The jackson',
},
relationships: {
person: {
data: { type: 'person', id: '1' },
},
},
},
});
});

assert.equal(
env.store._internalModelsFor('person').models.length,
1,
'one person record is loaded'
);
assert.equal(
env.store._internalModelsFor('boat').models.length,
2,
'two boat records are loaded'
);
assert.equal(env.store.hasRecordForId('person', 1), true);
assert.equal(env.store.hasRecordForId('boat', 1), true);
assert.equal(env.store.hasRecordForId('boat', 2), true);

let checkOrphanCalls = 0;
let cleanupOrphanCalls = 0;

function countOrphanCalls(record) {
let internalModel = record._internalModel;
let origCheck = internalModel._checkForOrphanedInternalModels;
let origCleanup = internalModel._cleanupOrphanedInternalModels;

internalModel._checkForOrphanedInternalModels = function() {
++checkOrphanCalls;
return origCheck.apply(record._internalModel, arguments);
};

internalModel._cleanupOrphanedInternalModels = function() {
++cleanupOrphanCalls;
return origCleanup.apply(internalModel, arguments);
};
}
countOrphanCalls(env.store.peekRecord('person', 1));
countOrphanCalls(env.store.peekRecord('boat', 1));
countOrphanCalls(env.store.peekRecord('boat', 2));

// make sure relationships are initialized
return env.store
.peekRecord('person', 1)
.get('boats')
.then(() => {
run(() => {
env.store.peekRecord('person', 1).unloadRecord();
env.store.peekRecord('boat', 1).unloadRecord();
env.store.peekRecord('boat', 2).unloadRecord();
});

assert.equal(env.store._internalModelsFor('person').models.length, 0);
assert.equal(env.store._internalModelsFor('boat').models.length, 0);

assert.equal(checkOrphanCalls, 3, 'each internalModel checks for cleanup');
assert.equal(cleanupOrphanCalls, 1, 'each model data tries to cleanup');
});
});

test('Unloading a record twice only schedules destroy once', function(assert) {
const store = env.store;
let record;
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/relationships/belongs-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { setupTest } from 'ember-qunit';
import Store from 'ember-data/store';
import Model from 'ember-data/model';
import { attr, belongsTo } from '@ember-decorators/data';
import testInDebug, { testRecordData } from 'dummy/tests/helpers/test-in-debug';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import {
setup as setupModelFactoryInjections,
reset as resetModelFactoryInjection,
Expand Down Expand Up @@ -1910,7 +1910,7 @@ test("belongsTo relationship with links doesn't trigger extra change notificatio
assert.equal(count, 0);
});

testRecordData(
test(
"belongsTo relationship doesn't trigger when model data doesn't support implicit relationship",
function(assert) {
class TestRecordData extends RecordData {
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/relationships/has-many-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import setupStore from 'dummy/tests/helpers/store';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import { module, test, skip } from 'qunit';
import DS from 'ember-data';
import { skipRecordData } from '../../helpers/test-in-debug';

let env, store, User, Contact, Email, Phone, Message, Post, Comment;
let Book, Chapter, Page;
Expand Down Expand Up @@ -960,7 +959,7 @@ test('A hasMany relationship can be reloaded if it was fetched via ids', functio
});
});

skipRecordData(
skip(
'A hasMany relationship can be reloaded even if it failed at the first time',
async function(assert) {
assert.expect(6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Store from 'ember-data/store';
import Model from 'ember-data/model';
import { resolve } from 'rsvp';
import { attr, belongsTo, hasMany } from '@ember-decorators/data';
import { testInDebug } from '../../helpers/test-in-debug';
import testInDebug from '../../helpers/test-in-debug';

module('inverse relationship load test', function(hooks) {
let store;
Expand Down
142 changes: 2 additions & 140 deletions tests/integration/relationships/inverse-relationships-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { run } from '@ember/runloop';
import { createStore } from 'dummy/tests/helpers/store';
import setupStore from 'dummy/tests/helpers/store';

import { testInDebug, testRecordData, skipRecordData } from 'dummy/tests/helpers/test-in-debug';
import testInDebug from 'dummy/tests/helpers/test-in-debug';
import { module, test } from 'qunit';

import DS from 'ember-data';
Expand Down Expand Up @@ -486,144 +485,7 @@ testInDebug("Inverse relationships that don't exist throw a nice error for a bel
}, /We found no inverse relationships by the name of 'testPost' on the 'user' model/);
});

skipRecordData('inverseFor short-circuits when inverse is null', function(assert) {
assert.expect(4);
Post = DS.Model.extend({
comments: DS.hasMany('comment', { async: false, inverse: null }),
});

Comment = DS.Model.extend({
post: DS.belongsTo('post', { async: false, inverse: null }),
});

User = DS.Model.extend({
messages: DS.hasMany('message', { async: false, inverse: 'user' }),
});

Message = DS.Model.extend({
user: DS.belongsTo('user', { async: false, inverse: 'messages' }),
});

var env = setupStore({ post: Post, comment: Comment, user: User, message: Message });
var store = env.store;

Post._findInverseFor = function() {
assert.notOk(true, 'Post model _findInverseFor is not called');
};

Comment._findInverseFor = function() {
assert.notOk(true, 'Comment model _findInverseFor is not called');
};

Message._findInverseFor = function() {
assert.ok(true, 'Message model _findInverseFor is called');
};

User._findInverseFor = function() {
assert.ok(true, 'User model _findInverseFor is called');
};

run(function() {
store.push({
data: {
id: '1',
type: 'post',
relationships: {
comments: {
data: [
{
id: '1',
type: 'comment',
},
{
id: '2',
type: 'comment',
},
],
},
},
},
});
store.push({
data: [
{
id: '1',
type: 'comment',
relationships: {
post: {
data: {
id: '1',
type: 'post',
},
},
},
},
{
id: '2',
type: 'comment',
relationships: {
post: {
data: {
id: '1',
type: 'post',
},
},
},
},
],
});
store.push({
data: {
id: '1',
type: 'user',
relationships: {
messages: {
data: [
{
id: '1',
type: 'message',
},
{
id: '2',
type: 'message',
},
],
},
},
},
});
store.push({
data: [
{
id: '1',
type: 'message',
relationships: {
user: {
data: {
id: '1',
type: 'user',
},
},
},
},
{
id: '2',
type: 'message',
relationships: {
post: {
data: {
id: '1',
type: 'user',
},
},
},
},
],
});
});
});

testRecordData('inverseFor is only called when inverse is not null', function(assert) {
test('inverseFor is only called when inverse is not null', function(assert) {
assert.expect(2);
Post = DS.Model.extend({
comments: DS.hasMany('comment', { async: false, inverse: null }),
Expand Down
Loading

0 comments on commit b13a6ea

Please sign in to comment.