Skip to content

Commit

Permalink
Re-add possibility to enable feature flags within Browser
Browse files Browse the repository at this point in the history
Optional feature flags can now be enabled via a checkbox, rendered at
the top of the test page. The state of the checkbox is set as query
parameter in the URL.

An in-repo-addon ensures that the ENABLE_OPTIONAL_FEATURES flag works
correctly, when the tests are run inside a browser: the workaround using
the in-repo-addon is needed, since the flag needs to be set before
Ember.js is loaded, but there is currently no other way.
  • Loading branch information
pangratz committed Dec 8, 2015
1 parent f58ffe4 commit a1cdc95
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
27 changes: 27 additions & 0 deletions lib/enable-optional-features-via-url/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*jshint node:true*/
module.exports = {
name: 'enable-optional-features-via-url',

/**
So the ENABLE_OPTIONAL_FEATURES flag is considered correctly within the
index.html, it needs to be set before Ember.js is loaded. Since there is
currently no way to access the `window` object within config/environment.js
(and hereby check if there is a query parameter present for the checkbox),
a script is injected, before Ember.js is loaded. The script checks if there
is no value yet for the ENABLE_OPTIONAL_FEATURES flag, and if so, it sets
the flag to true when there is a `enableoptionalfeatures` query parameter.
*/
contentFor: function(name) {
if (name === "vendor-prefix") {
var array = [
"<!-- injected by lib/enable-optional-features-via-url -->",
"window.EmberENV = window.EmberENV || {};",
"if (typeof window.EmberENV.ENABLE_OPTIONAL_FEATURES === 'undefined') {",
" window.EmberENV.ENABLE_OPTIONAL_FEATURES = window.location.search.indexOf('enableoptionalfeatures') !== -1;",
"}"
];

return array.join('\n');
}
}
};
6 changes: 6 additions & 0 deletions lib/enable-optional-features-via-url/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "enable-optional-features-via-url",
"keywords": [
"ember-addon"
]
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
"ember-addon"
],
"ember-addon": {
"configPath": "tests/dummy/config"
"configPath": "tests/dummy/config",
"paths": [
"lib/enable-optional-features-via-url"
]
}
}
9 changes: 1 addition & 8 deletions tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ import Ember from 'ember';

setResolver(resolver);

const ENV = Ember.ENV;
const QUNIT_PARAMS = QUnit.urlParams;
const { assert } = QUnit;

ENV.EXTEND_PROTOTYPES = QUNIT_PARAMS.extendprototypes;
ENV.ENABLE_OPTIONAL_FEATURES = QUNIT_PARAMS.enableoptionalfeatures;
ENV.ENABLE_DS_FILTER = true;

QUnit.begin(function() {
Ember.RSVP.configure('onerror', function(reason) {
// only print error messages if they're exceptions;
Expand Down Expand Up @@ -76,6 +70,5 @@ assert.without = function(array, item) {

addEmberAssertions(assert);

QUnit.config.testTimeout= 2000;
QUnit.config.testTimeout = 2000;
QUnit.config.urlConfig.push({ id: 'enableoptionalfeatures', label: "Enable Opt Features" });

0 comments on commit a1cdc95

Please sign in to comment.