Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Strip resolved Deprecations #6814

Merged
merged 8 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/asset-size-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ jobs:
- name: Build Production master (IE11)
run: |
mkdir -p packages/-ember-data/dists
TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/control-ie11
EMBER_DATA_FULL_COMPAT=true TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/control-ie11
- name: Build Production master
run: yarn workspace ember-data ember build -e production --output-path dists/control
run: EMBER_DATA_FULL_COMPAT=true yarn workspace ember-data ember build -e production --output-path dists/control
- name: Build Production master (no rollup)
run: EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/control-no-rollup
run: EMBER_DATA_FULL_COMPAT=true EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/control-no-rollup
- name: Checkout ${{github.ref}}
run: |
sha=$(cat tmp/sha-for-check.txt)
git checkout --progress --force $sha
- name: Install dependencies for ${{github.ref}}
run: yarn install
- name: Build Production ${{github.ref}} (IE11)
run: TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/experiment-ie11
run: EMBER_DATA_FULL_COMPAT=true TARGET_IE11=true yarn workspace ember-data ember build -e production --output-path dists/experiment-ie11
- name: Build Production ${{github.ref}}
run: yarn workspace ember-data ember build -e production --output-path dists/experiment
run: EMBER_DATA_FULL_COMPAT=true yarn workspace ember-data ember build -e production --output-path dists/experiment
- name: Build Production ${{github.ref}} (no rollup)
run: EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/experiment-no-rollup
run: EMBER_DATA_FULL_COMPAT=true EMBER_DATA_ROLLUP_PRIVATE=false yarn workspace ember-data ember build -e production --output-path dists/experiment-no-rollup
- name: Analyze Master Assets (IE11)
run: |
node ./bin/asset-size-tracking/generate-analysis.js packages/-ember-data/dists/control-ie11 ./control-ie11-data.json
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ jobs:
env:
EMBER_DATA_FEATURE_OVERRIDE: DISABLE_ALL
run: yarn test
- if: |
github.event_name == 'pull_request' && (
github.base_ref == 'master' || github.base_ref == 'beta'
) || github.event_name == 'push' && (
endsWith(github.ref, '/master') || endsWith(github.ref, '/beta')
)
name: Remove All Deprecations
env:
EMBER_DATA_FULL_COMPAT: true
run: yarn test:production

basic-tests-ie11:
needs: [lint]
Expand Down
13 changes: 8 additions & 5 deletions packages/-ember-data/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function(defaults) {
const isProd = process.env.EMBER_ENV === 'production';
const compatWith = process.env.EMBER_DATA_FULL_COMPAT ? '99.0' : null;
let app = new EmberAddon(defaults, {
emberData: {
compatWith,
},
babel: {
// this ensures that the same `@ember-data/canary-features` processing that the various
// ember-data addons do is done in the dummy app
plugins: [
...require('@ember-data/private-build-infra/src/debug-macros')(null, process.env.EMBER_ENV === 'production'),
],
// 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: [...require('@ember-data/private-build-infra/src/debug-macros')(null, isProd, compatWith)],
},
'ember-cli-babel': {
throwUnlessParallelizable: true,
Expand Down
71 changes: 52 additions & 19 deletions packages/-ember-data/tests/unit/model/rollback-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RESTAdapter from '@ember-data/adapter/rest';
import RESTSerializer from '@ember-data/serializer/rest';
import JSONAPISerializer from '@ember-data/serializer/json-api';
import { InvalidError } from '@ember-data/adapter/error';
import { DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS } from '@ember-data/private-build-infra/deprecations';

import { module, test } from 'qunit';

Expand Down Expand Up @@ -65,13 +66,17 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
});

assert.equal(person.get('firstName'), 'Thomas');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.equal(person.get('firstName'), 'Tom');
assert.equal(person.get('hasDirtyAttributes'), false);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test('changes to unassigned attributes can be rolled back', function(assert) {
Expand All @@ -95,13 +100,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
});

assert.equal(person.get('firstName'), 'Thomas');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.strictEqual(person.get('firstName'), undefined);
assert.equal(person.get('hasDirtyAttributes'), false);
assert.equal(person.get('rolledBackCount'), 1);

if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test('changes to attributes made after a record is in-flight only rolls back the local changes', function(assert) {
Expand Down Expand Up @@ -139,7 +149,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
person.set('lastName', 'Dolly');

assert.equal(person.get('lastName'), 'Dolly');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

person.rollbackAttributes();

Expand All @@ -148,7 +160,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(person.get('isSaving'), true);

return saving.then(() => {
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
assert.equal(person.get('hasDirtyAttributes'), false, 'The person is now clean');
});
});
Expand Down Expand Up @@ -186,16 +200,19 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
person.save().then(null, function() {
assert.equal(person.get('isError'), true);
assert.deepEqual(person.changedAttributes().firstName, ['Tom', 'Thomas']);
assert.equal(person.get('rolledBackCount'), 0);

if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}
run(function() {
person.rollbackAttributes();
});

assert.equal(person.get('firstName'), 'Tom');
assert.equal(person.get('isError'), false);
assert.equal(Object.keys(person.changedAttributes()).length, 0);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -236,14 +253,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
.catch(() => {
assert.equal(person.get('isError'), true);
assert.equal(person.get('isDeleted'), true);
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(() => person.rollbackAttributes());

assert.equal(person.get('isDeleted'), false);
assert.equal(person.get('isError'), false);
assert.equal(person.get('hasDirtyAttributes'), false, 'must be not dirty');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
})
.then(() => {
assert.equal(
Expand All @@ -261,14 +282,18 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho

assert.equal(person.get('isNew'), true, 'must be new');
assert.equal(person.get('hasDirtyAttributes'), true, 'must be dirty');
assert.equal(person.get('rolledBackCount'), 0);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 0);
}

run(person, 'rollbackAttributes');

assert.equal(person.get('isNew'), false, 'must not be new');
assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty');
assert.equal(person.get('isDeleted'), true, 'must be deleted');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});

test(`invalid new record's attributes can be rollbacked`, function(assert) {
Expand Down Expand Up @@ -304,7 +329,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(person.get('isNew'), false, 'must not be new');
assert.equal(person.get('hasDirtyAttributes'), false, 'must not be dirty');
assert.equal(person.get('isDeleted'), true, 'must be deleted');
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -357,7 +384,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
'original name',
'after rollbackAttributes() firstName has the original value'
);
assert.equal(person.get('rolledBackCount'), 1);
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(person.get('rolledBackCount'), 1);
}
});
});
});
Expand Down Expand Up @@ -394,10 +423,12 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
test("invalid record's attributes can be rollbacked", async function(assert) {
class Dog extends Model {
@attr() name;
rolledBackCount = 0;
rolledBack() {
}
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
Dog.prototype.rolledBackCount = 0;
Dog.prototype.rolledBack = function() {
this.incrementProperty('rolledBackCount');
}
};
}
const thrownAdapterError = new InvalidError([
{
Expand Down Expand Up @@ -457,7 +488,9 @@ module('unit/model/rollbackAttributes - model.rollbackAttributes()', function(ho
assert.equal(dog.get('name'), 'Pluto', 'Name is rolled back');
assert.notOk(dog.get('errors.name'), 'We have no errors for name anymore');
assert.ok(dog.get('isValid'), 'We are now in a valid state');
assert.equal(dog.get('rolledBackCount'), 1, 'we only rolled back once');
if (DEPRECATE_RECORD_LIFECYCLE_EVENT_METHODS) {
assert.equal(dog.get('rolledBackCount'), 1, 'we only rolled back once');
}
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { run } from '@ember/runloop';
import DS from 'ember-data';
import { module, test } from 'qunit';
const { AdapterPopulatedRecordArray, RecordArrayManager } = DS;
import Evented from '@ember/object/evented';
import { DEPRECATE_EVENTED_API_USAGE } from '@ember-data/private-build-infra/deprecations';

module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedRecordArray', function() {
function internalModelFor(record) {
Expand Down Expand Up @@ -125,9 +127,11 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
assert.equal(didAddRecord, 0, 'no records should have been added yet');

let didLoad = 0;
recordArray.on('didLoad', function() {
didLoad++;
});
if (DEPRECATE_EVENTED_API_USAGE) {
recordArray.on('didLoad', function() {
didLoad++;
});
}

let links = { foo: 1 };
let meta = { bar: 2 };
Expand All @@ -150,11 +154,15 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
'should now contain the loaded records'
);

assert.equal(didLoad, 0, 'didLoad event should not have fired');
if (DEPRECATE_EVENTED_API_USAGE) {
assert.equal(didLoad, 0, 'didLoad event should not have fired');
}
assert.equal(recordArray.get('links').foo, 1);
assert.equal(recordArray.get('meta').bar, 2);
});
assert.equal(didLoad, 1, 'didLoad event should have fired once');
if (DEPRECATE_EVENTED_API_USAGE) {
assert.equal(didLoad, 1, 'didLoad event should have fired once');
}
assert.expectDeprecation({
id: 'ember-data:evented-api-usage',
});
Expand All @@ -176,7 +184,8 @@ module('unit/record-arrays/adapter-populated-record-array - DS.AdapterPopulatedR
assert.equal(array, recordArray);
}

let recordArray = AdapterPopulatedRecordArray.create({
// we need Evented to gain access to the @array:change event
let recordArray = AdapterPopulatedRecordArray.extend(Evented).create({
query: 'some-query',
manager: new RecordArrayManager({}),
});
Expand Down
63 changes: 34 additions & 29 deletions packages/-ember-data/tests/unit/store/push-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import testInDebug from '@ember-data/unpublished-test-infra/test-support/test-in
import { module, test } from 'qunit';

import DS from 'ember-data';
import { deprecatedTest } from '@ember-data/unpublished-test-infra/test-support/deprecated-test';

let store, Person, PhoneNumber, Post;
const { attr, hasMany, belongsTo } = DS;
Expand Down Expand Up @@ -147,40 +148,44 @@ module('unit/store/push - DS.Store#push', function(hooks) {
});
});

test(`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`, async function(assert) {
assert.expect(2);

let didLoad = new EmberPromise((resolve, reject) => {
Person.reopen({
didLoad() {
try {
assert.ok(true, 'The didLoad callback was called');
resolve();
} catch (e) {
reject(e);
}
},
deprecatedTest(
`Calling push triggers 'didLoad' even if the record hasn't been requested from the adapter`,
{
id: 'ember-data:record-lifecycle-event-methods',
until: '4.0',
},
async function(assert) {
assert.expect(1);

let didLoad = new EmberPromise((resolve, reject) => {
Person.reopen({
didLoad() {
try {
assert.ok(true, 'The didLoad callback was called');
resolve();
} catch (e) {
reject(e);
}
},
});
});
});

run(() => {
store.push({
data: {
type: 'person',
id: 'wat',
attributes: {
firstName: 'Yehuda',
lastName: 'Katz',
run(() => {
store.push({
data: {
type: 'person',
id: 'wat',
attributes: {
firstName: 'Yehuda',
lastName: 'Katz',
},
},
},
});
});
});

await didLoad;
assert.expectDeprecation({
id: 'ember-data:record-lifecycle-event-methods',
});
});
await didLoad;
}
);

test('Calling push with partial records updates just those attributes', function(assert) {
assert.expect(2);
Expand Down
2 changes: 1 addition & 1 deletion packages/canary-features/addon/default-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- null - The feature is disabled by default, but can be enabled at runtime via `EmberDataENV`.

@module @ember-data/canary-features
@main
@main @ember-data/canary-features
@private
*/
export default {
Expand Down
Loading