diff --git a/README.md b/README.md index e527aa09..0e5b72cd 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,16 @@ Installation ember install ember-test-selectors ``` +When you install the addon, it should automatically generate a helper located at +`tests/helpers/test-selectors.js` as well as add an import to load that helper +in `tests/test-helper.js`. This sets up the component `data-test-*` auto-binding +for integration tests. + +You can do this manually as well: + +``` +$ ember generate ember-test-selectors +``` Usage ------------------------------------------------------------------------------ diff --git a/blueprints/.eslintrc.js b/blueprints/.eslintrc.js new file mode 100644 index 00000000..af760d3a --- /dev/null +++ b/blueprints/.eslintrc.js @@ -0,0 +1,11 @@ +module.exports = { + parserOptions: { + ecmaVersion: 6, + sourceType: 'module' + }, + env: { + node: null, + browser: true, + embertest: true, + }, +}; diff --git a/blueprints/files/tests/helpers/test-selectors.js b/blueprints/files/tests/helpers/test-selectors.js new file mode 100644 index 00000000..c31dd3df --- /dev/null +++ b/blueprints/files/tests/helpers/test-selectors.js @@ -0,0 +1,11 @@ +import Ember from 'ember'; +import bindDataTestAttributes from 'ember-test-selectors/utils/bind-data-test-attributes'; + +const { Component } = Ember; + +Component.reopen({ + init() { + this._super(...arguments); + bindDataTestAttributes(this); + } +}); diff --git a/blueprints/index.js b/blueprints/index.js new file mode 100644 index 00000000..118a2f43 --- /dev/null +++ b/blueprints/index.js @@ -0,0 +1,17 @@ +var EOL = require('os').EOL; + +module.exports = { + description: 'Generates ember-test-selectors test helper', + + afterInstall: function() { + var TEST_HELPER_PATH = 'tests/test-helper.js'; + var IMPORT_STATEMENT = EOL + "import './helpers/test-selectors';"; + var INSERT_AFTER = "import resolver from './helpers/resolver';"; + + return this.insertIntoFile(TEST_HELPER_PATH, IMPORT_STATEMENT, { + after: INSERT_AFTER + }); + }, + + normalizeEntityName: function() {} +};