This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #191 from rwjblue/reduce-to-shim
Remove functionality to defer to ember-qunit API.
- Loading branch information
Showing
11 changed files
with
92 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} | ||
}; |
Oops, something went wrong.