Skip to content

Commit

Permalink
fix: support legacy TS configurations (#5)
Browse files Browse the repository at this point in the history
* fix: support legacy TS setups
* chore: version bump
* docs: update with new examples
  • Loading branch information
jlp-craigmorten committed Jun 27, 2024
1 parent 5f3dbda commit c450586
Show file tree
Hide file tree
Showing 31 changed files with 3,408 additions and 122 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
"prettier",
],
rules: { "sort-imports": ["error", { ignoreCase: true }] },
ignorePatterns: ["lib"]
};
22 changes: 16 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ jobs:
node-version: 18
- run: yarn install --frozen-lockfile
- run: yarn ci
# TypeScript Example
# TypeScript NodeNext Example
- run: yarn install --frozen-lockfile
working-directory: ./examples/typescript
working-directory: ./examples/typescript-nodenext
- run: yarn test
working-directory: ./examples/typescript
working-directory: ./examples/typescript-nodenext
# TypeScript Legacy Example
- run: yarn install --frozen-lockfile
working-directory: ./examples/typescript-legacy
- run: yarn test
working-directory: ./examples/typescript-legacy

test-node-20:
runs-on: ubuntu-latest
Expand All @@ -31,8 +36,13 @@ jobs:
node-version: 20
- run: yarn install --frozen-lockfile
- run: yarn ci
# TypeScript Example
# TypeScript NodeNext Example
- run: yarn install --frozen-lockfile
working-directory: ./examples/typescript-nodenext
- run: yarn test
working-directory: ./examples/typescript-nodenext
# TypeScript Legacy Example
- run: yarn install --frozen-lockfile
working-directory: ./examples/typescript
working-directory: ./examples/typescript-legacy
- run: yarn test
working-directory: ./examples/typescript
working-directory: ./examples/typescript-legacy
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
7 changes: 4 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This directory contains a series of self-contained examples that you can use as
starting points for your setup, or as snippets to pull into your existing
projects:

| Example | Description |
| -------------------------- | ------------------------------------------------------------------------- |
| [TypeScript](./typescript) | A basic TypeScript example using the Virtual Screen Reader Jest Matchers. |
| Example | Description |
| -------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| [TypeScript Legacy](./typescript-legacy) | A basic example where Virtual Screen Reader Jest Matchers is used for a legacy TypeScript CommonJS application. |
| [TypeScript NodeNext](./typescript-nodenext) | A basic example where Virtual Screen Reader Jest Matchers is used for a Node.js application or library. |
20 changes: 20 additions & 0 deletions examples/typescript-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# TypeScript Legacy Example

A basic example where Virtual Screen Reader Jest Matchers is used for a legacy TypeScript CommonJS application.

Run this example with:

```bash
# Install and build core package
yarn install --frozen-lockfile

# Navigate to example, install, and test
cd examples/typescript-legacy
yarn install --frozen-lockfile
yarn test
```

> [!IMPORTANT]
> This example serves to demonstrate how you can use the Virtual Screen Reader Jest Matchers. The components themselves may not be using best accessibility practices.
>
> Always evaluate your own components for accessibility and test with real users.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable-next-line no-undef
module.exports = {
preset: "ts-jest",
resolver: "ts-jest-resolver",
testEnvironment: "jsdom",
roots: ["src"],
collectCoverageFrom: ["**/*.ts"],
Expand Down
5 changes: 5 additions & 0 deletions examples/typescript-legacy/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "../../lib/cjs/index.js";
// In your code, replace with:
// import "@guidepup/jest";

jest.setTimeout(10000);
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@guidepup/jest-typescript-example",
"name": "@guidepup/jest-typescript-legacy-example",
"version": "1.0.0",
"description": "Virtual Screen Reader Jest Matchers TypeScript Example",
"author": "Craig Morten <craig.morten@hotmail.co.uk>",
"license": "MIT",
"private": true,
"scripts": {
"test": "jest",
"test:coverage": "yarn test --coverage"
"preinstall": "yarn --cwd=../.. build",
"test": "jest"
},
"devDependencies": {
"@guidepup/jest": "file:../../",
"@guidepup/virtual-screen-reader": "^0.25.0",
"@guidepup/virtual-screen-reader": "^0.26.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.8",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.5",
"ts-jest-resolver": "^2.0.1",
"typescript": "^5.5.2"
}
}
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions examples/typescript-legacy/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"strict": true
},
"include": ["src/**/*", "jest.setup.ts"],
"exclude": ["node_modules"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,10 @@
semver "^7.3.8"
shelljs "^0.8.5"

"@guidepup/jest@file:../..":
version "0.4.0"
dependencies:
jest-snapshot "^29.7.0"

"@guidepup/virtual-screen-reader@^0.25.0":
version "0.25.0"
resolved "https://registry.yarnpkg.com/@guidepup/virtual-screen-reader/-/virtual-screen-reader-0.25.0.tgz#44de40a1133f1d74179cd5284ceefafac35dbed7"
integrity sha512-EhBUhzak+r8hhlBJQEwaoPfH3PsTdYGGXZ7wr1IM+/2PxKurE4Gokmx3jJc2PckWdAdEtGDxqaIlSLrVi4fNzA==
"@guidepup/virtual-screen-reader@^0.26.0":
version "0.26.0"
resolved "https://registry.yarnpkg.com/@guidepup/virtual-screen-reader/-/virtual-screen-reader-0.26.0.tgz#377f1e39fe11b54e75302e9a6c0f80586d9f5ff0"
integrity sha512-Q9RgFrIWPALW2s7DMVD6XsEGDZDw9kLSTIhvA9TXqjfK/RsTnJ1L3u/7+zBHPhy9eRCWTMP9SnDV2VZ8dvNzmA==
dependencies:
"@guidepup/guidepup" "^0.22.3"
"@testing-library/dom" "^10.2.0"
Expand Down Expand Up @@ -1806,7 +1801,7 @@ jest-resolve-dependencies@^29.7.0:
jest-regex-util "^29.6.3"
jest-snapshot "^29.7.0"

jest-resolve@^29.7.0:
jest-resolve@^29.5.0, jest-resolve@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-29.7.0.tgz#64d6a8992dd26f635ab0c01e5eef4399c6bcbc30"
integrity sha512-IOVhZSrg+UvVAshDSDtHyFCCBUl/Q3AAJv8iZ6ZjnZ74xzvwuzLXid9IIIPgTnY62SJjfuupMKZsZQRsCvxEgA==
Expand Down Expand Up @@ -2620,6 +2615,13 @@ tr46@^3.0.0:
dependencies:
punycode "^2.1.1"

ts-jest-resolver@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/ts-jest-resolver/-/ts-jest-resolver-2.0.1.tgz#4a1563cb10967e17eaae04157b0ba34e24d1c247"
integrity sha512-FolE73BqVZCs8/RbLKxC67iaAtKpBWx7PeLKFW2zJQlOf9j851I7JRxSDenri2NFvVH3QP7v3S8q1AmL24Zb9Q==
dependencies:
jest-resolve "^29.5.0"

ts-jest@^29.1.5:
version "29.1.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.5.tgz#d6c0471cc78bffa2cb4664a0a6741ef36cfe8f69"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TypeScript Example
# TypeScript NodeNext Example

A basic TypeScript example using the Virtual Screen Reader Jest Matchers.
A basic example where Virtual Screen Reader Jest Matchers is used for a Node.js application or library.

Run this example with:

Expand All @@ -9,7 +9,7 @@ Run this example with:
yarn install --frozen-lockfile

# Navigate to example, install, and test
cd examples/typescript
cd examples/typescript-nodenext
yarn install --frozen-lockfile
yarn test
```
Expand Down
18 changes: 18 additions & 0 deletions examples/typescript-nodenext/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// eslint-disable-next-line no-undef
module.exports = {
preset: "ts-jest",
resolver: "ts-jest-resolver",
testEnvironment: "jsdom",
roots: ["src"],
collectCoverageFrom: ["**/*.ts"],
coveragePathIgnorePatterns: [],
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
};
5 changes: 5 additions & 0 deletions examples/typescript-nodenext/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import "../../lib/cjs/index.js";
// In your code, replace with:
// import "@guidepup/jest";

jest.setTimeout(10000);
22 changes: 22 additions & 0 deletions examples/typescript-nodenext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@guidepup/jest-typescript-nodenext-example",
"version": "1.0.0",
"author": "Craig Morten <craig.morten@hotmail.co.uk>",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"preinstall": "yarn --cwd=../.. build",
"test": "jest"
},
"devDependencies": {
"@guidepup/virtual-screen-reader": "^0.26.0",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.8",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"ts-jest": "^29.1.5",
"ts-jest-resolver": "^2.0.1",
"typescript": "^5.5.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matchers snapshot matchers handles parallel assertions: toMatchScreenReaderSnapshot 1`] = `
[
"region",
"heading, Second Section Heading, level 1",
"paragraph",
"Second Section Text",
"end of paragraph",
"end of region",
]
`;

exports[`matchers toMatchScreenReaderSnapshot on a hidden node: toMatchScreenReaderSnapshot 1`] = `[]`;

exports[`matchers toMatchScreenReaderSnapshot on a null node: toMatchScreenReaderSnapshot 1`] = `[]`;

exports[`matchers toMatchScreenReaderSnapshot on a text node: toMatchScreenReaderSnapshot 1`] = `
[
"Nav Text",
]
`;

exports[`matchers toMatchScreenReaderSnapshot on an element: toMatchScreenReaderSnapshot 1`] = `
[
"region",
"heading, Second Section Heading, level 1",
"paragraph",
"Second Section Text",
"end of paragraph",
"end of region",
]
`;

exports[`matchers toMatchScreenReaderSnapshot on the whole body: toMatchScreenReaderSnapshot 1`] = `
[
"document",
"navigation",
"Nav Text",
"end of navigation",
"region",
"heading, First Section Heading, level 1",
"paragraph",
"First Section Text",
"end of paragraph",
"article",
"banner",
"heading, Article Header Heading, level 1",
"paragraph",
"Article Header Text",
"end of paragraph",
"end of banner",
"paragraph",
"Article Text",
"end of paragraph",
"end of article",
"end of region",
"region",
"heading, Second Section Heading, level 1",
"paragraph",
"Second Section Text",
"end of paragraph",
"end of region",
"contentinfo",
"Footer",
"end of contentinfo",
"end of document",
]
`;
47 changes: 47 additions & 0 deletions examples/typescript-nodenext/src/__snapshots__/mix.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`matchers snapshot tests toMatchScreenReaderSnapshot on the whole body: toMatchScreenReaderSnapshot 1`] = `
[
"document",
"navigation",
"Nav Text",
"end of navigation",
"region",
"heading, First Section Heading, level 1",
"paragraph",
"First Section Text",
"end of paragraph",
"article",
"banner",
"heading, Article Header Heading, level 1",
"paragraph",
"Article Header Text",
"end of paragraph",
"end of banner",
"paragraph",
"Article Text",
"end of paragraph",
"end of article",
"end of region",
"region",
"heading, Second Section Heading, level 1",
"paragraph",
"Second Section Text",
"end of paragraph",
"end of region",
"contentinfo",
"Footer",
"end of contentinfo",
"end of document",
]
`;

exports[`matchers virtual screen reader tests navigating headings 1`] = `
[
"document",
"heading, First Section Heading, level 1",
"heading, Article Header Heading, level 1",
"heading, Second Section Heading, level 1",
"heading, First Section Heading, level 1",
]
`;
Loading

0 comments on commit c450586

Please sign in to comment.