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

fix: support ESM #56

Merged
merged 9 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
"prettier",
],
plugins: ["require-extensions", "@typescript-eslint"],
ignorePatterns: ["examples"],
rules: {
"sort-imports": ["error", { ignoreCase: true }],
quotes: ["error", "double", { avoidEscape: true }],
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ jobs:
working-directory: ./examples/vue
- run: yarn test
working-directory: ./examples/vue

test-web-test-runner-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- run: yarn install --frozen-lockfile
- run: yarn install --frozen-lockfile
working-directory: ./examples/web-test-runner
- run: yarn test
working-directory: ./examples/web-test-runner
1 change: 1 addition & 0 deletions examples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"pretest": "yarn --cwd=../.. build",
"test": "vitest run",
"test:watch": "vitest",
"type-check": "vue-tsc --build --force",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/src/__tests__/IncrementCounter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import IncrementCounter from '../IncrementCounter.vue'
*
* in your own code.
*/
import { virtual } from '../../../../src'
import { virtual } from '../../../../lib/cjs'

describe('Increment Counter', () => {
afterEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/src/__tests__/OpenModal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ModalExample from '../OpenModal.vue'
*
* in your own code.
*/
import { virtual } from '../../../../src'
import { virtual } from '../../../../lib/cjs'

describe('Open Modal', () => {
afterEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/src/__tests__/TextAreaCounter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TextareaCounter from '../TextAreaCounter.vue'
*
* in your own code.
*/
import { virtual } from '../../../../src'
import { virtual } from '../../../../lib/cjs'

describe('Text Area Counter', () => {
afterEach(async () => {
Expand Down
21 changes: 21 additions & 0 deletions examples/web-test-runner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@guidepup/virtual-screen-reader-web-test-runner-example",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"pretest": "yarn --cwd=../.. build",
"test": "web-test-runner \"test/**/*.test.js\"",
"test:watch": "yarn test --watch"
},
"dependencies": {},
"devDependencies": {
"@esm-bundle/chai": "4.3.4",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-replace": "^5.0.5",
"@web/dev-server-rollup": "^0.6.1",
"@web/test-runner": "^0.18.0",
"aria-query-esm": "^5.3.0-fix.1"
}
}
33 changes: 33 additions & 0 deletions examples/web-test-runner/test/virtual.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect } from "@esm-bundle/chai";

/**
* Replace with:
*
* import { virtual } from '@guidepup/virtual-screen-reader'
*
* in your own code.
*/
import { virtual } from "../../../lib/esm/index.js";

beforeEach(async () => {
document.body.innerHTML = "<h1>Heading</h1><p>Paragraph text</p>";

await virtual.start({ container: document.body });
});

afterEach(async () => {
await virtual.stop();

document.body.innerHTML = "";
});

it("renders a heading and a paragraph", async () => {
await virtual.next();
await virtual.next();

expect(await virtual.spokenPhraseLog()).to.eql([
"heading, Heading, level 1",
"paragraph",
"Paragraph text",
]);
});
41 changes: 41 additions & 0 deletions examples/web-test-runner/web-test-runner.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from "path";
import { fileURLToPath } from "url";
import _alias from "@rollup/plugin-alias";
import _commonjs from "@rollup/plugin-commonjs";
import _replace from "@rollup/plugin-replace";
import { fromRollup } from "@web/dev-server-rollup";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const alias = fromRollup(_alias);
const commonjs = fromRollup(_commonjs);
const replace = fromRollup(_replace);

export default {
nodeResolve: true,
plugins: [
alias({
entries: [
{
find: "aria-query",
replacement: path.resolve(
__dirname,
"node_modules/aria-query-esm/lib/esm/index.js"
),
},
],
}),
replace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
commonjs({
include: [
"**/node_modules/@testing-library/**",
"**/node_modules/lz-string/**",
"**/node_modules/ansi-regex/**",
],
}),
],
};
Loading
Loading