From b7e4766aeb1c55ad7dc9dd85a3e215b8aa61cb5d Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 21 Mar 2018 15:44:27 +0100 Subject: [PATCH 1/6] test-helper: Use `setApplication()` API --- tests/dummy/config/environment.js | 1 + tests/helpers/resolver.js | 11 ----------- tests/helpers/start-app.js | 1 + tests/test-helper.js | 8 +++++--- 4 files changed, 7 insertions(+), 14 deletions(-) delete mode 100644 tests/helpers/resolver.js diff --git a/tests/dummy/config/environment.js b/tests/dummy/config/environment.js index 5e48d413..7ffb6855 100644 --- a/tests/dummy/config/environment.js +++ b/tests/dummy/config/environment.js @@ -44,6 +44,7 @@ module.exports = function(environment) { ENV.APP.LOG_VIEW_LOOKUPS = false; ENV.APP.rootElement = '#ember-testing'; + ENV.APP.autoboot = false; } if (environment === 'production') { diff --git a/tests/helpers/resolver.js b/tests/helpers/resolver.js deleted file mode 100644 index b208d38d..00000000 --- a/tests/helpers/resolver.js +++ /dev/null @@ -1,11 +0,0 @@ -import Resolver from '../../resolver'; -import config from '../../config/environment'; - -const resolver = Resolver.create(); - -resolver.namespace = { - modulePrefix: config.modulePrefix, - podModulePrefix: config.podModulePrefix -}; - -export default resolver; diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js index af5b14de..9b41b3f8 100644 --- a/tests/helpers/start-app.js +++ b/tests/helpers/start-app.js @@ -7,6 +7,7 @@ export default function startApp(attrs) { let application; let attributes = merge({}, config.APP); + attributes.autoboot = true; attributes = merge(attributes, attrs); // use defaults, but you can override; run(() => { diff --git a/tests/test-helper.js b/tests/test-helper.js index b5c0c4e6..0382a848 100644 --- a/tests/test-helper.js +++ b/tests/test-helper.js @@ -1,6 +1,8 @@ -import resolver from './helpers/resolver'; -import { setResolver } from '@ember/test-helpers'; +import Application from '../app'; +import config from '../config/environment'; +import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; -setResolver(resolver); +setApplication(Application.create(config.APP)); + start(); From d1d58c4e7d6e94115d7f2fb29dc35246938a7dc8 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 12 Nov 2019 09:44:26 +0100 Subject: [PATCH 2/6] Add `ember-maybe-import-regenerator` dev dependency --- package.json | 1 + yarn.lock | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b27b4a48..903ffb69 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "ember-cli-inject-live-reload": "^2.0.2", "ember-disable-prototype-extensions": "^1.1.2", "ember-load-initializers": "^2.1.0", + "ember-maybe-import-regenerator": "^0.1.6", "ember-qunit": "^4.6.0", "ember-resolver": "^5.3.0", "ember-source": "~3.14.1", diff --git a/yarn.lock b/yarn.lock index cb1a1e67..8b06cb3c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2047,6 +2047,26 @@ broccoli-funnel-reducer@^1.0.0: resolved "https://registry.yarnpkg.com/broccoli-funnel-reducer/-/broccoli-funnel-reducer-1.0.0.tgz#11365b2a785aec9b17972a36df87eef24c5cc0ea" integrity sha1-ETZbKnha7JsXlyo234fu8kxcwOo= +broccoli-funnel@^1.0.1: + version "1.2.0" + resolved "https://registry.yarnpkg.com/broccoli-funnel/-/broccoli-funnel-1.2.0.tgz#cddc3afc5ff1685a8023488fff74ce6fb5a51296" + integrity sha1-zdw6/F/xaFqAI0iP/3TOb7WlEpY= + dependencies: + array-equal "^1.0.0" + blank-object "^1.0.1" + broccoli-plugin "^1.3.0" + debug "^2.2.0" + exists-sync "0.0.4" + fast-ordered-set "^1.0.0" + fs-tree-diff "^0.5.3" + heimdalljs "^0.2.0" + minimatch "^3.0.0" + mkdirp "^0.5.0" + path-posix "^1.0.0" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + walk-sync "^0.3.1" + broccoli-funnel@^2.0.0, broccoli-funnel@^2.0.1, broccoli-funnel@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/broccoli-funnel/-/broccoli-funnel-2.0.2.tgz#0edf629569bc10bd02cc525f74b9a38e71366a75" @@ -2087,6 +2107,20 @@ broccoli-lint-eslint@^5.0.0: lodash.defaultsdeep "^4.6.0" md5-hex "^2.0.0" +broccoli-merge-trees@^1.0.0: + version "1.2.4" + resolved "https://registry.yarnpkg.com/broccoli-merge-trees/-/broccoli-merge-trees-1.2.4.tgz#a001519bb5067f06589d91afa2942445a2d0fdb5" + integrity sha1-oAFRm7UGfwZYnZGvopQkRaLQ/bU= + dependencies: + broccoli-plugin "^1.3.0" + can-symlink "^1.0.0" + fast-ordered-set "^1.0.2" + fs-tree-diff "^0.5.4" + heimdalljs "^0.2.1" + heimdalljs-logger "^0.1.7" + rimraf "^2.4.3" + symlink-or-copy "^1.0.0" + broccoli-merge-trees@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/broccoli-merge-trees/-/broccoli-merge-trees-2.0.0.tgz#10aea46dd5cebcc8b8f7d5a54f0a84a4f0bb90b9" @@ -3100,7 +3134,7 @@ ember-cli-babel-plugin-helpers@^1.0.0, ember-cli-babel-plugin-helpers@^1.1.0: resolved "https://registry.yarnpkg.com/ember-cli-babel-plugin-helpers/-/ember-cli-babel-plugin-helpers-1.1.0.tgz#de3baedd093163b6c2461f95964888c1676325ac" integrity sha512-Zr4my8Xn+CzO0gIuFNXji0eTRml5AxZUTDQz/wsNJ5AJAtyFWCY4QtKdoELNNbiCVGt1lq5yLiwTm4scGKu6xA== -ember-cli-babel@^6.16.0, ember-cli-babel@^6.8.1, ember-cli-babel@^6.8.2: +ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.16.0, ember-cli-babel@^6.8.1, ember-cli-babel@^6.8.2: version "6.18.0" resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.18.0.tgz#3f6435fd275172edeff2b634ee7b29ce74318957" integrity sha512-7ceC8joNYxY2wES16iIBlbPSxwKDBhYwC8drU3ZEvuPDMwVv1KzxCNu1fvxyFEBWhwaRNTUxSCsEVoTd9nosGA== @@ -3419,6 +3453,16 @@ ember-load-initializers@^2.1.0: ember-cli-babel "^7.10.0" ember-cli-typescript "^2.0.0" +ember-maybe-import-regenerator@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/ember-maybe-import-regenerator/-/ember-maybe-import-regenerator-0.1.6.tgz#35d41828afa6d6a59bc0da3ce47f34c573d776ca" + integrity sha1-NdQYKK+m1qWbwNo85H80xXPXdso= + dependencies: + broccoli-funnel "^1.0.1" + broccoli-merge-trees "^1.0.0" + ember-cli-babel "^6.0.0-beta.4" + regenerator-runtime "^0.9.5" + ember-qunit@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/ember-qunit/-/ember-qunit-4.6.0.tgz#ad79fd3ff00073a8779400cc5a4b44829517590f" @@ -3999,6 +4043,11 @@ execa@^1.0.0: signal-exit "^3.0.0" strip-eof "^1.0.0" +exists-sync@0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/exists-sync/-/exists-sync-0.0.4.tgz#9744c2c428cc03b01060db454d4b12f0ef3c8879" + integrity sha1-l0TCxCjMA7AQYNtFTUsS8O88iHk= + exit@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" @@ -4118,7 +4167,7 @@ fast-levenshtein@~2.0.4: resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" integrity sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc= -fast-ordered-set@^1.0.0: +fast-ordered-set@^1.0.0, fast-ordered-set@^1.0.2: version "1.0.3" resolved "https://registry.yarnpkg.com/fast-ordered-set/-/fast-ordered-set-1.0.3.tgz#3fbb36634f7be79e4f7edbdb4a357dee25d184eb" integrity sha1-P7s2Y097555PftvbSjV97iXRhOs= @@ -7195,6 +7244,11 @@ regenerator-runtime@^0.12.0: resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de" integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg== +regenerator-runtime@^0.9.5: + version "0.9.6" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.9.6.tgz#d33eb95d0d2001a4be39659707c51b0cb71ce029" + integrity sha1-0z65XQ0gAaS+OWWXB8UbDLcc4Ck= + regenerator-transform@0.9.11: version "0.9.11" resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.9.11.tgz#3a7d067520cb7b7176769eb5ff868691befe1283" From f839f941a078ba061e9f880397b40163cf56f21b Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 11 Nov 2019 21:59:04 +0100 Subject: [PATCH 3/6] ESLint: Update `parserOptions.ecmaVersion` to allow async/await --- tests/.eslintrc.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js index 244a5da9..0d98b50e 100644 --- a/tests/.eslintrc.js +++ b/tests/.eslintrc.js @@ -1,4 +1,8 @@ module.exports = { + parserOptions: { + sourceType: 'module', + ecmaVersion: 2017 + }, extends: [ 'simplabs/configs/ember-qunit', 'simplabs/plugins/qunit', From d7bff043bb9ce72164e55ce9056f1fbcbdb773c1 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 11 Nov 2019 21:54:26 +0100 Subject: [PATCH 4/6] tests/utils: Use nested test suite syntax --- .../utils/bind-data-test-attributes-test.js | 259 +++++++++--------- 1 file changed, 129 insertions(+), 130 deletions(-) diff --git a/tests/unit/utils/bind-data-test-attributes-test.js b/tests/unit/utils/bind-data-test-attributes-test.js index 06625123..90039b86 100644 --- a/tests/unit/utils/bind-data-test-attributes-test.js +++ b/tests/unit/utils/bind-data-test-attributes-test.js @@ -5,187 +5,186 @@ import { dasherize } from '@ember/string'; import bindDataTestAttributes from 'ember-test-selectors/utils/bind-data-test-attributes'; -module('Unit | Utility | bind data test attributes'); +module('Unit | Utility | bind data test attributes', function() { + test('it adds missing attributeBindings array', function(assert) { + let Fixture = EmberObject.extend({ + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + 'data-test-from-invocation': 'bar', + }); -test('it adds missing attributeBindings array', function(assert) { - let Fixture = EmberObject.extend({ - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - 'data-test-from-invocation': 'bar', + assert.deepEqual(instance.get('attributeBindings'), undefined); + + bindDataTestAttributes(instance); + + assert.deepEqual(instance.get('attributeBindings'), + ['data-test-from-invocation', 'data-test-from-factory']); }); - assert.deepEqual(instance.get('attributeBindings'), undefined); + test('it adds to existing attributeBindings array', function(assert) { + let Fixture = EmberObject.extend({ + attributeBindings: ['foo', 'bar'], - bindDataTestAttributes(instance); + foo: 1, + bar: 2, - assert.deepEqual(instance.get('attributeBindings'), - ['data-test-from-invocation', 'data-test-from-factory']); -}); + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + 'data-test-from-invocation': 'bar', + }); -test('it adds to existing attributeBindings array', function(assert) { - let Fixture = EmberObject.extend({ - attributeBindings: ['foo', 'bar'], + assert.deepEqual(instance.get('attributeBindings'), ['foo', 'bar']); - foo: 1, - bar: 2, + bindDataTestAttributes(instance); - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - 'data-test-from-invocation': 'bar', + assert.deepEqual(instance.get('attributeBindings'), + ['foo', 'bar', 'data-test-from-invocation', 'data-test-from-factory']); }); - assert.deepEqual(instance.get('attributeBindings'), ['foo', 'bar']); + test('it converts existing attributeBindings string to array', function(assert) { + let Fixture = EmberObject.extend({ + attributeBindings: 'foo', - bindDataTestAttributes(instance); + foo: 1, - assert.deepEqual(instance.get('attributeBindings'), - ['foo', 'bar', 'data-test-from-invocation', 'data-test-from-factory']); -}); + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + 'data-test-from-invocation': 'bar', + }); -test('it converts existing attributeBindings string to array', function(assert) { - let Fixture = EmberObject.extend({ - attributeBindings: 'foo', + assert.deepEqual(instance.get('attributeBindings'), 'foo'); - foo: 1, + bindDataTestAttributes(instance); - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - 'data-test-from-invocation': 'bar', + assert.deepEqual(instance.get('attributeBindings'), + ['foo', 'data-test-from-invocation', 'data-test-from-factory']); }); - assert.deepEqual(instance.get('attributeBindings'), 'foo'); + test('it only adds data-test-* properties', function(assert) { + let Fixture = EmberObject.extend({ + foo: 1, + bar: 2, - bindDataTestAttributes(instance); + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + baz: 3, - assert.deepEqual(instance.get('attributeBindings'), - ['foo', 'data-test-from-invocation', 'data-test-from-factory']); -}); + 'data-test-from-invocation': 'bar', + }); -test('it only adds data-test-* properties', function(assert) { - let Fixture = EmberObject.extend({ - foo: 1, - bar: 2, + assert.deepEqual(instance.get('attributeBindings'), undefined); - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - baz: 3, + bindDataTestAttributes(instance); - 'data-test-from-invocation': 'bar', + assert.deepEqual(instance.get('attributeBindings'), + ['data-test-from-invocation', 'data-test-from-factory']); }); - assert.deepEqual(instance.get('attributeBindings'), undefined); + test('it does not add a data-test property', function(assert) { + let Fixture = EmberObject.extend({ + 'data-test': 'foo', + }); + let instance = Fixture.create(); - bindDataTestAttributes(instance); + assert.deepEqual(instance.get('attributeBindings'), undefined); - assert.deepEqual(instance.get('attributeBindings'), - ['data-test-from-invocation', 'data-test-from-factory']); -}); + bindDataTestAttributes(instance); -test('it does not add a data-test property', function(assert) { - let Fixture = EmberObject.extend({ - 'data-test': 'foo', + assert.deepEqual(instance.get('attributeBindings'), undefined); }); - let instance = Fixture.create(); - assert.deepEqual(instance.get('attributeBindings'), undefined); - - bindDataTestAttributes(instance); - - assert.deepEqual(instance.get('attributeBindings'), undefined); -}); + test('it breaks if attributeBindings is a computed property', function(assert) { + let Fixture = EmberObject.extend({ + attributeBindings: computed('prop', function() { + return [this.get('prop')]; + }).readOnly(), -test('it breaks if attributeBindings is a computed property', function(assert) { - let Fixture = EmberObject.extend({ - attributeBindings: computed('prop', function() { - return [this.get('prop')]; - }).readOnly(), + foo: 5, - foo: 5, + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + prop: 'foo', - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - prop: 'foo', + 'data-test-from-invocation': 'bar', + }); - 'data-test-from-invocation': 'bar', + assert.throws(() => bindDataTestAttributes(instance)); }); - assert.throws(() => bindDataTestAttributes(instance)); -}); + test('it breaks if tagName is empty', function(assert) { + let Fixture = EmberObject.extend({ + tagName: '', + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + 'data-test-from-invocation': 'bar', + }); -test('it breaks if tagName is empty', function(assert) { - let Fixture = EmberObject.extend({ - tagName: '', - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - 'data-test-from-invocation': 'bar', + assert.throws(() => bindDataTestAttributes(instance)); }); - assert.throws(() => bindDataTestAttributes(instance)); -}); + test('it does not breaks if tagName is empty and supportsDataTestProperties is set', function(assert) { + assert.expect(0); -test('it does not breaks if tagName is empty and supportsDataTestProperties is set', function(assert) { - assert.expect(0); + let Fixture = EmberObject.extend({ + tagName: '', + supportsDataTestProperties: true, + 'data-test-from-factory': 'foo', + }); + let instance = Fixture.create({ + 'data-test-from-invocation': 'bar', + }); - let Fixture = EmberObject.extend({ - tagName: '', - supportsDataTestProperties: true, - 'data-test-from-factory': 'foo', - }); - let instance = Fixture.create({ - 'data-test-from-invocation': 'bar', + bindDataTestAttributes(instance); }); - bindDataTestAttributes(instance); -}); + test('issue #106', function(assert) { + let Component = EmberObject.extend({}); -test('issue #106', function(assert) { - let Component = EmberObject.extend({}); + Component.reopen({ + init() { + this._super(...arguments); + bindDataTestAttributes(this); + }, + }); - Component.reopen({ - init() { - this._super(...arguments); - bindDataTestAttributes(this); - }, - }); + let Mixin = EmberMixin.create({ + init() { + this._super(...arguments); - let Mixin = EmberMixin.create({ - init() { - this._super(...arguments); + if (this.tagName !== '') { + let componentName = dasherize(this._XXXdebugContainerKey.replace(/\//g, '-').split(':')[1]); + this.set('data-test-component', componentName); - if (this.tagName !== '') { - let componentName = dasherize(this._XXXdebugContainerKey.replace(/\//g, '-').split(':')[1]); - this.set('data-test-component', componentName); + let dataTestAttr = ['data-test-component']; + this.attributeBindings = this.attributeBindings ? this.attributeBindings.concat(dataTestAttr) : dataTestAttr; + } + }, + }); - let dataTestAttr = ['data-test-component']; - this.attributeBindings = this.attributeBindings ? this.attributeBindings.concat(dataTestAttr) : dataTestAttr; - } - }, - }); - - Component.reopen(Mixin); + Component.reopen(Mixin); - let Fixture1 = Component.extend({ - _XXXdebugContainerKey: 'component:fixture1', - tagName: 'span', - }); + let Fixture1 = Component.extend({ + _XXXdebugContainerKey: 'component:fixture1', + tagName: 'span', + }); - let fixture1 = Fixture1.create(); + let fixture1 = Fixture1.create(); - assert.strictEqual(fixture1.get('data-test-component'), 'fixture1'); + assert.strictEqual(fixture1.get('data-test-component'), 'fixture1'); - let Fixture2 = Component.extend({ - _XXXdebugContainerKey: 'component:fixture2', - tagName: '', - }); + let Fixture2 = Component.extend({ + _XXXdebugContainerKey: 'component:fixture2', + tagName: '', + }); - let fixture2 = Fixture2.create(); + let fixture2 = Fixture2.create(); - assert.strictEqual(fixture2.get('data-test-component'), undefined); + assert.strictEqual(fixture2.get('data-test-component'), undefined); + }); }); - From a8e28667cc9b78aee23a74e31ccc50c23c8c0dbd Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 11 Nov 2019 22:02:13 +0100 Subject: [PATCH 5/6] tests/integration: Replace `moduleForComponent()` with `setupRenderingTest()` --- ...ta-test-attributes-from-components-test.js | 112 +++++++++--------- ...rip-data-test-attributes-from-tags-test.js | 80 +++++++------ 2 files changed, 96 insertions(+), 96 deletions(-) diff --git a/tests/integration/strip-data-test-attributes-from-components-test.js b/tests/integration/strip-data-test-attributes-from-components-test.js index d983d9d0..5cdcb08c 100644 --- a/tests/integration/strip-data-test-attributes-from-components-test.js +++ b/tests/integration/strip-data-test-attributes-from-components-test.js @@ -1,4 +1,6 @@ -import { moduleForComponent, test, skip } from 'ember-qunit'; +import { module, test, skip } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import config from 'dummy/config/environment'; @@ -7,80 +9,76 @@ import { hasEmberVersion } from 'dummy/version-checks'; -moduleForComponent('print-test-attributes', 'StripTestSelectorsTransform plugin', { - integration: true -}); - -if (config.stripTestSelectors) { - - (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', function(assert) { - this.render(hbs`{{print-test-attributes data-test-should-not-be}}`); +module('StripTestSelectorsTransform plugin', function(hooks) { + setupRenderingTest(hooks); - assert.dom('.data-test-positional-params').hasText(hasEmberVersion(2, 10) || !hasEmberVersion(2, 3) ? '' : '0', 'there should be no params'); - }); + if (config.stripTestSelectors) { + (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with single positional params', async function(assert) { + await render(hbs`{{print-test-attributes data-test-should-not-be}}`); - (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with positional params data-test-* as first param', function(assert) { - this.render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`); + assert.dom('.data-test-positional-params').hasText(hasEmberVersion(2, 10) || !hasEmberVersion(2, 3) ? '' : '0', 'there should be no params'); + }); - assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); - }); + (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with positional params data-test-* as first param', async function(assert) { + await render(hbs`{{print-test-attributes data-test-should-not-be "param1"}}`); - (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with multiple positional params', function(assert) { - this.render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`); + assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); + }); - assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); - }); + (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with multiple positional params', async function(assert) { + await render(hbs`{{print-test-attributes "param1" data-test-should-not-be}}`); - (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with block and multiple positional params', function(assert) { - this.render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`); + assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); + }); - assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); - }); + (hasReliablePositionalParams ? test : skip)('it strips data-test-* attributes from components with block and multiple positional params', async function(assert) { + await render(hbs`{{#print-test-attributes "param1" data-test-should-not-be}}{{/print-test-attributes}}`); - test('it strips data-test-* attributes from components', function(assert) { - this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`); + assert.dom('.data-test-positional-params').hasText('1', 'there should be only one param'); + }); - assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); - }); + test('it strips data-test-* attributes from components', async function(assert) { + await render(hbs`{{print-test-attributes data-test-first="foobar"}}`); - test('it strips data-test-* attributes from components in block form', function(assert) { - this.render(hbs`{{#print-test-attributes data-test-first="foobar"}}hello{{/print-test-attributes}}`); + assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); + }); - assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); - }); + test('it strips data-test-* attributes from components in block form', async function(assert) { + await render(hbs`{{#print-test-attributes data-test-first="foobar"}}hello{{/print-test-attributes}}`); - test('it works with multiple data-test-* attributes on components', function(assert) { - this.render(hbs`{{print-test-attributes data-test-first="foobar" data-test-second="second"}}`); + assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); + }); - assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); - assert.dom('.data-test-second').hasText('', 'the data-test-second attribute was stripped'); - }); + test('it works with multiple data-test-* attributes on components', async function(assert) { + await render(hbs`{{print-test-attributes data-test-first="foobar" data-test-second="second"}}`); - test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) { - this.render(hbs`{{print-test-attributes data-test-first="foobar" data-non-test="baz"}}`); + assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); + assert.dom('.data-test-second').hasText('', 'the data-test-second attribute was stripped'); + }); - assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); - assert.dom('.data-non-test').hasText('baz', 'the data-non-test attribute was not stripped'); - }); + test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', async function(assert) { + await render(hbs`{{print-test-attributes data-test-first="foobar" data-non-test="baz"}}`); - test('it leaves data-test attributes untouched on components', function(assert) { - this.render(hbs`{{print-test-attributes data-test="foo"}}`); + assert.dom('.data-test-first').hasText('', 'the data-test-first was stripped'); + assert.dom('.data-non-test').hasText('baz', 'the data-non-test attribute was not stripped'); + }); - assert.dom('.data-test').hasText('foo', 'the data-test attribute was stripped'); - }); + test('it leaves data-test attributes untouched on components', async function(assert) { + await render(hbs`{{print-test-attributes data-test="foo"}}`); - test('it leaves other data attributes untouched on components', function(assert) { - this.render(hbs`{{print-test-attributes data-non-test="foo"}}`); + assert.dom('.data-test').hasText('foo', 'the data-test attribute was stripped'); + }); - assert.dom('.data-non-test').hasText('foo', 'the data-non-test attribute was not stripped'); - }); + test('it leaves other data attributes untouched on components', async function(assert) { + await render(hbs`{{print-test-attributes data-non-test="foo"}}`); -} else { + assert.dom('.data-non-test').hasText('foo', 'the data-non-test attribute was not stripped'); + }); + } else { + test('it does not strip data-test-* attributes from components', async function(assert) { + await render(hbs`{{print-test-attributes data-test-first="foobar"}}`); - test('it does not strip data-test-* attributes from components', function(assert) { - this.render(hbs`{{print-test-attributes data-test-first="foobar"}}`); - - assert.dom('.data-test-first').hasText('foobar', 'the data-test-first attribute was not stripped'); - }); - -} + assert.dom('.data-test-first').hasText('foobar', 'the data-test-first attribute was not stripped'); + }); + } +}); diff --git a/tests/integration/strip-data-test-attributes-from-tags-test.js b/tests/integration/strip-data-test-attributes-from-tags-test.js index 793837c8..c780119e 100644 --- a/tests/integration/strip-data-test-attributes-from-tags-test.js +++ b/tests/integration/strip-data-test-attributes-from-tags-test.js @@ -1,58 +1,60 @@ -import { moduleForComponent, test } from 'ember-qunit'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import config from 'dummy/config/environment'; -moduleForComponent('data-test-component', 'StripTestSelectorsTransform plugin', { - integration: true -}); +module('StripTestSelectorsTransform plugin', function(hooks) { + setupRenderingTest(hooks); -if (config.stripTestSelectors) { + if (config.stripTestSelectors) { - test('it strips data-test-* attributes from HTML tags', function(assert) { - this.render(hbs``); + test('it strips data-test-* attributes from HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-test-id="my-id"]').doesNotExist('data-test-id is stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-test-id="my-id"]').doesNotExist('data-test-id is stripped'); + }); - test('it works with multiple data-test-* attributes on HTML tags', function(assert) { - this.render(hbs``); + test('it works with multiple data-test-* attributes on HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-test-first]').doesNotExist('data-test-first is stripped'); - assert.dom('span[data-test-second="second-id"]').doesNotExist('data-test-second is stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-test-first]').doesNotExist('data-test-first is stripped'); + assert.dom('span[data-test-second="second-id"]').doesNotExist('data-test-second is stripped'); + }); - test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on HTML tags', function(assert) { - this.render(hbs``); + test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-id="my-id"]').exists('data-id is not stripped'); - assert.dom('span[data-test-id="my-test-id"]').doesNotExist('data-test-id is stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-id="my-id"]').exists('data-id is not stripped'); + assert.dom('span[data-test-id="my-test-id"]').doesNotExist('data-test-id is stripped'); + }); - test('it leaves data-test attributes untouched on HTML tags', function(assert) { - this.render(hbs``); + test('it leaves data-test attributes untouched on HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-test="my-id"]').exists('data-test-id is not stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-test="my-id"]').exists('data-test-id is not stripped'); + }); - test('it leaves other data attributes untouched on HTML tags', function(assert) { - this.render(hbs``); + test('it leaves other data attributes untouched on HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-id="my-id"]').exists('data-id is not stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-id="my-id"]').exists('data-id is not stripped'); + }); -} else { + } else { - test('it does not strip data-test-* attributes from HTML tags', function(assert) { - this.render(hbs``); + test('it does not strip data-test-* attributes from HTML tags', async function(assert) { + await render(hbs``); - assert.dom('span').exists('the span is present'); - assert.dom('span[data-test-id="my-id"]').exists('data-test-id is not stripped'); - }); + assert.dom('span').exists('the span is present'); + assert.dom('span[data-test-id="my-id"]').exists('data-test-id is not stripped'); + }); -} + } +}); From aef80c87e21e17e4fbc86899411da5fd1d1dae43 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 11 Nov 2019 21:53:28 +0100 Subject: [PATCH 6/6] tests/acceptance: Replace `moduleForAcceptance()` with `setupApplicationTest()` --- ...data-test-attributes-in-components-test.js | 137 +++++++++--------- tests/helpers/destroy-app.js | 5 - tests/helpers/module-for-acceptance.js | 21 --- tests/helpers/start-app.js | 20 --- 4 files changed, 70 insertions(+), 113 deletions(-) delete mode 100644 tests/helpers/destroy-app.js delete mode 100644 tests/helpers/module-for-acceptance.js delete mode 100644 tests/helpers/start-app.js diff --git a/tests/acceptance/bind-data-test-attributes-in-components-test.js b/tests/acceptance/bind-data-test-attributes-in-components-test.js index 017025e8..23f007f4 100644 --- a/tests/acceptance/bind-data-test-attributes-in-components-test.js +++ b/tests/acceptance/bind-data-test-attributes-in-components-test.js @@ -1,5 +1,6 @@ -import { test, skip } from 'qunit'; -import moduleForAcceptance from '../../tests/helpers/module-for-acceptance'; +import { module, test, skip } from 'qunit'; +import { setupApplicationTest } from 'ember-qunit'; +import { visit } from '@ember/test-helpers'; import config from 'dummy/config/environment'; import { hasPositionalParams } from 'dummy/version-checks'; @@ -11,70 +12,72 @@ if (!config.stripTestSelectors) { * because initializers are only applied in acceptance tests, but not in * component integration tests. */ - moduleForAcceptance('Acceptance | Initializer | ember-test-selectors', { - beforeEach() { - visit('/bind-test'); - }, - }); - - test('it binds data-test-* attributes on components', function(assert) { - assert.dom('.test1 div[data-test-first]').exists('data-test-first exists'); - assert.dom('.test1 div[data-test-first="foobar"]').exists('data-test-first has correct value'); - }); - - test('it binds data-test-* attributes on components in block form', function(assert) { - assert.dom('.test2 div[data-test-first]').exists('data-test-first exists'); - assert.dom('.test2 div[data-test-first="foobar"]').exists('data-test-first has correct value'); - }); - - test('it works with multiple data-test-* attributes on components', function(assert) { - assert.dom('.test3 div[data-test-first]').exists('data-test-first exists'); - assert.dom('.test3 div[data-test-first="foobar"]').exists('data-test-first has correct value'); - assert.dom('.test3 div[data-test-second]').exists('data-test-second exists'); - assert.dom('.test3 div[data-test-second="second"]').exists('data-test-second has correct value'); - }); - - test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) { - assert.dom('.test4 div[data-test-first]').exists('data-test-first exists'); - assert.dom('.test4 div[data-test-first="foobar"]').exists('data-test-first has correct value'); - assert.dom('.test4 div[data-non-test]').doesNotExist('data-non-test does not exists'); - }); - - test('it leaves data-test attribute untouched on components', function(assert) { - assert.dom('.test5 div[data-test]').doesNotExist('data-test does not exists'); - }); - - test('it leaves other data attributes untouched on components', function(assert) { - assert.dom('.test6 div[data-non-test]').doesNotExist('data-non-test does not exists'); - }); - - test('it binds data-test-* attributes with boolean values on components', function(assert) { - assert.dom('.test7 div[data-test-with-boolean-value]').exists('data-test-with-boolean-value exists'); - }); - - test('it binds data-test-* attributes without values on components', function(assert) { - assert.dom('.test8 div[data-test-without-value]').exists('data-test-without-value exists'); - }); - - test('it binds data-test-* attributes without values on block components', function(assert) { - assert.dom('.test9 div[data-test-without-value]').exists('data-test-without-value exists'); - }); - - (hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) { - assert.dom('.test10 div[data-test]').doesNotExist('data-test does not exists'); - }); - - test('it transforms data-test params to hash pairs on components', function(assert) { - assert.dom('.test11 div[data-test-something]').exists('data-test-something exists'); - }); - - test('it binds data-test attributes on {{link-to}} components', function(assert) { - assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar'); - assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar'); - }); - - test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) { - assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist'); - assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist'); + module('Acceptance | Initializer | ember-test-selectors', function(hooks) { + setupApplicationTest(hooks); + + hooks.beforeEach(async function() { + await visit('/bind-test'); + }); + + test('it binds data-test-* attributes on components', function(assert) { + assert.dom('.test1 div[data-test-first]').exists('data-test-first exists'); + assert.dom('.test1 div[data-test-first="foobar"]').exists('data-test-first has correct value'); + }); + + test('it binds data-test-* attributes on components in block form', function(assert) { + assert.dom('.test2 div[data-test-first]').exists('data-test-first exists'); + assert.dom('.test2 div[data-test-first="foobar"]').exists('data-test-first has correct value'); + }); + + test('it works with multiple data-test-* attributes on components', function(assert) { + assert.dom('.test3 div[data-test-first]').exists('data-test-first exists'); + assert.dom('.test3 div[data-test-first="foobar"]').exists('data-test-first has correct value'); + assert.dom('.test3 div[data-test-second]').exists('data-test-second exists'); + assert.dom('.test3 div[data-test-second="second"]').exists('data-test-second has correct value'); + }); + + test('it leaves other data attributes untouched, when a data-test-* attribute is present as well on components', function(assert) { + assert.dom('.test4 div[data-test-first]').exists('data-test-first exists'); + assert.dom('.test4 div[data-test-first="foobar"]').exists('data-test-first has correct value'); + assert.dom('.test4 div[data-non-test]').doesNotExist('data-non-test does not exists'); + }); + + test('it leaves data-test attribute untouched on components', function(assert) { + assert.dom('.test5 div[data-test]').doesNotExist('data-test does not exists'); + }); + + test('it leaves other data attributes untouched on components', function(assert) { + assert.dom('.test6 div[data-non-test]').doesNotExist('data-non-test does not exists'); + }); + + test('it binds data-test-* attributes with boolean values on components', function(assert) { + assert.dom('.test7 div[data-test-with-boolean-value]').exists('data-test-with-boolean-value exists'); + }); + + test('it binds data-test-* attributes without values on components', function(assert) { + assert.dom('.test8 div[data-test-without-value]').exists('data-test-without-value exists'); + }); + + test('it binds data-test-* attributes without values on block components', function(assert) { + assert.dom('.test9 div[data-test-without-value]').exists('data-test-without-value exists'); + }); + + (hasPositionalParams ? test : skip)('it leaves data-test attribute without value untouched on components', function(assert) { + assert.dom('.test10 div[data-test]').doesNotExist('data-test does not exists'); + }); + + test('it transforms data-test params to hash pairs on components', function(assert) { + assert.dom('.test11 div[data-test-something]').exists('data-test-something exists'); + }); + + test('it binds data-test attributes on {{link-to}} components', function(assert) { + assert.dom('.test-link-to-block a').hasAttribute('data-test-foo', 'bar'); + assert.dom('.test-link-to-inline a').hasAttribute('data-test-foo', 'bar'); + }); + + test('it handles the tagless components without assert when `supportsDataTestProperties` is set', function(assert) { + assert.dom('.test12 div[data-test-with-boolean-value]').doesNotExist('data-test-with-boolean-value does not exist'); + assert.dom('.test13 div[data-test-without-value]').doesNotExist('data-test-without-value does not exist'); + }); }); } diff --git a/tests/helpers/destroy-app.js b/tests/helpers/destroy-app.js deleted file mode 100644 index e7f983bd..00000000 --- a/tests/helpers/destroy-app.js +++ /dev/null @@ -1,5 +0,0 @@ -import { run } from '@ember/runloop'; - -export default function destroyApp(application) { - run(application, 'destroy'); -} diff --git a/tests/helpers/module-for-acceptance.js b/tests/helpers/module-for-acceptance.js deleted file mode 100644 index 0daf9c9a..00000000 --- a/tests/helpers/module-for-acceptance.js +++ /dev/null @@ -1,21 +0,0 @@ -import { Promise } from 'rsvp'; -import { module } from 'qunit'; -import startApp from '../helpers/start-app'; -import destroyApp from '../helpers/destroy-app'; - -export default function(name, options = {}) { - module(name, { - beforeEach() { - this.application = startApp(); - - if (options.beforeEach) { - return options.beforeEach.apply(this, arguments); - } - }, - - afterEach() { - let afterEach = options.afterEach && options.afterEach.apply(this, arguments); - return Promise.resolve(afterEach).then(() => destroyApp(this.application)); - } - }); -} diff --git a/tests/helpers/start-app.js b/tests/helpers/start-app.js deleted file mode 100644 index 9b41b3f8..00000000 --- a/tests/helpers/start-app.js +++ /dev/null @@ -1,20 +0,0 @@ -import { merge } from '@ember/polyfills'; -import { run } from '@ember/runloop'; -import Application from '../../app'; -import config from '../../config/environment'; - -export default function startApp(attrs) { - let application; - - let attributes = merge({}, config.APP); - attributes.autoboot = true; - attributes = merge(attributes, attrs); // use defaults, but you can override; - - run(() => { - application = Application.create(attributes); - application.setupForTesting(); - application.injectTestHelpers(); - }); - - return application; -}