Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #191 from rwjblue/reduce-to-shim
Browse files Browse the repository at this point in the history
Remove functionality to defer to ember-qunit API.
  • Loading branch information
rwjblue authored Oct 8, 2017
2 parents 38d8901 + 486d7cd commit 4ab1f87
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 416 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ cache:
env:
- EMBER_TRY_SCENARIO=default
- EMBER_TRY_SCENARIO=old-test-loader
- EMBER_TRY_SCENARIO=npm-test-loader
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand Down
140 changes: 9 additions & 131 deletions addon-test-support/ember-cli-qunit.js
Original file line number Diff line number Diff line change
@@ -1,131 +1,9 @@
import Ember from 'ember';
import QUnit from 'qunit';
import { QUnitAdapter } from 'ember-qunit';
import AbstractTestLoader, {
addModuleExcludeMatcher,
addModuleIncludeMatcher
} from 'ember-cli-test-loader/test-support/index';


addModuleExcludeMatcher(function(moduleName) {
return QUnit.urlParams.nolint &&
moduleName.match(/\.(jshint|lint-test)$/);
});

addModuleIncludeMatcher(function(moduleName) {
return moduleName.match(/\.jshint$/);
});

let moduleLoadFailures = [];

QUnit.done(function() {
if (moduleLoadFailures.length) {
throw new Error('\n' + moduleLoadFailures.join('\n'));
}
});

export class TestLoader extends AbstractTestLoader {
moduleLoadFailure(moduleName, error) {
moduleLoadFailures.push(error);

QUnit.module('TestLoader Failures');
QUnit.test(moduleName + ': could not be loaded', function() {
throw error;
});
}
}
/**
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;
}
}

/**
Load tests following the default patterns:
* The module name ends with `-test`
* The module name ends with `.jshint`
Excludes tests that match the following
patterns when `?nolint` URL param is set:
* The module name ends with `.jshint`
* The module name ends with `-lint-test`
@method loadTests
*/
export function loadTests() {
new TestLoader().loadModules();
}

/**
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();
}
}
// reexporting for compatibility
export {
TestLoader,
setupTestContainer,
loadTests,
startTests,
setupTestAdapter,
start
} from 'ember-qunit';
36 changes: 20 additions & 16 deletions config/ember-try.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
/*jshint node:true*/
module.exports = {
scenarios: [
{
name: 'default',
bower: {
dependencies: {
'ember-cli-test-loader': '0.2.2'
}
}
},
{
name: 'old-test-loader',
bower: {
dependencies: {
'ember-cli-test-loader': '0.2.0'
'ember-cli-test-loader': '0.2.2'
}
}
},
{
name: 'npm-test-loader',
name: 'default',
npm: {
devDependencies: {
'ember-cli-test-loader': '^1.1.0'
'ember-cli-test-loader': '^2.2.0'
}
}
},
Expand All @@ -30,22 +22,30 @@ module.exports = {
bower: {
dependencies: {
'ember': 'components/ember#release',
'ember-cli-test-loader': '0.2.2'
},
resolutions: {
'ember': 'release'
}
},
npm: {
devDependencies: {
'ember-cli-test-loader': '^2.2.0'
}
}
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta',
'ember-cli-test-loader': '0.2.2'
},
resolutions: {
'ember': 'beta'
'ember': 'beta',
}
},
npm: {
devDependencies: {
'ember-cli-test-loader': '^2.2.0',
}
}
},
Expand All @@ -54,10 +54,14 @@ module.exports = {
bower: {
dependencies: {
'ember': 'components/ember#canary',
'ember-cli-test-loader': '0.2.2'
},
resolutions: {
'ember': 'canary'
'ember': 'canary',
}
},
npm: {
devDependencies: {
'ember-cli-test-loader': '^2.2.0',
}
}
}
Expand Down
154 changes: 3 additions & 151 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,162 +1,14 @@
'use strict';

const path = require('path');
const fs = require('fs');
const resolve = require('resolve');

module.exports = {
name: 'ember-cli-qunit',

_getDependencyTrees: function() {
if (this._dependencyTrees) {
return this._dependencyTrees;
}

let emberQUnitPath = path.dirname(resolve.sync('ember-qunit'));
let emberTestHelpersPath = path.dirname(resolve.sync('ember-test-helpers', { basedir: emberQUnitPath }));

this._dependencyTrees = [
this.treeGenerator(emberQUnitPath),
this.treeGenerator(emberTestHelpersPath),
];

return this._dependencyTrees;
},

init: function() {
this._super.init && this._super.init.apply(this, arguments);

const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let dep = checker.for('ember-cli', 'npm');

if (!dep.gt('2.2.0-beta.2')) {
const SilentError = require('silent-error');
throw new SilentError('ember-cli-qunit@3.0.0 and higher requires at least ember-cli@2.2.0. Please downgrade to ember-cli-qunit@2 for older ember-cli version support.');
}

this._shouldPreprocessAddonTestSupport = !!this.options && !!this.options.babel;

this.setTestGenerator();
},

blueprintsPath: function() {
return path.join(__dirname, 'blueprints');
},

// intentionally not calling _super here
// to avoid these trees being namespaced into
// `ember-cli-qunit/test-support/`
treeForAddonTestSupport: function(onDiskAddonTestSupportTree) {
const MergeTrees = require('broccoli-merge-trees');
let trees = [].concat(
this._getDependencyTrees(),
onDiskAddonTestSupportTree
);
let tree = new MergeTrees(trees);

if (this._shouldPreprocessAddonTestSupport) {
return this.preprocessJs(tree, {
registry: this.registry
});
} else {
return tree;
}
},

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

let trees = [
tree,
this._notificationsTree(),
this.treeGenerator(qunitPath)
];

return new MergeTrees(trees, {
annotation: 'ember-cli-qunit: treeForVendor'
treeForAddonTestSupport: function(tree) {
return this.preprocessJs(tree, {
registry: this.registry
});
},

included: function included(app, parentAddon) {
let target = (parentAddon || app);
this._super.included.call(this, target);

this.targetOptions = target.options;

let testSupportPath = target.options.outputPaths.testSupport.js;
testSupportPath = testSupportPath.testSupport || testSupportPath;
testSupportPath = path.dirname(testSupportPath) || 'assets';

if (app.tests) {
let fileAssets = [
'vendor/qunit/qunit.js',
'vendor/qunit/qunit.css',
'vendor/qunit-notifications/index.js',
'vendor/ember-cli-qunit/qunit-configuration.js',
];

let addonOptions = target.options['ember-cli-qunit'];
let hasAddonOptions = !!addonOptions;
let explicitlyDisabledContainerStyles = hasAddonOptions && addonOptions.disableContainerStyles === true;
if (!explicitlyDisabledContainerStyles) {
fileAssets.push('vendor/ember-cli-qunit/test-container-styles.css');
}

fileAssets.forEach(function(file){
app.import(file, {
type: 'test'
});
});

let imgAssets = [
'vendor/ember-cli-qunit/images/passed.png',
'vendor/ember-cli-qunit/images/failed.png'
];

imgAssets.forEach(function(img) {
app.import(img, {
type: 'test',
destDir: testSupportPath
});
});
}
},

_notificationsTree: function() {
const Funnel = require('broccoli-funnel');
let notificationsPath = path.dirname(resolve.sync('qunit-notifications'));
return new Funnel(notificationsPath, {
include: [ 'index.js' ],
destDir: 'qunit-notifications',
annotation: 'qunit-notifications'
});
},

contentFor: function(type) {
// Skip if insertContentForTestBody === false.
if (type === 'test-body' && !(this.targetOptions['ember-cli-qunit'] && this.targetOptions['ember-cli-qunit'].insertContentForTestBody === false)) {
return this._readTemplate('test-body');
}
},

_readTemplate: function(name) {
return fs.readFileSync(path.join(__dirname, 'templates', name + '.html'));
},

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

tests.forEach(function(test) {
output += "QUnit.test('" + test.name + "', function(assert) {\n";
output += " assert.expect(1);\n";
output += " assert.ok(" + test.passed + ", '" + test.errorMessage + "');\n";
output += "});\n";
});

return output;
};
}
};
Loading

0 comments on commit 4ab1f87

Please sign in to comment.