Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): add jest accessibility matcher #9

Merged
merged 61 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d9f0b26
build(root): update repository urls in package json files
Apr 9, 2020
7a41187
test(rules,format): fix test names to follow convention
Apr 9, 2020
483291c
feat(jest): add basic scaffolding for jest integration
Apr 9, 2020
4eaaf65
build(root): fix lint:fix script
Apr 13, 2020
6630be3
build(jest): add jest as a peer dependency
Apr 14, 2020
a91a3e0
docs(root): add homepage fields in package json to point to readme
Apr 14, 2020
51ec35d
feat(jest): add scaffolding for jest expect matcher
Apr 14, 2020
e8055fa
improvement(jest): flesh out custom jest axe matcher
Apr 23, 2020
54be107
build(jest): add jest matcher utils dep
Apr 23, 2020
7609b7b
build(root): add npm update checker util
Apr 23, 2020
6c7e86d
build(root): update script to upgrade dependencies; upgrade dependencies
Apr 23, 2020
f8649b2
improvement(jest): use matcher hint util to format message
Apr 24, 2020
b5bee0f
build(root): check staged files before invoking commit process
Apr 24, 2020
c7184e4
test(jest): fix dom lang setup, test names, err msgs
Apr 27, 2020
1554fdf
build(root): add eslint watcher package and watch scripts
Apr 27, 2020
ecbfbf9
feat(jest): add toBeAccessibleWith jest a11y matcher for use with config
Apr 28, 2020
2a1c1bf
feat(test-utils): add a test utilities package
Apr 28, 2020
ba71b58
refactor(test-utils): refactor packages to use the common code
Apr 28, 2020
2481a06
build(root): add markdown link checker dep, scripts, config
Apr 29, 2020
37f5f8f
build(root): add eslint plugin to check code snippets in markdown files
Apr 29, 2020
28e628f
improvement(jest): fix return types on the matcher interface
Apr 29, 2020
3531458
build(root): upgrade to next version of eslint markdown plugin
Apr 29, 2020
3dbd29a
docs(root): add typescript tag to code blocks in docs
Apr 29, 2020
342f577
build(root): update dependencies
Apr 29, 2020
a88ef4d
build(root): add plugin to generate table of contents for markdown files
Apr 29, 2020
a832256
docs(root): update table of contents for all markdown docs
Apr 29, 2020
97677cb
build(root): add eslint plugins to check imports, comment directives
Apr 29, 2020
23d4c4c
improvement(root): fix conflicting settings for md files formatting
Apr 29, 2020
f54b9ac
improvement(root): add typescript resolver eslint import plugin
Apr 30, 2020
eafdc8c
chore(root): update dependencies
Apr 30, 2020
ca3d7a3
refactor(jest): rename jest module to matcher
Apr 30, 2020
618868c
improvement(root): fix project references in typescript configs
Apr 30, 2020
2546f72
refactor(jest): add util func to register a11y matchers
Apr 30, 2020
7466a6f
test(jest): add test for a11y matcher setup; fix import
Apr 30, 2020
9e56fb0
refactor(jest): move fix a11y config to be a func
Apr 30, 2020
e415437
refactor(jest): consolidate before test setup
Apr 30, 2020
e1e271a
improvement(jest): call fix config from the jest matcher
May 1, 2020
8ca12bf
improvement(jest): make fix a11y config immutable
May 1, 2020
c4a4b8a
build(root): fix missing deps, build clean script
May 1, 2020
4054e00
docs(root): add quick start section to contributing doc
May 1, 2020
4a16474
chore(root): bump versions of changed packages
May 1, 2020
8fc2fa6
build: add git pre push hook to build, test
May 1, 2020
9ad3ee0
fix(preset-rules): revert object freeze on a11y config object
May 1, 2020
6e3ee18
improvement: fix/silence lint warnings, improve docs
May 1, 2020
2f9f9b3
docs: add SPDX license ID at top of license file
May 1, 2020
dbc80f1
refactor(jest): rename fix a11y config func to adapt a11y config
May 4, 2020
349a426
test(jest): add test to check for error when expect is undefined
May 4, 2020
2b64f15
refactor(jest): remove toBeAccessibleWith a11y matcher
May 4, 2020
c77f356
ci: add pr title github action, change code cov github action
May 4, 2020
2b18c4b
improvement(jest): add config to automate setup of a11y matchers
May 4, 2020
56b4893
ci: add missing build step to new github actions
May 4, 2020
3889075
ci(github action): change pr title check to install only req deps
May 4, 2020
eca6850
refactor(jest): remove adaptA11yConfig from package level direct export
May 5, 2020
6eb2a3b
improvement(jest): add ability to check HTML elements for accessibility
May 5, 2020
85609d3
build(jest): fix main entry point in jest package.json
May 5, 2020
36b0087
build: add ts-cleaner to clean dist files
May 7, 2020
cbbe288
test(jest): add integration test package to test jest config setup
May 7, 2020
a6662f6
refactor(test-integration): rename test-integ to test-integration
May 7, 2020
e4c2717
docs: add/refactor docs
May 7, 2020
97249c9
docs: change code block types in docs from ts to js
May 7, 2020
9b1aa3b
test(jest): add doc/tests for checking html elem with jest
May 8, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions cSpell.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
{
"ignorePaths": ["node_modules/**", "package.json"],
"ignoreWords": [
"assertAccessible",
"doctoc",
"CNCF",
"SPDX", // license header
"tsdoc"
],
"ignoreWords": ["assertAccessible", "doctoc", "CNCF", "integ", "SPDX", "tsdoc"],
"ignoreRegExpList": ["ruleset"]
}
31 changes: 30 additions & 1 deletion packages/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,42 @@ Accessibility matcher for [Jest](https://jestjs.io)


- [Setup](#setup)
- [Automatic](#automatic)
- [Manual](#manual)
- [Usage](#usage)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Setup

- TODO: Based on https://github.com/jest-community/jest-extended#setup
The accessibility matcher helper APIs need to be registered with Jest before they can be used in tests.

### Automatic

Modify Jest config to add the required setup for accessibility matchers.

In the `jest.config.js` at the root of your project, add

```javascript
const { jestConfig } = require('@sa11y/jest');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trevor-bliss In 2b18c4b I am trying to automate setup of the a11y matchers so that they can be setup once in a project instead of every test module. But I am not able to get it to work. Can you please take a look at see what I am missing.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simplify the jest config in the integration test package and work backwards from a working solution.

In packages/test-integ/jest.config.js, can you have the setupFilesAfterEnv option directly that points to a local file that calls expect.extend to add a trivial custom matcher?

Once you have that then start using the imports/exports until you get back to where you wanted to be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, let me try that out - thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trevor-bliss Ran into some issues trying the config jest
I have opened an issue with info #11
If there are no other issues with this PR can we merge this while I continue working on the jest config? I can revert 2b18c4b from this PR and add it to another branch?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah works for me. Approved the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @trevor-bliss
Modified jest setup as per your suggestions in #11
Can you please review


module.exports = {
...jestConfig,
// Your config ..
};
```

### Manual

Invoke `registerA11yMatchers` before using the accessibility matchers in the tests.

```typescript
import { registerA11yMatchers } from '@sa11y/jest';

beforeAll(() => {
registerA11yMatchers();
});
```

## Usage

Expand Down
4 changes: 4 additions & 0 deletions packages/jest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@

export { toBeAccessible } from './matcher';
export { adaptA11yConfig, registerA11yMatchers } from './setup';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adaptA11yConfig something we need to give to consumers? It seems like this package could just always call it internally but there may be a use case I'm missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the tests are using it - so it needs to be exported I guess?
But I have been thinking about its usefulness to consumers as well.. Right now with its limited scope, its probably not useful. But if we allowed consumers to register their own adapters that could be useful. But there isn't a clear use case for such a workflow right now.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well setup.js can still export the function so the tests can directly import it to call, but if no one outside of this package is using it, you don't need to re-export it here in index.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it ! Fixed.


export const jestConfig = {
setupFilesAfterEnv: [require.resolve('./setup')],
};
3 changes: 3 additions & 0 deletions packages/jest/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ export function adaptA11yConfig(config: A11yConfig): A11yConfig {
},
};
}

// When this file is used as part of Jest setup with setupFilesAfterEnv
registerA11yMatchers();
11 changes: 11 additions & 0 deletions packages/test-integ/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [`test-integ`](#test-integ)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# `test-integ`

Private package for integration testing @sa11y packages
13 changes: 13 additions & 0 deletions packages/test-integ/__tests__/integration.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

describe('integration test @sa11y/jest', () => {
it.skip('should have a11y matchers working with setup in jest.config.js', () => {
// TODO(Fix) : Fails with TypeError: expect(...).toBeAccessible is not a function
expect(document).toBeAccessible();
});
});
13 changes: 13 additions & 0 deletions packages/test-integ/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { jestConfig } = require('@sa11y/jest');

module.exports = {
...jestConfig,
};
16 changes: 16 additions & 0 deletions packages/test-integ/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@sa11y/test-integ",
"version": "0.1.0",
"private": true,
"description": "Private package for integration testing @sa11y packages",
"license": "BSD-3-Clause",
"homepage": "https://github.com/salesforce/sa11y/tree/master/packages/test-integ#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/salesforce/sa11y.git",
"directory": "packages/test-integ"
},
"devDependencies": {
"@sa11y/jest": "0.1.0"
}
}
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"compilerOptions": { "strict": true },
"include": ["./packages/**/*.ts", "*.js"]
"include": ["*.js", "./packages/**/*.ts", "./packages/**/*.js"]
}