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

[RFC] Adds a wrapped QUnit.only #205

Merged
merged 2 commits into from
Nov 1, 2015
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bower_components
tmp
dist
build
*.log
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"ember-test-helpers": "^0.5.14"
},
"devDependencies": {
"qunit": "^1.17.1",
"qunit": "^1.20.0",
"loader": "stefanpenner/loader.js#1.0.1",
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4",
Expand Down
2 changes: 2 additions & 0 deletions lib/ember-qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import moduleFor from 'ember-qunit/module-for';
import moduleForComponent from 'ember-qunit/module-for-component';
import moduleForModel from 'ember-qunit/module-for-model';
import test from 'ember-qunit/test';
import only from 'ember-qunit/only';
import { setResolver } from 'ember-test-helpers';

export {
moduleFor,
moduleForComponent,
moduleForModel,
test,
only,
setResolver
};
6 changes: 6 additions & 0 deletions lib/ember-qunit/only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import testWrapper from 'ember-qunit/test-wrapper';
import { only as qunitOnly } from 'qunit';

export default function only(testName, callback) {
testWrapper(testName, callback, qunitOnly);
}
32 changes: 32 additions & 0 deletions lib/ember-qunit/test-wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Ember from 'ember';
import { getContext } from 'ember-test-helpers';

export default function testWrapper(testName, callback, qunit) {
function wrapper(assert) {
var context = getContext();

var result = callback.call(context, assert);

function failTestOnPromiseRejection(reason) {
var message;
if (reason instanceof Error) {
message = reason.stack;
if (reason.message && message.indexOf(reason.message) < 0) {
// PhantomJS has a `stack` that does not contain the actual
// exception message.
message = Ember.inspect(reason) + "\n" + message;
}
} else {
message = Ember.inspect(reason);
}
ok(false, message);
}

Ember.run(function(){
QUnit.stop();
Ember.RSVP.Promise.resolve(result)['catch'](failTestOnPromiseRejection)['finally'](QUnit.start);
});
}

qunit(testName, wrapper);
}
31 changes: 2 additions & 29 deletions lib/ember-qunit/test.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,6 @@
import Ember from 'ember';
import { getContext } from 'ember-test-helpers';
import testWrapper from 'ember-qunit/test-wrapper';
import { test as qunitTest } from 'qunit';

export default function test(testName, callback) {
function wrapper(assert) {
var context = getContext();

var result = callback.call(context, assert);

function failTestOnPromiseRejection(reason) {
var message;
if (reason instanceof Error) {
message = reason.stack;
if (reason.message && message.indexOf(reason.message) < 0) {
// PhantomJS has a `stack` that does not contain the actual
// exception message.
message = Ember.inspect(reason) + "\n" + message;
}
} else {
message = Ember.inspect(reason);
}
ok(false, message);
}

Ember.run(function(){
QUnit.stop();
Ember.RSVP.Promise.resolve(result)['catch'](failTestOnPromiseRejection)['finally'](QUnit.start);
});
}

qunitTest(testName, wrapper);
testWrapper(testName, callback, qunitTest);
}
1 change: 1 addition & 0 deletions lib/qunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
export var module = QUnit.module;
export var test = QUnit.test;
export var skip = QUnit.skip;
export var only = QUnit.only;

export default QUnit;
7 changes: 6 additions & 1 deletion tests/qunit-shim-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
module,
test,
skip
skip,
only
} from 'qunit';

module('qunit-shim test');
Expand All @@ -13,3 +14,7 @@ test('should work!', function(assert) {
test('imports skips', function(assert) {
assert.equal(typeof skip, 'function', 'imports QUnit.skip');
});

test('imports only', function(assert) {
assert.equal(typeof only, 'function', 'imports QUnit.only');
});