Skip to content
Closed
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
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ addons:
chrome: stable

cache:
directories:
- $HOME/.npm
yarn: true

env:
global:
Expand All @@ -36,9 +35,11 @@ matrix:
- env: EMBER_TRY_SCENARIO=ember-canary

before_install:
- npm config set spin false
- npm install -g npm@4
- npm --version
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --no-lockfile --non-interactive

script:
# Usually, it's ok to finish the test scenario without reverting
Expand Down
78 changes: 53 additions & 25 deletions addon-test-support/asserts/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,39 @@ let TestAdapter = QUnitAdapter.extend({

let noop = () => {};

let cleanup = (origTestAdapter, origLoggerError) => {
// Cleanup the test adapter and restore the original.
return Ember.run(() => {
Ember.Test.adapter.destroy();
Ember.Test.adapter = origTestAdapter;
Ember.Logger.error = origLoggerError;
});
};

let handleError = (context, error, matcher, isProductionBuild) => {
let isEmberError = error instanceof Ember.Error;
let matches = Boolean(isEmberError && checkMatcher(error.message, matcher));
let errObj = {};

if (isProductionBuild) {
errObj = {
result: true,
actual: null,
expected: null,
message: 'Assertions are disabled in production builds.'
};
} else {
errObj = {
result: isEmberError && matches,
actual: error && error.message,
expected: matcher,
message: matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
};
}

context.pushResult(errObj);
};

export default function() {
let isProductionBuild = (function() {
try {
Expand All @@ -25,6 +58,7 @@ export default function() {

QUnit.assert.expectAssertion = function(cb, matcher) {
// Save off the original adapter and replace it with a test one.
debugger;
let origTestAdapter = Ember.Test.adapter;
let origLoggerError = Ember.Logger.error;
Ember.run(() => {
Expand All @@ -33,38 +67,32 @@ export default function() {
});

let error = null;
let result;
try {
cb();
result = cb();
} catch (e) {
error = e;
} finally {
error = error || Ember.Test.adapter.lastError;
}

let isEmberError = error instanceof Ember.Error;
let matches = Boolean(isEmberError && checkMatcher(error.message, matcher));

if (isProductionBuild) {
this.pushResult({
result: true,
actual: null,
expected: null,
message: 'Assertions are disabled in production builds.'
});
if (error) {
handleError(this, error, matcher, isProductionBuild);
} else if (Ember.Test.adapter.lastError) {
handleError(this, Ember.Test.adapter.lastError, matcher, isProductionBuild);
} else if(result && typeof result === 'object' && result !== null && typeof result.then === 'function') {
return result
.then(() => {
if (Ember.Test.adapter.lastError) {
handleError(this, Ember.Test.adapter.lastError, matcher, isProductionBuild);
} else {
handleError(this, null, matcher, null);
}
})
.catch(() => handleError(this, error, matcher, isProductionBuild))
.finally(() => cleanup(origTestAdapter, origLoggerError));
} else {
this.pushResult({
result: isEmberError && matches,
actual: error && error.message,
expected: matcher,
message: matcher ? 'Ember.assert matched specific message' : 'Ember.assert called with any message'
});
handleError(this, null, matcher, null);
}

// Cleanup the test adapter and restore the original.
Ember.run(() => {
Ember.Test.adapter.destroy();
Ember.Test.adapter = origTestAdapter;
Ember.Logger.error = origLoggerError;
});
return cleanup(origTestAdapter, origLoggerError);
};
}
4 changes: 0 additions & 4 deletions bower.json

This file was deleted.

19 changes: 6 additions & 13 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-env node */
module.exports = {
useYarn: true,
scenarios: [
{
name: 'ember-lts-2.4',
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-4'
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': 'lts-2-4'
'ember': 'lts-2-8'
}
},
npm: {
Expand All @@ -18,18 +19,10 @@ module.exports = {
}
},
{
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': 'lts-2-8'
}
},
name: 'ember-lts-2.12',
npm: {
devDependencies: {
'ember-source': null
'ember-source': '~2.12.0'
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"test": "ember try:each"
},
"dependencies": {
"ember-cli-babel": "^6.9.0",
"broccoli-filter": "^1.0.1"
"broccoli-filter": "^1.0.1",
"ember-cli-babel": "^6.9.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
Expand All @@ -33,14 +33,15 @@
"ember-cli-htmlbars": "^2.0.1",
"ember-cli-htmlbars-inline-precompile": "^1.0.0",
"ember-cli-inject-live-reload": "^1.4.1",
"ember-cli-qunit": "^4.0.0",
"ember-cli-qunit": "^4.1.1",
"ember-cli-release": "^0.2.9",
"ember-cli-shims": "^1.1.0",
"ember-cli-sri": "^2.1.0",
"ember-cli-uglify": "^2.0.0",
"ember-disable-prototype-extensions": "^1.1.2",
"ember-export-application-global": "^2.0.0",
"ember-load-initializers": "^1.0.0",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-resolver": "^4.0.0",
"ember-source": "~2.16.0",
"loader.js": "^4.2.3"
Expand Down
43 changes: 0 additions & 43 deletions tests/helpers/module-for-assert.js

This file was deleted.

23 changes: 23 additions & 0 deletions tests/helpers/setup-assert-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import QUnit from 'qunit';

export default function setupAssertTest(hooks) {
hooks.beforeEach(function() {
let originalPushResult = QUnit.assert.pushResult;
this.pushedResults = [];

QUnit.assert.pushResult = (result) => {
this.pushedResults.push(result);
};

this.restoreAsserts = () => {
if (originalPushResult) {
QUnit.assert.pushResult = originalPushResult;
originalPushResult = null;
}
};
});

hooks.afterEach(function() {
this.restoreAsserts();
});
}
Empty file removed tests/integration/.gitkeep
Empty file.
90 changes: 59 additions & 31 deletions tests/integration/assertion-test.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,77 @@
import Ember from 'ember';
import { test } from 'ember-qunit';
import { module, test } from 'qunit';
import { render } from 'ember-test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import moduleForAssert from '../helpers/module-for-assert';
import setupAssertTest from '../helpers/setup-assert-test';

module('Assertion', function(hooks) {
setupRenderingTest(hooks);
setupAssertTest(hooks);

moduleForAssert('Integration: Assertion', {
integration: true,
beforeEach() {
this.register('component:x-assert-test', Ember.Component.extend({
hooks.beforeEach(function() {
this.owner.register('component:x-assert-test', Ember.Component.extend({
init() {
this._super();
debugger;
Ember.assert('x-assert-test will always assert');
}
}));
}
});

test('Check for assert', function(assert) {
assert.expectAssertion(() => {
this.render(hbs`{{x-assert-test}}`);
}, /x-assert-test will always assert/);
});

// Restore the asserts (removes the mocking)
this.restoreAsserts();
test('Check for assert', async function(assert) {
await assert.expectAssertion(() => {
return render(hbs`{{x-assert-test}}`);
}, /x-assert-test will always assert/);
debugger;
// Restore the asserts (removes the mocking)
this.restoreAsserts();

assert.ok(this.pushedResults[0].result, '`expectWarning` captured warning call');
});
assert.ok(this.pushedResults[0].result, 'properly captured assertion');
});

test('Does not log caught assertions', function(assert) {
let origLoggerError = Ember.Logger.error;
try {
let errorCalled = false;
Ember.Logger.error = () => {
errorCalled = true;
};
test('Check for async assert', async function(assert) {
this.owner.register('component:x-assert-async-test', Ember.Component.extend({
init() {
this._super();
let ms = 10;
return new Ember.RSVP.Promise(() => {
return Ember.run.later(this, '_assert', ms);
});
},
_assert() {
Ember.assert('x-assert-async-test will asynchronously assert');
}
}));

assert.expectAssertion(() => {
this.render(hbs`{{x-assert-test}}`);
}, /x-assert-test will always assert/);
await assert.expectAssertion(() => {
return render(hbs`{{x-assert-async-test}}`);
}, /x-assert-async-test will asynchronously assert/);

// Restore the asserts (removes the mocking)
this.restoreAsserts();

assert.equal(errorCalled, false, 'assertion was not logged');
} finally {
Ember.Logger.error = origLoggerError;
}
assert.ok(this.pushedResults[0].result, 'properly captured an async assertion');
});

test('Does not log caught assertions', async function(assert) {
let origLoggerError = Ember.Logger.error;
try {
let errorCalled = false;
Ember.Logger.error = () => {
errorCalled = true;
};

await assert.expectAssertion(() => {
return render(hbs`{{x-assert-test}}`);
}, /x-assert-test will always assert/);

// Restore the asserts (removes the mocking)
this.restoreAsserts();

assert.equal(errorCalled, false, 'assertion was not logged');
} finally {
Ember.Logger.error = origLoggerError;
}
});
});
Empty file removed tests/unit/.gitkeep
Empty file.
Loading