Skip to content
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
47 changes: 47 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {
root: true,
extends: ['eslint:recommended', 'prettier'],
plugins: ['prettier'],
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
},
env: {
browser: true,
},
rules: {
'prettier/prettier': ['error', {
singleQuote: true,
trailingComma: 'es5',
printWidth: 100,
}],
},
overrides: [
{
files: ['./index.js'],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
}
},
{
files: ['tests/**/*.js'],
env: {
qunit: true
}
},
{
files: ['./index.js', 'addon-test-support/**/*.js', 'config/**/*.js'],
plugins: [
'disable-features',
],
rules: {
'disable-features/disable-async-await': 'error',
'disable-features/disable-generator-functions': 'error',
}
},
]
};
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# emberjs-qunit-browserstack
# emberjs-qunit-browserstack (Using BrowserStack Runner)

### Installation

* `npm install`

### Configuration

### Parameters for `browserstack.json`

* `username`: BrowserStack username (Or `BROWSERSTACK_USERNAME` environment variable)
* `key`: BrowserStack [access key](https://www.browserstack.com/accounts/local-testing) (Or `BROWSERSTACK_KEY` environment variable)
* `test_path`: Path to the test page which will run the tests when opened in a browser.

### Running Tests locally

* `ember serve` Note: if ember is not present in the path then use `./node_modules/.bin/ember`
* visit [http://localhost:4200/tests](http://localhost:4200/tests).

### Running Tests on Browserstack

* `ember serve` Note: if ember is not present in the path then use `./node_modules/.bin/ember`
* `./node_modules/.bin/browserstack-runner`
47 changes: 47 additions & 0 deletions addon-test-support/ember-qunit/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Ember from 'ember';
import QUnit from 'qunit';

function unhandledRejectionAssertion(current, error) {
let message, source;

if (typeof error === 'object' && error !== null) {
message = error.message;
source = error.stack;
} else if (typeof error === 'string') {
message = error;
source = 'unknown source';
} else {
message = 'unhandledRejection occured, but it had no message';
source = 'unknown source';
}

current.pushResult({
result: false,
actual: false,
expected: true,
message: message,
source: source,
});
}

export default Ember.Test.Adapter.extend({
init() {
this.doneCallbacks = [];
},

asyncStart() {
this.doneCallbacks.push(QUnit.config.current ? QUnit.config.current.assert.async() : null);
},

asyncEnd() {
let done = this.doneCallbacks.pop();
// This can be null if asyncStart() was called outside of a test
if (done) {
done();
}
},

exception(error) {
unhandledRejectionAssertion(QUnit.config.current, error);
},
});
134 changes: 134 additions & 0 deletions addon-test-support/ember-qunit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export { default as moduleFor } from './legacy-2-x/module-for';
export { default as moduleForComponent } from './legacy-2-x/module-for-component';
export { default as moduleForModel } from './legacy-2-x/module-for-model';
export { default as QUnitAdapter } from './adapter';
export {
setResolver,
render,
clearRender,
settled,
pauseTest,
resumeTest,
} from '@ember/test-helpers';
export { module, test, skip, only, todo } from 'qunit';
export { loadTests } from './test-loader';

import { loadTests } from './test-loader';
import Ember from 'ember';
import QUnit from 'qunit';
import QUnitAdapter from './adapter';
import {
setupContext,
teardownContext,
setupRenderingContext,
teardownRenderingContext,
} from '@ember/test-helpers';

export function setupTest(hooks, options) {
hooks.beforeEach(function(assert) {
return setupContext(this, options).then(() => {
let originalPauseTest = this.pauseTest;
this.pauseTest = function QUnit_pauseTest() {
assert.timeout(-1); // prevent the test from timing out

return originalPauseTest.call(this);
};
});
});

hooks.afterEach(function() {
return teardownContext(this);
});
}

export function setupRenderingTest(hooks, options) {
setupTest(hooks, options);

hooks.beforeEach(function() {
return setupRenderingContext(this);
});

hooks.afterEach(function() {
return teardownRenderingContext(this);
});
}

/**
Uses current URL configuration to setup the test container.

* If `?nocontainer` is set, the test container will be hidden.
* If `?dockcontainer` or `?devmode` are set the test container will be
absolutely positioned.
* If `?devmode` is set, the test container will be made full screen.

@method setupTestContainer
*/
export function setupTestContainer() {
let testContainer = document.getElementById('ember-testing-container');
if (!testContainer) {
return;
}

let params = QUnit.urlParams;

let containerVisibility = params.nocontainer ? 'hidden' : 'visible';
let containerPosition = params.dockcontainer || params.devmode ? 'fixed' : 'relative';

if (params.devmode) {
testContainer.className = ' full-screen';
}

testContainer.style.visibility = containerVisibility;
testContainer.style.position = containerPosition;

let qunitContainer = document.getElementById('qunit');
if (params.dockcontainer) {
qunitContainer.style.marginBottom = window.getComputedStyle(testContainer).height;
}
}

/**
Instruct QUnit to start the tests.
@method startTests
*/
export function startTests() {
QUnit.start();
}

/**
Sets up the `Ember.Test` adapter for usage with QUnit 2.x.

@method setupTestAdapter
*/
export function setupTestAdapter() {
Ember.Test.adapter = QUnitAdapter.create();
}

/**
@method start
@param {Object} [options] Options to be used for enabling/disabling behaviors
@param {Boolean} [options.loadTests] If `false` tests will not be loaded automatically.
@param {Boolean} [options.setupTestContainer] If `false` the test container will not
be setup based on `devmode`, `dockcontainer`, or `nocontainer` URL params.
@param {Boolean} [options.startTests] If `false` tests will not be automatically started
(you must run `QUnit.start()` to kick them off).
@param {Boolean} [options.setupTestAdapter] If `false` the default Ember.Test adapter will
not be updated.
*/
export function start(options = {}) {
if (options.loadTests !== false) {
loadTests();
}

if (options.setupTestContainer !== false) {
setupTestContainer();
}

if (options.setupTestAdapter !== false) {
setupTestAdapter();
}

if (options.startTests !== false) {
startTests();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createModule } from './qunit-module';
import { TestModuleForComponent } from 'ember-test-helpers';

export default function moduleForComponent(name, description, callbacks) {
createModule(TestModuleForComponent, name, description, callbacks);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createModule } from './qunit-module';
import { TestModuleForModel } from 'ember-test-helpers';

export default function moduleForModel(name, description, callbacks) {
createModule(TestModuleForModel, name, description, callbacks);
}
6 changes: 6 additions & 0 deletions addon-test-support/ember-qunit/legacy-2-x/module-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createModule } from './qunit-module';
import { TestModule } from 'ember-test-helpers';

export default function moduleFor(name, description, callbacks) {
createModule(TestModule, name, description, callbacks);
}
68 changes: 68 additions & 0 deletions addon-test-support/ember-qunit/legacy-2-x/qunit-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Ember from 'ember';
import { module as qunitModule } from 'qunit';

function noop() {}

function callbackFor(name, callbacks) {
if (typeof callbacks !== 'object') {
return noop;
}
if (!callbacks) {
return noop;
}

var callback = noop;

if (callbacks[name]) {
callback = callbacks[name];
delete callbacks[name];
}

return callback;
}

export function createModule(Constructor, name, description, callbacks) {
if (!callbacks && typeof description === 'object') {
callbacks = description;
description = name;
}

var before = callbackFor('before', callbacks);
var beforeEach = callbackFor('beforeEach', callbacks);
var afterEach = callbackFor('afterEach', callbacks);
var after = callbackFor('after', callbacks);

var module;
var moduleName = typeof description === 'string' ? description : name;

qunitModule(moduleName, {
before() {
// storing this in closure scope to avoid exposing these
// private internals to the test context
module = new Constructor(name, description, callbacks);
return before.apply(this, arguments);
},

beforeEach() {
// provide the test context to the underlying module
module.setContext(this);

return module.setup(...arguments).then(() => {
return beforeEach.apply(this, arguments);
});
},

afterEach() {
let result = afterEach.apply(this, arguments);
return Ember.RSVP.resolve(result).then(() => module.teardown(...arguments));
},

after() {
try {
return after.apply(this, arguments);
} finally {
after = afterEach = before = beforeEach = callbacks = module = null;
}
},
});
}
Loading