Skip to content

Commit

Permalink
Merge pull request #205 from ebenoist/adds-qunit-only
Browse files Browse the repository at this point in the history
[RFC] Adds a wrapped QUnit.only
  • Loading branch information
rwjblue committed Nov 1, 2015
2 parents 32edc12 + bdcce8c commit 0c52f2e
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 31 deletions.
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');
});

0 comments on commit 0c52f2e

Please sign in to comment.