Skip to content

Commit

Permalink
Merge pull request #6986 from emberjs/backport/fix/beta
Browse files Browse the repository at this point in the history
[BUFGIX BETA] dont run canary model tests in beta
  • Loading branch information
hjdivad authored Jan 23, 2020
2 parents 8654aab + 3b64061 commit b4e8f05
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@
const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
const isProd = process.env.EMBER_ENV === 'production';
const compatWith = process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : null;
const plugins = [...require('@ember-data/private-build-infra/src/debug-macros')(null, isProd, compatWith)];

let app = new EmberApp(defaults, {
emberData: {
compatWith,
},
// Add options here
babel: {
// this ensures that the same build-time code stripping that is done
// for library packages is also done for our tests and dummy app
plugins,
},
});

// Use `app.import` to add additional libraries to the generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test": "ember test --test-port=0"
},
"dependencies": {
"@ember-data/private-build-infra": "3.16.0-beta.0",
"@ember-data/adapter": "3.16.0-beta.0",
"@ember-data/serializer": "3.16.0-beta.0",
"@ember-data/store": "3.16.0-beta.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,101 @@ import { module, test } from 'qunit';

import { setupTest } from 'ember-qunit';

import { CUSTOM_MODEL_CLASS } from '@ember-data/canary-features';
import Store from '@ember-data/store';

module('modelFor without @ember-data/model', function(hooks) {
setupTest(hooks);
if (CUSTOM_MODEL_CLASS) {
module('modelFor without @ember-data/model', function(hooks) {
setupTest(hooks);

test('We can call modelFor', function(assert) {
this.owner.register(
'service:store',
class TestStore extends Store {
instantiateRecord() {
test('We can call modelFor', function(assert) {
this.owner.register(
'service:store',
class TestStore extends Store {
instantiateRecord() {
return {
id: '1',
type: 'user',
name: 'Chris Thoburn',
};
}
teardownRecord() {
return;
}
}
);
const store = this.owner.lookup('service:store');
store.registerSchemaDefinitionService({
attributesDefinitionFor(identifier) {
return {
id: '1',
type: 'user',
name: 'Chris Thoburn',
name: {
name: 'name',
},
};
}
teardownRecord() {
return;
}
},
relationshipsDefinitionFor(identifier) {
return {};
},
doesTypeExist(type) {
return type === 'user';
},
});

try {
store.modelFor('user');
assert.ok(true, 'We should not throw an eror when schema is available');
} catch (e) {
assert.ok(false, `We threw an unexpected error when schema is available: ${e.message}`);
}
);
const store = this.owner.lookup('service:store');
store.registerSchemaDefinitionService({
attributesDefinitionFor(identifier) {
return {
name: {
name: 'name',
},
};
},
relationshipsDefinitionFor(identifier) {
return {};
},
doesTypeExist(type) {
return type === 'user';
},
});

try {
store.modelFor('user');
assert.ok(true, 'We should not throw an eror when schema is available');
} catch (e) {
assert.ok(false, `We threw an unexpected error when schema is available: ${e.message}`);
}
try {
store.modelFor('person');
assert.ok(false, 'We should throw an eror when no schema is available');
} catch (e) {
assert.strictEqual(
e.message,
"No model was found for 'person' and no schema handles the type",
'We throw an error when no schema is available'
);
}
});

try {
store.modelFor('person');
assert.ok(false, 'We should throw an eror when no schema is available');
} catch (e) {
assert.strictEqual(
e.message,
"No model was found for 'person' and no schema handles the type",
'We throw an error when no schema is available'
test('modelFor returns a stable reference', function(assert) {
this.owner.register(
'service:store',
class TestStore extends Store {
instantiateRecord() {
return {
id: '1',
type: 'user',
name: 'Chris Thoburn',
};
}
teardownRecord() {
return;
}
}
);
}
});

test('modelFor returns a stable reference', function(assert) {
this.owner.register(
'service:store',
class TestStore extends Store {
instantiateRecord() {
const store = this.owner.lookup('service:store');
store.registerSchemaDefinitionService({
attributesDefinitionFor(identifier) {
return {
id: '1',
type: 'user',
name: 'Chris Thoburn',
name: {
name: 'name',
},
};
}
teardownRecord() {
return;
}
}
);
const store = this.owner.lookup('service:store');
store.registerSchemaDefinitionService({
attributesDefinitionFor(identifier) {
return {
name: {
name: 'name',
},
};
},
relationshipsDefinitionFor(identifier) {
return {};
},
doesTypeExist(type) {
return type === 'user';
},
});
},
relationshipsDefinitionFor(identifier) {
return {};
},
doesTypeExist(type) {
return type === 'user';
},
});

const ShimUser1 = store.modelFor('user');
const ShimUser2 = store.modelFor('user');
assert.strictEqual(ShimUser1, ShimUser2, 'Repeat modelFor calls return the same shim');
const ShimUser1 = store.modelFor('user');
const ShimUser2 = store.modelFor('user');
assert.strictEqual(ShimUser1, ShimUser2, 'Repeat modelFor calls return the same shim');
});
});
});
}

0 comments on commit b4e8f05

Please sign in to comment.