Skip to content

Commit 1131ad4

Browse files
authored
Merge pull request #588 from Gaurav0/acceptance_tests_for_tests
Fix tests in 2.16 and add acceptance tests for tests
2 parents 2b49f3e + 5309846 commit 1131ad4

9 files changed

Lines changed: 458 additions & 31 deletions

File tree

app/serializers/gist.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default ApplicationSerializer.extend({
1818
},
1919

2020
normalizeArrayResponse(store, primaryModelClass, payload) {
21-
payload.forEach((hash)=> this.normalizeGist(hash, true));
21+
payload.forEach(hash => this.normalizeGist(hash, true));
2222

2323
return this._super(...arguments);
2424
},

app/services/ember-cli.js

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,6 @@ export default Ember.Service.extend({
265265
// avoids security error
266266
appJS += "window.history.pushState = function() {}; window.history.replaceState = function() {}; window.sessionStorage = undefined;";
267267

268-
// Use parent's version of QUnit in Ember.testing mode
269-
if (testing) {
270-
appJS += "window.QUnit = window.parent.QUnit;";
271-
}
272-
273268
// Hide toolbar since it is not working
274269
appCSS += `\n#qunit-testrunner-toolbar, #qunit-tests a[href] { display: none; }\n`;
275270

@@ -307,6 +302,10 @@ export default Ember.Service.extend({
307302
let EmberENV = twiddleJSON.EmberENV || {};
308303
const isTestingEnabled = testingEnabled(twiddleJSON);
309304

305+
if (testing && !isTestingEnabled) {
306+
depScriptTags += `<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/qunit/2.3.2/qunit.js"></script>`;
307+
}
308+
310309
depScriptTags += `<script type="text/javascript">EmberENV = ${JSON.stringify(EmberENV)};</script>`;
311310
depScriptTags += `<script type="text/javascript" src="${window.assetMap.loader}"></script>`;
312311

@@ -324,6 +323,41 @@ export default Ember.Service.extend({
324323
}
325324
});
326325

326+
if (isTestingEnabled) {
327+
testStuff += `
328+
<script type="text/javascript">
329+
// Hack around dealing with multiple global QUnits!
330+
jQuery.ajax({
331+
url: 'https://cdnjs.cloudflare.com/ajax/libs/qunit/2.3.2/qunit.js',
332+
dataType: 'text'
333+
}).then(function(script) {
334+
var oldQUnit;
335+
if (window.QUnit) {
336+
oldQUnit = window.QUnit;
337+
}
338+
window.QUnit = {
339+
config: {
340+
autostart: false
341+
}
342+
}
343+
eval(script);
344+
if (!oldQUnit) {
345+
oldQUnit = window.QUnit;
346+
}
347+
if (window.testModule) {
348+
window.require(window.testModule);
349+
}
350+
window.QUnit.start = function() {};
351+
window.QUnit.done(function() {
352+
window.QUnit = oldQUnit;
353+
});
354+
Ember.run(function() {
355+
oldQUnit.start();
356+
});
357+
});
358+
</script>`;
359+
}
360+
327361
depScriptTags += `<script type="text/javascript" src="${window.assetMap.twiddleDeps}"></script>`;
328362

329363
if (isTestingEnabled) {
@@ -355,7 +389,7 @@ export default Ember.Service.extend({
355389
testJSFiles.forEach(jsFile => {
356390
depScriptTags += `<script type="text/javascript" src="${window.assetMap[jsFile]}"></script>`;
357391
});
358-
392+
359393
testStuff += `<script type="text/javascript">
360394
Ember.Test.adapter = require('ember-qunit').QUnitAdapter.create();
361395
</script>`;

bower.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"bootstrap-sass": "~3.3.5",
88
"dom-ruler": "~0.2.4",
99
"pretender": "~1.4.1",
10-
"ember-inflector": "~1.3.1",
1110
"lodash": "~3.10.1",
1211
"Faker": "~3.1.0",
1312
"file-saver": "1.3.4",

ember-cli-build.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ module.exports = function(defaults) {
7474
},
7575

7676
tests: true,
77-
hinting: process.env.EMBER_CLI_TEST_COMMAND || !isProductionLikeBuild,
78-
79-
vendorFiles: {
80-
'ember.js': {
81-
staging: 'bower_components/ember/ember.prod.js'
82-
},
83-
'ember-testing.js': []
84-
}
77+
hinting: process.env.EMBER_CLI_TEST_COMMAND || !isProductionLikeBuild
8578
});
8679

8780
if (isFastboot) {
@@ -99,10 +92,6 @@ module.exports = function(defaults) {
9992
app.import('vendor/shims/path.js');
10093
app.import('bower_components/file-saver/FileSaver.js');
10194

102-
if (env === "test") {
103-
app.import('bower_components/ember/ember-testing.js', { type: 'test' });
104-
}
105-
10695
if (!isFastboot) {
10796
app.import('vendor/drags.js');
10897
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from 'ember-twiddle/tests/helpers/module-for-acceptance';
3+
import { timeout } from 'ember-concurrency';
4+
5+
moduleForAcceptance('Acceptance | acceptance-application-test', {
6+
beforeEach: function() {
7+
this.cachePrompt = window.prompt;
8+
window.prompt = (text, defaultResponse) => defaultResponse;
9+
},
10+
11+
afterEach: function() {
12+
window.prompt = this.cachePrompt;
13+
}
14+
});
15+
16+
test('An acceptance test for an application works', function(assert) {
17+
18+
const files = [
19+
{
20+
filename: "application.template.hbs",
21+
content: `Welcome to {{appName}}`
22+
},
23+
{
24+
filename: "application.controller.js",
25+
content: `import Ember from "ember";
26+
export default Ember.Controller.extend({
27+
appName: 'Ember Twiddle'
28+
});`
29+
},
30+
{
31+
filename: "twiddle.json",
32+
content: `{
33+
"version": "0.13.0",
34+
"EmberENV": {
35+
"FEATURES": {}
36+
},
37+
"options": {
38+
"use_pods": false,
39+
"enable-testing": true
40+
},
41+
"dependencies": {
42+
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js"
43+
}
44+
}`
45+
},
46+
{
47+
filename: "components/my-component.js",
48+
content: `import Ember from 'ember';
49+
50+
export default Ember.Component.extend({
51+
});`
52+
},
53+
{
54+
filename: "templates/components/my-component.hbs",
55+
content: `{{yield}}`
56+
},
57+
{
58+
filename: "tests/test-helper.js",
59+
content: `import resolver from './helpers/resolver';
60+
import {
61+
setResolver
62+
} from 'ember-qunit';
63+
import jQuery from 'jquery';
64+
65+
setResolver(resolver);
66+
67+
window.testModule = 'twiddle/tests/acceptance/application-test';
68+
`
69+
},
70+
{
71+
filename: "tests/helpers/resolver.js",
72+
content: `import Resolver from '../../resolver';
73+
import config from '../../config/environment';
74+
75+
const resolver = Resolver.create();
76+
77+
resolver.namespace = {
78+
modulePrefix: config.modulePrefix,
79+
podModulePrefix: config.podModulePrefix
80+
};
81+
82+
export default resolver;`
83+
},
84+
{
85+
filename: "tests/helpers/module-for-acceptance.js",
86+
content: `import { module } from 'qunit';
87+
import Ember from 'ember';
88+
import startApp from '../helpers/start-app';
89+
import destroyApp from '../helpers/destroy-app';
90+
91+
const { RSVP: { Promise } } = Ember;
92+
93+
export default function(name, options = {}) {
94+
module(name, {
95+
beforeEach() {
96+
this.application = startApp();
97+
98+
if (options.beforeEach) {
99+
return options.beforeEach.apply(this, arguments);
100+
}
101+
},
102+
103+
afterEach() {
104+
let afterEach = options.afterEach && options.afterEach.apply(this, arguments);
105+
return Promise.resolve(afterEach).then(() => destroyApp(this.application));
106+
}
107+
});
108+
}`
109+
},
110+
{
111+
filename: "tests/helpers/start-app.js",
112+
content: `import Ember from 'ember';
113+
import Application from '../../app';
114+
import config from '../../config/environment';
115+
116+
const { run } = Ember;
117+
const assign = Ember.assign || Ember.merge;
118+
119+
export default function startApp(attrs) {
120+
let application;
121+
122+
let attributes = assign({rootElement: "#test-root"}, config.APP);
123+
attributes = assign(attributes, attrs); // use defaults, but you can override;
124+
125+
run(() => {
126+
application = Application.create(attributes);
127+
application.setupForTesting();
128+
application.injectTestHelpers();
129+
});
130+
131+
return application;
132+
}
133+
`
134+
},
135+
{
136+
filename: "tests/helpers/destroy-app.js",
137+
content: `import Ember from 'ember';
138+
139+
export default function destroyApp(application) {
140+
Ember.run(application, 'destroy');
141+
}`
142+
},
143+
{
144+
filename: "tests/acceptance/application-test.js",
145+
content: `import { test } from 'qunit';
146+
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
147+
148+
moduleForAcceptance('TODO: put something here');
149+
150+
test('visiting /application', function(assert) {
151+
visit('/');
152+
153+
andThen(function() {
154+
assert.equal(currentURL(), '/', 'route loaded correctly');
155+
});
156+
});`
157+
}
158+
];
159+
160+
runGist(files);
161+
162+
andThen(function() {
163+
return timeout(500); // TODO: fix and remove this timing hack
164+
});
165+
166+
andThen(function() {
167+
const outputSpan = 'div#qunit-testresult-display > span.passed';
168+
169+
assert.equal(outputPane().$(outputSpan).text(), '1', 'acceptance test passed');
170+
});
171+
});

0 commit comments

Comments
 (0)