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

Bring over more functionality from ember-cli-qunit. #283

Merged
merged 1 commit into from
Oct 7, 2017
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
57 changes: 48 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const path = require('path');
const fs = require('fs');
const stripIndent = require('common-tags').stripIndent;

module.exports = {
name: 'ember-qunit',
Expand All @@ -12,18 +12,34 @@ module.exports = {

this.import('vendor/qunit/qunit.js', { type: 'test' });
this.import('vendor/qunit/qunit.css', { type: 'test' });
this.import('vendor/ember-qunit/qunit-configuration.js', { type: 'test' });

let addonOptions = this.targetOptions();
let explicitlyDisabledStyles = addonOptions.disableContainerStyles === true;
if (!explicitlyDisabledStyles) {
this.import('vendor/ember-qunit/test-container-styles.css', {
type: 'test',
});
}
},

targetOptions() {
if (!this._targetOptions) {
// 1. check this.parent.options['ember-qunit']
let targetOptions = this.parent.options && this.parent.options['ember-qunit'];
let targetOptions =
this.parent.options && this.parent.options['ember-qunit'];
// 2. check this.app.options['ember-qunit']
targetOptions = targetOptions || this.app && this.app.options && this.app.options['ember-qunit'];
targetOptions =
targetOptions ||
(this.app && this.app.options && this.app.options['ember-qunit']);
// 3. check this.parent.options['ember-cli-qunit']
targetOptions = targetOptions || this.parent.options && this.parent.options['ember-cli-qunit'];
targetOptions =
targetOptions ||
(this.parent.options && this.parent.options['ember-cli-qunit']);
// 4. check this.app.options['ember-cli-qunit']
targetOptions = targetOptions || this.app && this.app.options && this.app.options['ember-cli-qunit'];
targetOptions =
targetOptions ||
(this.app && this.app.options && this.app.options['ember-cli-qunit']);
this._targetOptions = targetOptions || {};
}

Expand All @@ -32,8 +48,11 @@ module.exports = {

contentFor: function(type) {
// Skip if insertContentForTestBody === false.
if (type === 'test-body' && !(this.targetOptions().insertContentForTestBody === false)) {
return `
if (
type === 'test-body' &&
!(this.targetOptions().insertContentForTestBody === false)
) {
return stripIndent`
<div id="qunit"></div>
<div id="qunit-fixture"></div>

Expand All @@ -44,14 +63,17 @@ module.exports = {
}
},

treeForVendor: function() {
treeForVendor: function(tree) {
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
let qunitPath = path.dirname(require.resolve('qunitjs'));

return new Funnel(this.treeGenerator(qunitPath), {
let qunitTree = new Funnel(this.treeGenerator(qunitPath), {
destDir: 'qunit',
annotation: 'ember-qunit#treeForVendor',
});

return new MergeTrees([qunitTree, tree]);
},

treeForAddonTestSupport(tree) {
Expand All @@ -63,4 +85,21 @@ module.exports = {
registry: this.registry,
});
},

setTestGenerator: function() {
this.project.generateTestFile = function(moduleName, tests) {
let output = `QUnit.module('${moduleName}');\n`;

tests.forEach(function(test) {
output += stripIndent`
QUnit.test('${test.name}', function(assert) {
assert.expect(1);
assert.ok(${test.passed}, '${test.errorMessage}');
});
`;
});

return output;
};
},
};
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^2.0.0",
"common-tags": "^1.4.0",
"ember-cli-babel": "^6.3.0",
"ember-cli-test-loader": "^2.2.0",
"ember-test-helpers": "^0.7.0-beta.2",
Expand Down
11 changes: 11 additions & 0 deletions vendor/ember-qunit/qunit-configuration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* globals QUnit */

(function() {
QUnit.config.autostart = false;
QUnit.config.urlConfig.push({ id: 'nocontainer', label: 'Hide container' });
QUnit.config.urlConfig.push({ id: 'nolint', label: 'Disable Linting' });
QUnit.config.urlConfig.push({ id: 'dockcontainer', label: 'Dock container' });
QUnit.config.urlConfig.push({ id: 'devmode', label: 'Development mode' });

QUnit.config.testTimeout = QUnit.urlParams.devmode ? null : 60000; //Default Test Timeout 60 Seconds
})();
34 changes: 34 additions & 0 deletions vendor/ember-qunit/test-container-styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ember-testing-container {
position: relative;
background: white;
bottom: 0;
right: 0;
width: 640px;
height: 384px;
overflow: auto;
z-index: 98;
border: 1px solid #ccc;
margin: 0 auto;
}

#ember-testing-container.full-screen {
width: 100%;
height: 100%;
overflow: auto;
z-index: 98;
border: none;
}

#ember-testing {
width: 200%;
height: 200%;
transform: scale(0.5);
transform-origin: top left;
}

.full-screen #ember-testing {
position: absolute;
width: 100%;
height: 100%;
transform: scale(1);
}