Skip to content

Commit

Permalink
use ember-auto-import instead of ember-browserify #2 (#79)
Browse files Browse the repository at this point in the history
use ember-auto-import instead of ember-browserify
  • Loading branch information
benwalder authored Sep 4, 2018
1 parent 4edbb1f commit d529a8f
Show file tree
Hide file tree
Showing 32 changed files with 11,801 additions and 54 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
excludedFiles: [
'app/**',
'addon/**',
'addon-test-support/**',
'tests/dummy/app/**',
'node-tests/fixtures/**'
],
Expand Down
23 changes: 4 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,20 @@ Installing ember-cli-yadda is a breeze. All you need to do is run the following
ember install ember-cli-yadda
```

This adds the latest version of yadda to your node modules, along with [ember-browserify](https://www.npmjs.com/package/ember-browserify) (to allow yadda to run in the browser). It also adds the following files:
This adds the following files:

```
/tests/acceptance/steps/steps.js
/tests/integration/steps/steps.js
/tests/unit/steps/steps.js
/tests/helpers/yadda.js
/tests/helpers/yadda-annotations.js
```

You may specify the version of yadda by changing it in package.json and running `npm install`.
You may specify the version of yadda by adding it in package.json and running `npm install`.

## Upgrading

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

- Install the latest version of ember-cli-yadda.
- Run `ember g ember-cli-yadda` to add the most recent files from the blueprint to your project.
- Add the appropriate [setup annotation](#setup-tests) to each Feature or Scenario.
- Refactor your step files to use the new testing APIs:
- 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).
- use `async`/`await` for all asynchronous operations, including `andThen()`
- [ember-test-helpers-codemod](https://github.com/simonihmig/ember-test-helpers-codemod) will be able to do most of
these changes automatically
- For further details have a look at the [Migration Guide for QUnit](https://github.com/emberjs/ember-qunit/blob/master/docs/migration.md)
or the [Migration Guide for Mocha](https://github.com/emberjs/ember-mocha/blob/master/docs/migration.md#upgrading-to-the-new-testing-apis)
- *Optional*: customize `tests/helpers/yadda-annotations.js` with any additional setup logic that is needed, see
[here](#customization)
See the [Release Notes](https://github.com/albertjan/ember-cli-yadda/releases).

## Usage

Expand Down Expand Up @@ -129,7 +114,7 @@ Because we probably have more features about bananas, we add the `Given I have b
`/tests/acceptance/steps.js`

```js
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { visit } from '@ember/test-helpers';

export default function(assert) {
Expand Down
2 changes: 2 additions & 0 deletions addon-test-support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import yadda from 'yadda';
export { yadda };
3 changes: 0 additions & 3 deletions blueprints/main-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ module.exports = {
name: 'ember-cli-yadda',
description: 'ember-cli-yadda',
normalizeEntityName() {
},
afterInstall() {
return this.addAddonToProject('ember-browserify');
}
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';
import { visit } from '@ember/test-helpers';

Expand Down
2 changes: 0 additions & 2 deletions blueprints/mocha/ember-cli-yadda/files/tests/helpers/yadda.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';

export default function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';

export default function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { visit } from '@ember/test-helpers';

export default function(assert) {
Expand Down
2 changes: 0 additions & 2 deletions blueprints/qunit/ember-cli-yadda/files/tests/helpers/yadda.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';

export default function(assert) {
return yadda.localisation.default.library()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';

export default function(assert) {
return yadda.localisation.default.library()
Expand Down
2 changes: 1 addition & 1 deletion docs/legacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Feature: bananas rot
Because we probably have more features about bananas. We add the `Given I have bananas` to the global steps file: `/tests/acceptance/steps.js`

```js
import yadda from '../../helpers/yadda';
import { yadda } from '../../helpers/yadda';

export default function(assert) {
return yadda.localisation.English.library()
Expand Down
31 changes: 30 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const FeatureParser = require('./lib/feature-parser');

module.exports = {
name: 'ember-cli-yadda',
options: {
autoImport:{
exclude: ['mocha'],
webpack: {
node: {
fs: "empty"
}
}
}
},
getTestFramework() {
let dependencies = this.project.dependencies();
if ('ember-cli-mocha' in dependencies || 'ember-mocha' in dependencies) {
Expand All @@ -28,11 +38,30 @@ module.exports = {
return path.join(__dirname, 'blueprints', this.getTestFramework());
},
included(app) {
this._super.included(app);
this._super.included.apply(this, arguments);
let options = app.options['ember-cli-yadda'] || {};
if (typeof options.persist === 'undefined') {
options.persist = true;
}
this._options = options;
},
treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
// import { yadda } from 'ember-cli-yadda';
// shamelessly stolen from https://github.com/cibernox/ember-native-dom-helpers/blob/19adea1683fc386baca6eb7c83cd0a147bd4d586/index.js
// and https://github.com/kaliber5/ember-window-mock/blob/master/index.js#L7-L24

const Funnel = require('broccoli-funnel');

let namespacedTree = new Funnel(tree, {
srcDir: '/',
destDir: `/${this.moduleName()}`,
annotation: `Addon#treeForTestSupport (${this.name})`,
});

return this.preprocessJs(namespacedTree, '/', this.name, {
registry: this.registry,
});
}
};
6 changes: 4 additions & 2 deletions lib/feature-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class FeatureParser extends Filter {
let nestedFolderParts = pathParts.slice(3, -1);
let stepsPath = [basePath, testFolder, 'steps', ...nestedFolderParts].join('/');

// import testRunner from 'ember-cli-yadda/test-support/${this.testFramework}/test-runner';

let module = `
import yadda from '${basePath}/helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import * as library from '${stepsPath}/${fileName}-steps';
import yaddaAnnotations from '${basePath}/helpers/yadda-annotations';
import testRunner from 'ember-cli-yadda/test-support/${this.testFramework}/test-runner';
import testRunner from 'ember-cli-yadda/${this.testFramework}/test-runner';
const feature = ${JSON.stringify(feature, null, 2)};
Expand Down
3 changes: 1 addition & 2 deletions node-tests/blueprints/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ describe('Acceptance: ember generate ember-cli-yadda', function() {
let args = ['ember-cli-yadda'];

let fixtureFiles = [
'helpers/yadda.js',
'helpers/yadda-annotations.js',
'helpers/yadda-annotations.js'
].concat(
testTypes.map((type) => `${type}/steps/steps.js`)
);
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/mocha/acceptance/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';
import { visit } from '@ember/test-helpers';

Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/mocha/helpers/yadda.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import yadda from 'npm:yadda';
import { yadda } from 'ember-cli-yadda';
export default yadda;
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/mocha/integration/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';

export default function() {
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/mocha/unit/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { expect } from 'chai';

export default function() {
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/qunit/acceptance/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';
import { visit } from '@ember/test-helpers';

export default function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/qunit/helpers/yadda.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import yadda from 'npm:yadda';
import { yadda } from 'ember-cli-yadda';
export default yadda;
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/qunit/integration/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';

export default function(assert) {
return yadda.localisation.default.library()
Expand Down
2 changes: 1 addition & 1 deletion node-tests/fixtures/main/qunit/unit/steps/steps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import yadda from '../../helpers/yadda';
import { yadda } from 'ember-cli-yadda';

export default function(assert) {
return yadda.localisation.default.library()
Expand Down
Loading

0 comments on commit d529a8f

Please sign in to comment.