Skip to content

Commit

Permalink
upgrade @ember/test-helpers to 3.x; drop node < 16 support
Browse files Browse the repository at this point in the history
  • Loading branch information
fivetanley committed Jun 12, 2023
1 parent b1121fb commit 2590a2f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
49 changes: 30 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ individual tests using an `a11yAudit()` test helper.

## Compatibility

* Ember.js v3.8.0 or above
* Ember CLI v3.8 or above
* Node.js v12 or above
* `@ember/test-helpers` v2.0.0 or above
- Ember.js v3.8.0 or above
- Ember CLI v3.8 or above
- Node.js v16 or above
- `@ember/test-helpers` v3.0.0 or above

Note: we enforce a peerDependency of `@ember/test-helpers`. If you encounter the following message:

Expand All @@ -25,6 +25,8 @@ ember-a11y-testing has the following unmet peerDependencies:

please update your version of `@ember/test-helpers` in your package.json accordingly.

Note: Users who are using Node <= 14 in their apps should use `ember-a11y-testing@^5.2.1`.

## Installation

```bash
Expand Down Expand Up @@ -115,7 +117,7 @@ start();

:warning: It's important to note that you must also use the [`enableA11yAudit`](#force-running-audits) query parameter in order to force audits. This setting is required in addition to any invocation strategy you provide.

By default, audits will be run on `visit`, `click`, `doubleClick`, and `tap`. To add additional helpers to hook into, specify them by name in the `options.helpers` argument. Note that this option specifies the *complete* set of helpers to hook into; to include the defaults you must import them and splat them into the array as shown below.
By default, audits will be run on `visit`, `click`, `doubleClick`, and `tap`. To add additional helpers to hook into, specify them by name in the `options.helpers` argument. Note that this option specifies the _complete_ set of helpers to hook into; to include the defaults you must import them and splat them into the array as shown below.

```js
import {
Expand Down Expand Up @@ -231,7 +233,7 @@ test('Some test case', function (assert) {
},
};

await a11yAudit(this.element, axeOptions)
await a11yAudit(this.element, axeOptions);

assert.ok(true, 'no a11y errors found!');
});
Expand Down Expand Up @@ -291,28 +293,34 @@ To do so, import and use `shouldForceAudit` from `ember-a11y-testing`, as shown
// `&enableA11yAudit` set in the URL
import { a11yAudit, shouldForceAudit } from 'ember-a11y-testing/test-support';

test('Some test case', await function(assert) {
await visit('/');
test(
'Some test case',
await function (assert) {
await visit('/');

if (shouldForceAudit()) {
await a11yAudit();
if (shouldForceAudit()) {
await a11yAudit();
}
assert.ok(true, 'no a11y errors found!');
}
assert.ok(true, 'no a11y errors found!');
});
);
```

```javascript
// No `enableA11yAudit` set in the URL
import { a11yAudit, shouldForceAudit } from 'ember-a11y-testing/test-support';

test('Some test case', await function(assert) {
await visit('/');
test(
'Some test case',
await function (assert) {
await visit('/');

if (shouldForceAudit()) {
await a11yAudit(); // will not run
if (shouldForceAudit()) {
await a11yAudit(); // will not run
}
// ...
}
// ...
});
);
```

You can also create your own app-level helper, which will conditionally check whether to run the audits or not:
Expand Down Expand Up @@ -380,7 +388,10 @@ import Application from 'my-app/app';
import config from 'my-app/config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-qunit';
import { setupMiddlewareReporter, useMiddlewareReporter } from 'ember-a11y-testing/test-support';
import {
setupMiddlewareReporter,
useMiddlewareReporter,
} from 'ember-a11y-testing/test-support';

setApplication(Application.create(config.APP));

Expand Down
10 changes: 3 additions & 7 deletions addon-test-support/setup-global-a11y-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _registerHook } from '@ember/test-helpers';
import { registerHook, type HookUnregister } from '@ember/test-helpers';
import { InvocationStrategy, AuditFunction } from './types';
import { getRunOptions } from './run-options';
import a11yAudit from './audit';
Expand All @@ -24,10 +24,6 @@ type HelperName =
| 'typeIn'
| 'visit';

interface HookUnregister {
unregister: () => void;
}

let _unregisterHooks: HookUnregister[] = [];

export const DEFAULT_A11Y_TEST_HELPER_NAMES: HelperName[] = [
Expand All @@ -38,7 +34,7 @@ export const DEFAULT_A11Y_TEST_HELPER_NAMES: HelperName[] = [
];

/**
* Sets up a11yAudit calls using `@ember/test-helpers`' `_registerHook` API.
* Sets up a11yAudit calls using `@ember/test-helpers`' `registerHook` API.
*
* @param shouldAudit Invocation strategy function that determines whether to run the audit helper or not.
* @param audit Optional audit function used to run the audit. Allows for providing either a11yAudit
Expand Down Expand Up @@ -74,7 +70,7 @@ export function setupGlobalA11yHooks(
let helpers = options?.helpers ?? DEFAULT_A11Y_TEST_HELPER_NAMES;

helpers.forEach((helperName) => {
let hook = _registerHook(helperName, 'end', async () => {
let hook = registerHook(helperName, 'end', async () => {
if (shouldForceAudit() && shouldAudit(helperName, 'end')) {
await audit(getRunOptions());
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.9.3",
"@ember/test-helpers": "^3.0.3",
"@embroider/test-setup": "^2.0.2",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
Expand Down Expand Up @@ -131,7 +131,7 @@
"webpack": "^5.65.0"
},
"peerDependencies": {
"@ember/test-helpers": "^2.0.0",
"@ember/test-helpers": "^3.0.0",
"qunit": ">= 2"
},
"peerDependenciesMeta": {
Expand All @@ -140,7 +140,7 @@
}
},
"engines": {
"node": "12.* || 14.* || >= 16"
"node": "16.* || >= 18"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down Expand Up @@ -168,7 +168,7 @@
}
},
"volta": {
"node": "14.20.0",
"node": "18.16.0",
"yarn": "1.22.19"
}
}
36 changes: 13 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1101,21 +1101,20 @@
dependencies:
ember-cli-babel "^7.26.6"

"@ember/test-helpers@^2.9.3":
version "2.9.3"
resolved "https://registry.yarnpkg.com/@ember/test-helpers/-/test-helpers-2.9.3.tgz#c2a9d6ab1c367af92cf1a334f97eb19b8e06e6e1"
integrity sha512-ejVg4Dj+G/6zyLvQsYOvmGiOLU6AS94tY4ClaO1E2oVvjjtVJIRmVLFN61I+DuyBg9hS3cFoPjQRTZB9MRIbxQ==
"@ember/test-helpers@^3.0.3":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@ember/test-helpers/-/test-helpers-3.0.3.tgz#4d278ebc4576fbf5ff5a2643978f2d310d2656cc"
integrity sha512-W8fEWritv36W216wmuusOlsUJs+iDFkOvHratI8tw466NV4deq9TVej1p5DtUFeDUUP/E14IxqrNNC3qaYszfQ==
dependencies:
"@ember/test-waiters" "^3.0.0"
"@ember/test-waiters" "^3.0.2"
"@embroider/macros" "^1.10.0"
"@embroider/util" "^1.9.0"
broccoli-debug "^0.6.5"
broccoli-funnel "^3.0.8"
ember-auto-import "^2.6.0"
ember-cli-babel "^7.26.11"
ember-cli-htmlbars "^6.1.1"
ember-destroyable-polyfill "^2.0.3"
ember-cli-htmlbars "^6.2.0"

"@ember/test-waiters@^2.4.3 || ^3.0.0", "@ember/test-waiters@^3.0.0":
"@ember/test-waiters@^2.4.3 || ^3.0.0", "@ember/test-waiters@^3.0.2":
version "3.0.2"
resolved "https://registry.yarnpkg.com/@ember/test-waiters/-/test-waiters-3.0.2.tgz#5b950c580a1891ed1d4ee64f9c6bacf49a15ea6f"
integrity sha512-H8Q3Xy9rlqhDKnQpwt2pzAYDouww4TZIGSI1pZJhM7mQIGufQKuB0ijzn/yugA6Z+bNdjYp1HioP8Y4hn2zazQ==
Expand All @@ -1125,7 +1124,7 @@
ember-cli-version-checker "^5.1.2"
semver "^7.3.5"

"@embroider/macros@^1.0.0", "@embroider/macros@^1.10.0", "@embroider/macros@^1.11.0":
"@embroider/macros@^1.0.0", "@embroider/macros@^1.10.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.11.0.tgz#d6c1f1c1325e8253971483c20059edd08ef5a353"
integrity sha512-P/WSB+PqKSja5qXjYvhLyUM0ivcDoI9kkqs+R0GNujfVhS0EIIAMHfD9uHDBbhzFit39pT0QJqgcXGE2rprCPA==
Expand Down Expand Up @@ -1175,15 +1174,6 @@
lodash "^4.17.21"
resolve "^1.20.0"

"@embroider/util@^1.9.0":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@embroider/util/-/util-1.11.1.tgz#622390932542e6b7f8d5d28e956891306e664eb3"
integrity sha512-IqzlEQahM2cfLvo4PULA2WyvROqr9jRmeSv0GGZzpitWCh6l4FDwweOLSArdlKSXdQxHkKhwBMCi//7DhKjRlg==
dependencies:
"@embroider/macros" "^1.11.0"
broccoli-funnel "^3.0.5"
ember-cli-babel "^7.26.11"

"@eslint/eslintrc@^0.4.3":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c"
Expand Down Expand Up @@ -3612,7 +3602,7 @@ broccoli-funnel@^2.0.0, broccoli-funnel@^2.0.1, broccoli-funnel@^2.0.2:
symlink-or-copy "^1.0.0"
walk-sync "^0.3.1"

broccoli-funnel@^3.0.3, broccoli-funnel@^3.0.5, broccoli-funnel@^3.0.8:
broccoli-funnel@^3.0.3, broccoli-funnel@^3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/broccoli-funnel/-/broccoli-funnel-3.0.8.tgz#f5b62e2763c3918026a15a3c833edc889971279b"
integrity sha512-ng4eIhPYiXqMw6SyGoxPHR3YAwEd2lr9FgBI1CyTbspl4txZovOsmzFkMkGAlu88xyvYXJqHiM2crfLa65T1BQ==
Expand Down Expand Up @@ -5178,7 +5168,7 @@ ember-auto-import@^1.11.3:
walk-sync "^0.3.3"
webpack "^4.43.0"

ember-auto-import@^2.2.4, ember-auto-import@^2.5.0:
ember-auto-import@^2.2.4, ember-auto-import@^2.5.0, ember-auto-import@^2.6.0:
version "2.6.3"
resolved "https://registry.yarnpkg.com/ember-auto-import/-/ember-auto-import-2.6.3.tgz#f18d1b93dd10b08ba5496518436f9d56dd4e000a"
integrity sha512-uLhrRDJYWCRvQ4JQ1e64XlSrqAKSd6PXaJ9ZsZI6Tlms9T4DtQFxNXasqji2ZRJBVrxEoLCRYX3RTldsQ0vNGQ==
Expand Down Expand Up @@ -5280,7 +5270,7 @@ ember-cli-github-pages@^0.2.2:
ember-cli-version-checker "^2.1.0"
rsvp "^4.7.0"

ember-cli-htmlbars@^6.0.1, ember-cli-htmlbars@^6.1.1:
ember-cli-htmlbars@^6.0.1, ember-cli-htmlbars@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/ember-cli-htmlbars/-/ember-cli-htmlbars-6.2.0.tgz#18ec48ee1c93f9eed862a64eb24a9d14604f1dfc"
integrity sha512-j5EGixjGau23HrqRiW/JjoAovg5UBHfjbyN7wX5ekE90knIEqUUj1z/Mo/cTx/J2VepQ2lE6HdXW9LWQ/WdMtw==
Expand Down Expand Up @@ -5614,7 +5604,7 @@ ember-compatibility-helpers@^1.1.2, ember-compatibility-helpers@^1.2.1:
fs-extra "^9.1.0"
semver "^5.4.1"

ember-destroyable-polyfill@^2.0.1, ember-destroyable-polyfill@^2.0.3:
ember-destroyable-polyfill@^2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/ember-destroyable-polyfill/-/ember-destroyable-polyfill-2.0.3.tgz#1673ed66609a82268ef270a7d917ebd3647f11e1"
integrity sha512-TovtNqCumzyAiW0/OisSkkVK93xnVF4NRU6+FN0ubpfwEOpRrmM2RqDwXI6YAChCgSHON1cz0DfQStpA1Gjuuw==
Expand Down

0 comments on commit 2590a2f

Please sign in to comment.