Skip to content

Commit aed21db

Browse files
authored
Set Yadda options (#72)
* Set Yadda options * check for setup* annotation for scenario setup * use default localisation in blueprint steps.js * set localisation from configuration for both parsing features and steps * update dummy app generated files * update test fixtures * bump version * replaces #42
1 parent edb09fe commit aed21db

File tree

25 files changed

+103
-50
lines changed

25 files changed

+103
-50
lines changed

README.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ your Ember test setup using either [ember-qunit](https://github.com/emberjs/embe
1111
[ember-mocha](https://github.com/emberjs/ember-mocha).
1212

1313
The following describes the use of ember-cli-yadda >= v0.4.0 which works only with the latest modern
14-
Ember testing APIs, as laid out in the RFCs
15-
[232](https://github.com/emberjs/rfcs/blob/master/text/0232-simplify-qunit-testing-api.md)
16-
and
14+
Ember testing APIs, as laid out in the RFCs
15+
[232](https://github.com/emberjs/rfcs/blob/master/text/0232-simplify-qunit-testing-api.md)
16+
and
1717
[268](https://github.com/emberjs/rfcs/blob/master/text/0268-acceptance-testing-refactor.md).
1818

1919
For the older APIs use v0.3.x and have a look at our [Legacy Guide](docs/legacy.md).
@@ -40,7 +40,7 @@ You may specify the version of yadda by changing it in package.json and running
4040

4141
## Upgrading
4242

43-
To upgrade to the latest version of this addon from a previous release < 0.4.0, including refactoring your existing
43+
To upgrade to the latest version of this addon from a previous release < 0.4.0, including refactoring your existing
4444
tests to Ember's new testing APIs, follow these steps:
4545

4646
- Install the latest version of ember-cli-yadda.
@@ -49,11 +49,11 @@ tests to Ember's new testing APIs, follow these steps:
4949
- Refactor your step files to use the new testing APIs:
5050
- for application tests, skip using Ember's global test helpers and use those provided by [@ember/test-helpers](https://github.com/emberjs/ember-test-helpers).
5151
- use `async`/`await` for all asynchronous operations, including `andThen()`
52-
- [ember-test-helpers-codemod](https://github.com/simonihmig/ember-test-helpers-codemod) will be able to do most of
52+
- [ember-test-helpers-codemod](https://github.com/simonihmig/ember-test-helpers-codemod) will be able to do most of
5353
these changes automatically
5454
- For further details have a look at the [Migration Guide for QUnit](https://github.com/emberjs/ember-qunit/blob/master/docs/migration.md)
5555
or the [Migration Guide for Mocha](https://github.com/emberjs/ember-mocha/blob/master/docs/migration.md#upgrading-to-the-new-testing-apis)
56-
- *Optional*: customize `tests/helpers/yadda-annotations.js` with any additional setup logic that is needed, see
56+
- *Optional*: customize `tests/helpers/yadda-annotations.js` with any additional setup logic that is needed, see
5757
[here](#customization)
5858

5959
## Usage
@@ -89,8 +89,8 @@ This will generate the following files in your project directory:
8989

9090
#### Integration or unit tests
9191

92-
To create an integration or unit test, you can use `ember g feature [feature title] --type=integration` for an
93-
integration test, or `--type=unit` for a unit test. This generates a feature and step definition file where you can
92+
To create an integration or unit test, you can use `ember g feature [feature title] --type=integration` for an
93+
integration test, or `--type=unit` for a unit test. This generates a feature and step definition file where you can
9494
write your tests.
9595

9696
For example:
@@ -121,26 +121,26 @@ Feature: bananas rot
121121
Then the banana rots
122122
```
123123

124-
The `@setupApplicationTest` annotation will setup all scenarios of this feature as application tests, using the
124+
The `@setupApplicationTest` annotation will setup all scenarios of this feature as application tests, using the
125125
`setupApplicationTest()` function provided by either `ember-qunit` or `ember-mocha`. See the [Annotations](#annotations)
126126
section below for more information on how to setup your tests.
127127

128-
Because we probably have more features about bananas, we add the `Given I have bananas` to the global steps file:
128+
Because we probably have more features about bananas, we add the `Given I have bananas` to the global steps file:
129129
`/tests/acceptance/steps.js`
130130

131131
```js
132132
import yadda from '../../helpers/yadda';
133-
import { visit } from '@ember/test-helpers';
133+
import { visit } from '@ember/test-helpers';
134134

135135
export default function(assert) {
136-
return yadda.localisation.English.library()
136+
return yadda.localisation.default.library()
137137
.given("I have bananas", async function() {
138138
await visit("/bananas");
139139
});
140140
}
141141
```
142142

143-
*Notice that the preferable way to handle asynchronous steps like the one above is to use `async`/ `await`. But you can
143+
*Notice that the preferable way to handle asynchronous steps like the one above is to use `async`/ `await`. But you can
144144
also explicitly return a promise or use a `next()` [callback](https://acuminous.gitbooks.io/yadda-user-guide/en/usage/step-libraries.html).*
145145

146146
The fact that "it's next to apples" is probably unique to this Feature so we'll add it to the feature specific step definitions in `/tests/acceptance/steps/bananas-rot-feature-steps.js`. That will look like this:
@@ -172,8 +172,8 @@ export default function(assert) {
172172

173173
##### Scope and helpers
174174

175-
ember-cli-yadda passes the original scope down to each step definition. This means that you have access to the same
176-
context (like `this.element` or `this.owner`) and helpers from `@ember/test-helpers` (like `click()`), as you did when
175+
ember-cli-yadda passes the original scope down to each step definition. This means that you have access to the same
176+
context (like `this.element` or `this.owner`) and helpers from `@ember/test-helpers` (like `click()`), as you did when
177177
writing a normal test in QUnit/Mocha.
178178

179179
##### Sharing variables between steps
@@ -215,23 +215,23 @@ You already saw the use of the `@setupApplicationTest` annotation in the example
215215
Yadda's [support for annotations](https://acuminous.gitbooks.io/yadda-user-guide/en/feature-specs/annotations.html`) can
216216
be used to customize the way tests are run.
217217

218-
The implementation for the way certain annotations affect your tests lives in the `tests/yadda-annotations.js` file.
218+
The implementation for the way certain annotations affect your tests lives in the `tests/yadda-annotations.js` file.
219219
The addon installs this file with a default implementation as described below, but you can freely customize it at your
220220
will.
221221

222222
#### Skipping tests
223223

224-
You can skip tests by adding the `@ignore` annotation above the Scenario or Feature.
224+
You can skip tests by adding the `@ignore` annotation above the Scenario or Feature.
225225

226226
#### Test suites
227227

228-
You can set `ENV.annotations` to an array of annotations (either statically or e.g. by assigning them from an
228+
You can set `ENV.annotations` to an array of annotations (either statically or e.g. by assigning them from an
229229
environment variable like `process.env.ANNOTATIONS`). This will then run only those Features or Scenarios that have one
230230
of these annotations assigned.
231231

232232
#### Setup tests
233233

234-
For each of the setup functions already known from `ember-qunit` or `ember-mocha`, there exists a corresponding
234+
For each of the setup functions already known from `ember-qunit` or `ember-mocha`, there exists a corresponding
235235
annotation to setup your Feature/Scenario accordingly:
236236

237237
- `@setupTest` for (unit) tests requiring the DI container of Ember to be set up
@@ -240,20 +240,20 @@ annotation to setup your Feature/Scenario accordingly:
240240

241241
#### Customization
242242

243-
You can customize how annotations are handled in your app's `tests/yadda-annotations.js` file, e.g. to add support for
243+
You can customize how annotations are handled in your app's `tests/yadda-annotations.js` file, e.g. to add support for
244244
additional annotations, or extend the existing ones. This module has to export these hooks, that are called by this
245245
addon's test runner:
246246

247247
- `runFeature`: called for each feature. If you return a function, this will be called to run the feature, instead of
248248
the default implementation.
249249
- `runScenario`: similar to `runFeature`, but called for each scenario.
250-
- `setupFeature`: called for each feature to setup the test environment. You can call QUnit's or Mocha's `beforeEach`
250+
- `setupFeature`: called for each feature to setup the test environment. You can call QUnit's or Mocha's `beforeEach`
251251
and `afterEach` functions here to add custom setup/teardown work.
252252
- `setupScenario`: similar to `setupFeature`, but called for each scenario.
253253

254254
Have a look at the existing implementation and the comments present in your `tests/yadda-annotations.js` file!
255255

256-
Here is an example to extend the defaul implementation of the `@setupApplicationTest` annotation to also call the
256+
Here is an example to extend the defaul implementation of the `@setupApplicationTest` annotation to also call the
257257
`setupMirage()` function provided by `ember-cli-mirage` to setup the Mirage server:
258258

259259
```js
@@ -272,6 +272,25 @@ function setupYaddaTest(annotations) {
272272
}
273273
```
274274

275+
### Yadda Configuration
276+
If you need to set Yadda configuration, add the following to `ember-cli-build.js`:
277+
278+
```javascript
279+
module.exports = function(defaults) {
280+
let app = new EmberApp(defaults, {
281+
282+
'ember-cli-yadda': {
283+
yaddaOptions: { // passed through to yadda parseFeature()
284+
language: 'Polish', // converted to Yadda.localisation.Polish
285+
leftPlaceholderChar: '<',
286+
rightPlaceholderChar: '>'
287+
}
288+
289+
}
290+
});
291+
```
292+
See [yadda FeatureParser]([https://github.com/acuminous/yadda/blob/master/lib/parsers/FeatureParser.js#L8]) for yadda options.
293+
275294
## Inner workings
276295
277296
This ember addon registers a preprocessor that parses `.feature` / `.spec` / `.specification` files using [yadda](https://github.com/acuminous/yadda) and generates a `-test.js` file in the apropriate test folder. It also adds a little loader helper ``/tests/helpers/yadda.js`` because yadda does not define an amd module.

blueprints/mocha/ember-cli-yadda/files/tests/acceptance/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
import { visit } from '@ember/test-helpers';
44

55
export default function() {
6-
return yadda.localisation.English.library()
6+
return yadda.localisation.default.library()
77
.given('I type "Ember g feature make-feature"', async function() {
88
await visit('/');
99
expect(true, this.step).to.be.true;

blueprints/mocha/ember-cli-yadda/files/tests/helpers/yadda-annotations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function setupFeature(featureAnnotations) {
5353

5454
function setupScenario(featureAnnotations, scenarioAnnotations) {
5555
let setupFn = setupYaddaTest(scenarioAnnotations);
56-
if (setupFn && (featureAnnotations.application || featureAnnotations.rendering || featureAnnotations.context)) {
57-
throw new Error('You must not assign any @application, @rendering or @context annotations to a scenario as well as its feature!');
56+
if (setupFn && (featureAnnotations.setupapplicationtest || featureAnnotations.setuprenderingtest || featureAnnotations.setuptest)) {
57+
throw new Error('You must not assign any @setupapplicationtest, @setuprenderingtest or @setuptest annotations to a scenario as well as its feature!');
5858
}
5959
return setupFn;
6060
}

blueprints/mocha/ember-cli-yadda/files/tests/integration/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { expect } from 'chai';
33

44
export default function() {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', function(){
77
expect(true, this.step).to.be.true;
88
})

blueprints/mocha/ember-cli-yadda/files/tests/unit/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { expect } from 'chai';
33

44
export default function() {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', function(){
77
expect(true, this.step).to.be.true;
88
})

blueprints/qunit/ember-cli-yadda/files/tests/acceptance/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { visit } from '@ember/test-helpers';
33

44
export default function(assert) {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', async function() {
77
await visit('/');
88
assert.ok(true, this.step);

blueprints/qunit/ember-cli-yadda/files/tests/helpers/yadda-annotations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function setupFeature(featureAnnotations) {
5353

5454
function setupScenario(featureAnnotations, scenarioAnnotations) {
5555
let setupFn = setupYaddaTest(scenarioAnnotations);
56-
if (setupFn && (featureAnnotations.application || featureAnnotations.rendering || featureAnnotations.context)) {
57-
throw new Error('You must not assign any @application, @rendering or @context annotations to a scenario as well as its feature!');
56+
if (setupFn && (featureAnnotations.setupapplicationtest || featureAnnotations.setuprenderingtest || featureAnnotations.setuptest)) {
57+
throw new Error('You must not assign any @setupapplicationtest, @setuprenderingtest or @setuptest annotations to a scenario as well as its feature!');
5858
}
5959
return setupFn;
6060
}

blueprints/qunit/ember-cli-yadda/files/tests/integration/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yadda from '../../helpers/yadda';
22

33
export default function(assert) {
4-
return yadda.localisation.English.library()
4+
return yadda.localisation.default.library()
55
.given('I type "Ember g feature make-feature"', function(){
66
assert.ok(true, this.step);
77
})

blueprints/qunit/ember-cli-yadda/files/tests/unit/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yadda from '../../helpers/yadda';
22

33
export default function(assert) {
4-
return yadda.localisation.English.library()
4+
return yadda.localisation.default.library()
55
.given('I type "Ember g feature make-feature"', function(){
66
assert.ok(true, this.step);
77
})

lib/feature-parser.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ class FeatureParser extends Filter {
1212
this.options = options;
1313
this.extensions = ['feature', 'spec', 'specification'];
1414
this.targetExtension = 'js';
15+
16+
//pull language from original options, if it exists
17+
this.yaddaLanguage = 'English';
18+
if (options.yaddaOptions && options.yaddaOptions.language) {
19+
this.yaddaLanguage = options.yaddaOptions.language;
20+
}
21+
22+
//clone options and change change language to be the object
23+
this.yaddaOptions = Object.assign({}, options.yaddaOptions);
24+
this.yaddaOptions.language = yadda.localisation[this.yaddaLanguage];
1525
}
1626

1727
processString(content, relativePath) {
18-
let feature = new yadda.parsers.FeatureParser().parse(content);
28+
29+
let feature = new yadda.parsers.FeatureParser(this.yaddaOptions).parse(content);
1930
let pathParts = relativePath.split('/');
2031
let basePath = pathParts.slice(0, 2).join('/');
2132
let fileName = pathParts.slice(-1)[0].split('.')[0]; //remove extension
@@ -29,9 +40,11 @@ class FeatureParser extends Filter {
2940
import * as library from '${stepsPath}/${fileName}-steps';
3041
import yaddaAnnotations from '${basePath}/helpers/yadda-annotations';
3142
import testRunner from 'ember-cli-yadda/test-support/${this.testFramework}/test-runner';
32-
43+
3344
const feature = ${JSON.stringify(feature, null, 2)};
34-
45+
46+
yadda.localisation.default = yadda.localisation.${this.yaddaLanguage};
47+
3548
testRunner(feature, yadda, yaddaAnnotations, library);
3649
`;
3750

node-tests/fixtures/main/mocha/acceptance/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { expect } from 'chai';
33
import { visit } from '@ember/test-helpers';
44

55
export default function() {
6-
return yadda.localisation.English.library()
6+
return yadda.localisation.default.library()
77
.given('I type "Ember g feature make-feature"', async function() {
88
await visit('/');
99
expect(true, this.step).to.be.true;

node-tests/fixtures/main/mocha/helpers/yadda-annotations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function setupFeature(featureAnnotations) {
5353

5454
function setupScenario(featureAnnotations, scenarioAnnotations) {
5555
let setupFn = setupYaddaTest(scenarioAnnotations);
56-
if (setupFn && (featureAnnotations.application || featureAnnotations.rendering || featureAnnotations.context)) {
57-
throw new Error('You must not assign any @application, @rendering or @context annotations to a scenario as well as its feature!');
56+
if (setupFn && (featureAnnotations.setupapplicationtest || featureAnnotations.setuprenderingtest || featureAnnotations.setuptest)) {
57+
throw new Error('You must not assign any @setupapplicationtest, @setuprenderingtest or @setuptest annotations to a scenario as well as its feature!');
5858
}
5959
return setupFn;
6060
}

node-tests/fixtures/main/mocha/integration/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { expect } from 'chai';
33

44
export default function() {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', function(){
77
expect(true, this.step).to.be.true;
88
})

node-tests/fixtures/main/mocha/unit/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { expect } from 'chai';
33

44
export default function() {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', function(){
77
expect(true, this.step).to.be.true;
88
})

node-tests/fixtures/main/qunit/acceptance/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { visit } from '@ember/test-helpers';
33

44
export default function(assert) {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', async function() {
77
await visit('/');
88
assert.ok(true, this.step);

node-tests/fixtures/main/qunit/helpers/yadda-annotations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ function setupFeature(featureAnnotations) {
5353

5454
function setupScenario(featureAnnotations, scenarioAnnotations) {
5555
let setupFn = setupYaddaTest(scenarioAnnotations);
56-
if (setupFn && (featureAnnotations.application || featureAnnotations.rendering || featureAnnotations.context)) {
57-
throw new Error('You must not assign any @application, @rendering or @context annotations to a scenario as well as its feature!');
56+
if (setupFn && (featureAnnotations.setupapplicationtest || featureAnnotations.setuprenderingtest || featureAnnotations.setuptest)) {
57+
throw new Error('You must not assign any @setupapplicationtest, @setuprenderingtest or @setuptest annotations to a scenario as well as its feature!');
5858
}
5959
return setupFn;
6060
}

node-tests/fixtures/main/qunit/integration/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yadda from '../../helpers/yadda';
22

33
export default function(assert) {
4-
return yadda.localisation.English.library()
4+
return yadda.localisation.default.library()
55
.given('I type "Ember g feature make-feature"', function(){
66
assert.ok(true, this.step);
77
})

node-tests/fixtures/main/qunit/unit/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yadda from '../../helpers/yadda';
22

33
export default function(assert) {
4-
return yadda.localisation.English.library()
4+
return yadda.localisation.default.library()
55
.given('I type "Ember g feature make-feature"', function(){
66
assert.ok(true, this.step);
77
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-yadda",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Ember-cli yadda addon for running Gherkin acceptance tests",
55
"keywords": [
66
"ember-addon",

tests/acceptance/steps/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yadda from '../../helpers/yadda';
22
import { visit } from '@ember/test-helpers';
33

44
export default function(assert) {
5-
return yadda.localisation.English.library()
5+
return yadda.localisation.default.library()
66
.given('I type "Ember g feature make-feature"', async function() {
77
await visit('/');
88
assert.ok(true, this.step);

tests/helpers/yadda.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
// needed for dummy app to run
21
import yadda from 'npm:yadda';
32
export default yadda;

tests/integration/steps/components/steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import yadda from '../../../helpers/yadda';
22

33
export default function(assert) {
4-
return yadda.localisation.English.library()
4+
return yadda.localisation.default.library()
55
.then('I should see the text "$text"', function(text) {
66
assert.equal(this.element.textContent.trim(), text);
77
});

tests/integration/steps/steps.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import yadda from '../../helpers/yadda';
2+
3+
export default function(assert) {
4+
return yadda.localisation.default.library()
5+
.given('I type "Ember g feature make-feature"', function(){
6+
assert.ok(true, this.step);
7+
})
8+
.when('I look in the folder', function(){
9+
assert.ok(true, this.step);
10+
});
11+
}

0 commit comments

Comments
 (0)