Skip to content

Commit ea24362

Browse files
authored
Merge pull request #110 from typed-ember/moar-generators
Acceptance test generator
2 parents 7364d6f + ae5f3fd commit ea24362

File tree

15 files changed

+306
-35
lines changed

15 files changed

+306
-35
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ install:
3535

3636
script:
3737
- yarn lint:js
38+
- yarn ember try:one integrated-node-tests
3839
# Usually, it's ok to finish the test scenario without reverting
3940
# to the addon's original dependency state, skipping "cleanup".
40-
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
41-
- yarn run nodetest
41+
- yarn ember try:one $EMBER_TRY_SCENARIO --skip-cleanup
4242

4343
# We build PRs, but don't trigger separate builds for the PR from the branch.
4444
branches:

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_script:
2828
# Output useful info for debugging.
2929
- yarn versions
3030
- cmd: yarn ember try:one ember-release
31-
- cmd: yarn run nodetest
31+
- cmd: yarn ember try:one integrated-node-tests
3232

3333
# Don't actually build.
3434
build: off
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const pathUtil = require('ember-cli-path-utils');
5+
const stringUtils = require('ember-cli-string-utils');
6+
const existsSync = require('exists-sync');
7+
8+
const useTestFrameworkDetector = require('../test-framework-detector');
9+
10+
module.exports = useTestFrameworkDetector({
11+
description: 'Generates an acceptance test for a feature.',
12+
13+
locals: function(options) {
14+
let testFolderRoot = stringUtils.dasherize(options.project.name());
15+
16+
if (options.project.isEmberCLIAddon()) {
17+
testFolderRoot = pathUtil.getRelativeParentPath(options.entity.name, -1, false);
18+
}
19+
20+
let destroyAppExists = existsSync(
21+
path.join(this.project.root, '/tests/helpers/destroy-app.js')
22+
);
23+
24+
let friendlyTestName = [
25+
'Acceptance',
26+
stringUtils.dasherize(options.entity.name).replace(/[-]/g, ' '),
27+
].join(' | ');
28+
29+
return {
30+
testFolderRoot: testFolderRoot,
31+
friendlyTestName,
32+
destroyAppExists: destroyAppExists,
33+
};
34+
},
35+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, it, beforeEach, afterEach } from 'mocha';
2+
import { expect } from 'chai';
3+
import startApp from '<%= dasherizedPackageName %>/tests/helpers/start-app';
4+
<% if (destroyAppExists) { %>import destroyApp from '<%= dasherizedPackageName %>/tests/helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop';<% } %>
5+
6+
describe('<%= friendlyTestName %>', function() {
7+
let application;
8+
9+
beforeEach(function() {
10+
application = startApp();
11+
});
12+
13+
afterEach(function() {
14+
<% if (destroyAppExists) { %>destroyApp(application);<% } else { %>run(application, 'destroy');<% } %>
15+
});
16+
17+
it('can visit /<%= dasherizedModuleName %>', function() {
18+
visit('/<%= dasherizedModuleName %>');
19+
20+
return andThen(() => {
21+
expect(currentURL()).to.equal('/<%= dasherizedModuleName %>');
22+
});
23+
});
24+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from '<%= testFolderRoot %>/tests/helpers/module-for-acceptance';
3+
4+
moduleForAcceptance('<%= friendlyTestName %>');
5+
6+
test('visiting /<%= dasherizedModuleName %>', function(assert) {
7+
visit('/<%= dasherizedModuleName %>');
8+
9+
andThen(function() {
10+
assert.equal(currentURL(), '/<%= dasherizedModuleName %>');
11+
});
12+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { module, test } from 'qunit';
2+
import { visit, currentURL } from '@ember/test-helpers';
3+
import { setupApplicationTest } from 'ember-qunit';
4+
5+
module('<%= friendlyTestName %>', function(hooks) {
6+
setupApplicationTest(hooks);
7+
8+
test('visiting /<%= dasherizedModuleName %>', async function(assert) {
9+
await visit('/<%= dasherizedModuleName %>');
10+
11+
assert.equal(currentURL(), '/<%= dasherizedModuleName %>');
12+
});
13+
});

config/ember-try.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
module.exports = {
22
useYarn: true,
33
scenarios: [
4+
{
5+
name: 'integrated-node-tests',
6+
command: 'yarn nodetest',
7+
npm: {
8+
devDependencies: {
9+
'ember-cli-qunit': null,
10+
},
11+
},
12+
},
413
{
514
name: 'ember-lts-2.12',
615
npm: {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
'use strict';
2+
3+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
4+
const setupTestHooks = blueprintHelpers.setupTestHooks;
5+
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7+
const modifyPackages = blueprintHelpers.modifyPackages;
8+
9+
const chai = require('ember-cli-blueprint-test-helpers/chai');
10+
const expect = chai.expect;
11+
12+
const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
13+
const fixture = require('../helpers/fixture');
14+
15+
describe('Blueprint: acceptance-test', function() {
16+
setupTestHooks(this);
17+
18+
describe('in app', function() {
19+
beforeEach(function() {
20+
return emberNew();
21+
});
22+
23+
it('acceptance-test foo', function() {
24+
return emberGenerateDestroy(['acceptance-test', 'foo'], _file => {
25+
expect(_file('tests/acceptance/foo-test.ts')).to.equal(
26+
fixture('acceptance-test/default.ts')
27+
);
28+
});
29+
});
30+
31+
describe('with ember-cli-qunit@4.2.0', function() {
32+
beforeEach(function() {
33+
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
34+
});
35+
36+
it('acceptance-test foo', function() {
37+
return emberGenerateDestroy(['acceptance-test', 'foo'], _file => {
38+
expect(_file('tests/acceptance/foo-test.ts')).to.equal(
39+
fixture('acceptance-test/qunit-rfc268.ts')
40+
);
41+
});
42+
});
43+
});
44+
45+
describe('with ember-cli-mocha', function() {
46+
beforeEach(function() {
47+
return modifyPackages([
48+
{ name: 'ember-cli-qunit', delete: true },
49+
{ name: 'ember-cli-mocha', dev: true },
50+
]);
51+
});
52+
53+
it('acceptance-test foo', function() {
54+
return emberGenerateDestroy(['acceptance-test', 'foo'], _file => {
55+
expect(_file('tests/acceptance/foo-test.ts')).to.equal(
56+
fixture('acceptance-test/mocha.ts')
57+
);
58+
});
59+
});
60+
});
61+
});
62+
63+
describe('in addon', function() {
64+
beforeEach(function() {
65+
return emberNew({ target: 'addon' });
66+
});
67+
68+
it('acceptance-test foo', function() {
69+
return emberGenerateDestroy(['acceptance-test', 'foo'], _file => {
70+
expect(_file('tests/acceptance/foo-test.ts')).to.equal(
71+
fixture('acceptance-test/addon-default.ts')
72+
);
73+
74+
expect(_file('app/acceptance-tests/foo.ts')).to.not.exist;
75+
});
76+
});
77+
78+
it('acceptance-test foo/bar', function() {
79+
return emberGenerateDestroy(['acceptance-test', 'foo/bar'], _file => {
80+
expect(_file('tests/acceptance/foo/bar-test.ts')).to.equal(
81+
fixture('acceptance-test/addon-nested.ts')
82+
);
83+
84+
expect(_file('app/acceptance-tests/foo/bar.ts')).to.not.exist;
85+
});
86+
});
87+
88+
describe('with ember-cli-qunit@4.2.0', function() {
89+
beforeEach(function() {
90+
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
91+
});
92+
93+
it('acceptance-test foo', function() {
94+
return emberGenerateDestroy(['acceptance-test', 'foo'], _file => {
95+
expect(_file('tests/acceptance/foo-test.ts')).to.equal(
96+
fixture('acceptance-test/qunit-rfc268.ts')
97+
);
98+
});
99+
});
100+
});
101+
});
102+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
globals: {
3+
andThen: false,
4+
visit: false,
5+
currentURL: false
6+
}
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { test } from 'qunit';
2+
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
3+
4+
moduleForAcceptance('Acceptance | foo');
5+
6+
test('visiting /foo', function(assert) {
7+
visit('/foo');
8+
9+
andThen(function() {
10+
assert.equal(currentURL(), '/foo');
11+
});
12+
});

0 commit comments

Comments
 (0)