diff --git a/CHANGELOG.md b/CHANGELOG.md index d8e3a8b3..3ea6fbdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + + +### Bug Fixes + +* proper imports in esm context ([#718](https://github.com/dequelabs/axe-core-npm/issues/718)) ([f2a41bc](https://github.com/dequelabs/axe-core-npm/commit/f2a41bcaf33f5000fa1cd08f1a3e184b5d6360be)) +* **react:** include .mjs file in publish ([#722](https://github.com/dequelabs/axe-core-npm/issues/722)) ([a7bf92f](https://github.com/dequelabs/axe-core-npm/commit/a7bf92fd9856b7be0fea4f3c8bd38a79a3c9fde3)) + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/lerna.json b/lerna.json index f158afc0..84fed617 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ "packages/webdriverjs/tests/example", "axe_core_test" ], - "version": "4.7.0" + "version": "4.7.1" } diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 9a7c2af8..4920530e 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + +**Note:** Version bump only for package @axe-core/cli + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index 43d55e0a..7ec4b5ea 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -1,15 +1,15 @@ { "name": "@axe-core/cli", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/cli", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { - "@axe-core/webdriverjs": "^4.7.0", + "@axe-core/webdriverjs": "^4.7.1", "axe-core": "^4.7.0", "chromedriver": "^112.0.0", "colors": "^1.4.0", diff --git a/packages/cli/package.json b/packages/cli/package.json index 8b548d33..80746899 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/cli", - "version": "4.7.0", + "version": "4.7.1", "description": "A CLI for accessibility testing using axe-core", "author": { "name": "Wilco Fiers", @@ -53,7 +53,7 @@ "testing" ], "dependencies": { - "@axe-core/webdriverjs": "^4.7.0", + "@axe-core/webdriverjs": "^4.7.1", "axe-core": "^4.7.0", "chromedriver": "^112.0.0", "colors": "^1.4.0", diff --git a/packages/playwright/CHANGELOG.md b/packages/playwright/CHANGELOG.md index 009748f0..b9be6eb0 100644 --- a/packages/playwright/CHANGELOG.md +++ b/packages/playwright/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + +**Note:** Version bump only for package @axe-core/playwright + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/playwright/package-lock.json b/packages/playwright/package-lock.json index 4226eda4..72de7397 100644 --- a/packages/playwright/package-lock.json +++ b/packages/playwright/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/playwright", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/playwright", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { "axe-core": "^4.7.0" diff --git a/packages/playwright/package.json b/packages/playwright/package.json index e305f8db..19835c94 100644 --- a/packages/playwright/package.json +++ b/packages/playwright/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/playwright", - "version": "4.7.0", + "version": "4.7.1", "description": "Provides a method to inject and analyze web pages using axe", "contributors": [ { diff --git a/packages/puppeteer/CHANGELOG.md b/packages/puppeteer/CHANGELOG.md index 25e204c5..2bf093a4 100644 --- a/packages/puppeteer/CHANGELOG.md +++ b/packages/puppeteer/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + + +### Bug Fixes + +* proper imports in esm context ([#718](https://github.com/dequelabs/axe-core-npm/issues/718)) ([f2a41bc](https://github.com/dequelabs/axe-core-npm/commit/f2a41bcaf33f5000fa1cd08f1a3e184b5d6360be)) + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/puppeteer/esmTest.mjs b/packages/puppeteer/esmTest.mjs index e87f8065..05cbe935 100644 --- a/packages/puppeteer/esmTest.mjs +++ b/packages/puppeteer/esmTest.mjs @@ -1,7 +1,34 @@ import defaultExport, { AxePuppeteer } from './dist/index.mjs'; import assert from 'assert'; +import puppeteer from 'puppeteer'; +import { fileURLToPath, pathToFileURL } from 'url'; +import { join } from 'path'; const exportIsFunction = typeof(defaultExport) === 'function'; const exportIsSame = defaultExport === AxePuppeteer; assert(exportIsFunction, 'export is not a function'); assert(exportIsSame, 'default and named export is not the same'); + + +const options = {}; + +if (process.env.CI) { + options.args = []; + options.args.push('--no-sandbox', '--disable-setuid-sandbox'); + options.executablePath = '/usr/bin/google-chrome-stable'; +} + +async function integrationTest() { + let path = fileURLToPath(new URL('.', import.meta.url)); + path = join(path, './node_modules/axe-test-fixtures/fixtures/index.html'); + + const browser = await puppeteer.launch(options); + const page = await browser.newPage(); + await page.setBypassCSP(true); + await page.goto(pathToFileURL(path)); + const results = await new AxePuppeteer(page).analyze(); + assert(results.violations.length > 0, 'could not find violations'); + await page.close(); + await browser.close(); +} +integrationTest(); diff --git a/packages/puppeteer/package-lock.json b/packages/puppeteer/package-lock.json index 5fc4c250..1a6c6a2d 100644 --- a/packages/puppeteer/package-lock.json +++ b/packages/puppeteer/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/puppeteer", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/puppeteer", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { "axe-core": "^4.7.0" @@ -20,6 +20,7 @@ "@types/test-listen": "^1.1.0", "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "chai": "^4.3.6", + "cross-dirname": "^0.1.0", "express": "^4.18.2", "mocha": "^10.0.0", "nyc": "^15.1.0", @@ -1902,6 +1903,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-dirname": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cross-dirname/-/cross-dirname-0.1.0.tgz", + "integrity": "sha512-+R08/oI0nl3vfPcqftZRpytksBXDzOUveBq/NBVx0sUp1axwzPQrKinNx5yd5sxPu8j1wIy8AfnVQ+5eFdha6Q==", + "dev": true + }, "node_modules/cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", @@ -6728,6 +6735,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-dirname": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cross-dirname/-/cross-dirname-0.1.0.tgz", + "integrity": "sha512-+R08/oI0nl3vfPcqftZRpytksBXDzOUveBq/NBVx0sUp1axwzPQrKinNx5yd5sxPu8j1wIy8AfnVQ+5eFdha6Q==", + "dev": true + }, "cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", diff --git a/packages/puppeteer/package.json b/packages/puppeteer/package.json index 4eab0d06..ac624cce 100644 --- a/packages/puppeteer/package.json +++ b/packages/puppeteer/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/puppeteer", - "version": "4.7.0", + "version": "4.7.1", "description": "Provides a chainable axe API for Puppeteer and automatically injects into all frames", "repository": { "type": "git", @@ -40,6 +40,7 @@ "@types/test-listen": "^1.1.0", "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "chai": "^4.3.6", + "cross-dirname": "^0.1.0", "express": "^4.18.2", "mocha": "^10.0.0", "nyc": "^15.1.0", diff --git a/packages/puppeteer/src/legacy.ts b/packages/puppeteer/src/legacy.ts index f333bbe8..5b8aa9fe 100644 --- a/packages/puppeteer/src/legacy.ts +++ b/packages/puppeteer/src/legacy.ts @@ -1,5 +1,7 @@ import * as fs from 'fs'; import { Frame } from 'puppeteer'; +import { getFilename } from 'cross-dirname'; +import { pathToFileURL } from 'url'; interface IInjectAxeArgs { source?: string | Function; @@ -52,7 +54,19 @@ export async function injectJS( } async function injectJSModule(frame: Frame): Promise { - const source = fs.readFileSync(require.resolve('axe-core'), 'utf8'); + let axeCorePath = ''; + if (typeof require === 'function' && typeof require.resolve === 'function') { + axeCorePath = require.resolve('axe-core'); + } else { + const { createRequire } = (await import('node:module')) as any; + // `getFilename` is needed because esm's `import.meta.url` is illegal syntax in cjs + const filename = pathToFileURL(getFilename()).toString(); + + const require = createRequire(filename); + axeCorePath = require.resolve('axe-core'); + } + + const source = fs.readFileSync(axeCorePath, 'utf8'); await injectJSSource(frame, source); } diff --git a/packages/puppeteer/src/utils.ts b/packages/puppeteer/src/utils.ts index 1e2f766b..0434ace3 100644 --- a/packages/puppeteer/src/utils.ts +++ b/packages/puppeteer/src/utils.ts @@ -2,6 +2,8 @@ import * as fs from 'fs'; import * as Axe from 'axe-core'; import { Frame } from 'puppeteer'; import { axeConfigure, axeShadowSelect } from './browser'; +import { getFilename } from 'cross-dirname'; +import { pathToFileURL } from 'url'; import { pageIsLoaded } from './browser'; export async function frameSourceInject( @@ -11,8 +13,22 @@ export async function frameSourceInject( ): Promise { await assertFrameReady(frame); if (!source) { - const pathFile = require.resolve('axe-core'); - source = fs.readFileSync(pathFile, 'utf8'); + let axeCorePath = ''; + if ( + typeof require === 'function' && + typeof require.resolve === 'function' + ) { + axeCorePath = require.resolve('axe-core'); + } else { + const { createRequire } = (await import('node:module')) as any; + // `getFilename` is needed because esm's `import.meta.url` is illegal syntax in cjs + const filename = pathToFileURL(getFilename()).toString(); + + const require = createRequire(filename); + axeCorePath = require.resolve('axe-core'); + } + + source = fs.readFileSync(axeCorePath, 'utf8'); } await frame.evaluate(source); await frame.evaluate(axeConfigure, config as Axe.Spec); diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 853b2de1..4c0c4b8d 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + + +### Bug Fixes + +* **react:** include .mjs file in publish ([#722](https://github.com/dequelabs/axe-core-npm/issues/722)) ([a7bf92f](https://github.com/dequelabs/axe-core-npm/commit/a7bf92fd9856b7be0fea4f3c8bd38a79a3c9fde3)) + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/react/examples/shadow-dom/CHANGELOG.md b/packages/react/examples/shadow-dom/CHANGELOG.md index 14e49082..9d7454fc 100644 --- a/packages/react/examples/shadow-dom/CHANGELOG.md +++ b/packages/react/examples/shadow-dom/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + +**Note:** Version bump only for package @axe-core/react-example + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) **Note:** Version bump only for package @axe-core/react-example diff --git a/packages/react/examples/shadow-dom/package-lock.json b/packages/react/examples/shadow-dom/package-lock.json index bf3c967c..b5e5afe0 100644 --- a/packages/react/examples/shadow-dom/package-lock.json +++ b/packages/react/examples/shadow-dom/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/react-example", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/react-example", - "version": "4.7.0", + "version": "4.7.1", "license": "MIT", "dependencies": { "create-react-class": "^15.6.3", diff --git a/packages/react/examples/shadow-dom/package.json b/packages/react/examples/shadow-dom/package.json index 3d0b9946..521f70a3 100644 --- a/packages/react/examples/shadow-dom/package.json +++ b/packages/react/examples/shadow-dom/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/react-example", - "version": "4.7.0", + "version": "4.7.1", "description": "Example of react-axe with a React.js application", "main": "index.js", "private": true, @@ -13,7 +13,7 @@ "author": "Dylan Barrell (dylan@barrell.com)", "license": "MIT", "dependencies": { - "@axe-core/react": "^4.7.0", + "@axe-core/react": "^4.7.1", "create-react-class": "^15.6.3", "react": "^16.8.6", "react-dom": "^16.8.6", diff --git a/packages/react/package-lock.json b/packages/react/package-lock.json index bb5926b4..3c42a4fc 100644 --- a/packages/react/package-lock.json +++ b/packages/react/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/react", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/react", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { "axe-core": "^4.7.0", diff --git a/packages/react/package.json b/packages/react/package.json index fe8266a0..6848af60 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/react", - "version": "4.7.0", + "version": "4.7.1", "description": "Dynamic accessibility analysis for React using axe-core", "main": "./dist/index.js", "module": "./dist/index.mjs", @@ -20,6 +20,7 @@ "dist/cache.d.ts", "dist/cache.js.map", "dist/index.js", + "dist/index.mjs", "dist/index.d.ts", "dist/index.js.map" ], diff --git a/packages/reporter-earl/CHANGELOG.md b/packages/reporter-earl/CHANGELOG.md index c6da7215..c090358f 100644 --- a/packages/reporter-earl/CHANGELOG.md +++ b/packages/reporter-earl/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + +**Note:** Version bump only for package @axe-core/reporter-earl + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/reporter-earl/package-lock.json b/packages/reporter-earl/package-lock.json index 3d28df11..cf0e9db6 100644 --- a/packages/reporter-earl/package-lock.json +++ b/packages/reporter-earl/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/reporter-earl", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/reporter-earl", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "devDependencies": { "@types/clone": "^2.1.1", diff --git a/packages/reporter-earl/package.json b/packages/reporter-earl/package.json index 15f09eea..f6987f20 100644 --- a/packages/reporter-earl/package.json +++ b/packages/reporter-earl/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/reporter-earl", - "version": "4.7.0", + "version": "4.7.1", "description": "A EARL+JSON-LD reporter for axe-core", "main": "dist/axeReporterEarl.js", "module": "./dist/axeReporterEarl.mjs", diff --git a/packages/webdriverio/CHANGELOG.md b/packages/webdriverio/CHANGELOG.md index d6cf4b04..fcc4694e 100644 --- a/packages/webdriverio/CHANGELOG.md +++ b/packages/webdriverio/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + + +### Bug Fixes + +* proper imports in esm context ([#718](https://github.com/dequelabs/axe-core-npm/issues/718)) ([f2a41bc](https://github.com/dequelabs/axe-core-npm/commit/f2a41bcaf33f5000fa1cd08f1a3e184b5d6360be)) + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/webdriverio/esmTest.mjs b/packages/webdriverio/esmTest.mjs index 88773e6d..9921a2d7 100644 --- a/packages/webdriverio/esmTest.mjs +++ b/packages/webdriverio/esmTest.mjs @@ -1,5 +1,33 @@ import defaultExport from './dist/index.mjs'; import assert from 'assert'; +import * as webdriverio from 'webdriverio'; +import { fileURLToPath, pathToFileURL } from 'url'; +import { join } from 'path'; const exportIsFunction = typeof(defaultExport) === 'function'; assert(exportIsFunction, 'export is not a function'); + + +async function integrationTest() { + let path = fileURLToPath(new URL('.', import.meta.url)); + path = join(path, './node_modules/axe-test-fixtures/fixtures/index.html'); + + const options = { + automationProtocol: 'devtools', + path: '/', + capabilities: { + browserName: 'chrome', + 'goog:chromeOptions': { + args: ['--headless'] + } + }, + logLevel: 'error' + }; + const client = await webdriverio.remote( options ); + await client.url(pathToFileURL(path).toString()); + + const results = await new defaultExport({ client }).analyze(); + assert(results.violations.length > 0, 'could not find violations'); + process.exit(0); +} +integrationTest() diff --git a/packages/webdriverio/package-lock.json b/packages/webdriverio/package-lock.json index a92cf0cf..89f39df4 100644 --- a/packages/webdriverio/package-lock.json +++ b/packages/webdriverio/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/webdriverio", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/webdriverio", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { "axe-core": "^4.7.0", @@ -23,6 +23,7 @@ "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "chai": "^4.3.6", "chromedriver": "^112.0.0", + "cross-dirname": "^0.1.0", "delay": "^5.0.0", "express": "^4.18.2", "mocha": "^10.0.0", @@ -2337,6 +2338,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-dirname": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cross-dirname/-/cross-dirname-0.1.0.tgz", + "integrity": "sha512-+R08/oI0nl3vfPcqftZRpytksBXDzOUveBq/NBVx0sUp1axwzPQrKinNx5yd5sxPu8j1wIy8AfnVQ+5eFdha6Q==", + "dev": true + }, "node_modules/cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", @@ -8487,6 +8494,12 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "cross-dirname": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cross-dirname/-/cross-dirname-0.1.0.tgz", + "integrity": "sha512-+R08/oI0nl3vfPcqftZRpytksBXDzOUveBq/NBVx0sUp1axwzPQrKinNx5yd5sxPu8j1wIy8AfnVQ+5eFdha6Q==", + "dev": true + }, "cross-fetch": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", diff --git a/packages/webdriverio/package.json b/packages/webdriverio/package.json index 9b74ad92..75f74fb0 100644 --- a/packages/webdriverio/package.json +++ b/packages/webdriverio/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/webdriverio", - "version": "4.7.0", + "version": "4.7.1", "description": "Provides a method to inject and analyze web pages using axe", "contributors": [ { @@ -59,6 +59,7 @@ "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "chai": "^4.3.6", "chromedriver": "^112.0.0", + "cross-dirname": "^0.1.0", "delay": "^5.0.0", "express": "^4.18.2", "mocha": "^10.0.0", diff --git a/packages/webdriverio/src/index.ts b/packages/webdriverio/src/index.ts index 1f3efcd0..4a7bcb8f 100644 --- a/packages/webdriverio/src/index.ts +++ b/packages/webdriverio/src/index.ts @@ -12,6 +12,8 @@ import { axeRunLegacy, configureAllowedOrigins } from './utils'; +import { getFilename } from 'cross-dirname'; +import { pathToFileURL } from 'url'; import type { Browser, Element } from 'webdriverio'; import type { @@ -23,6 +25,21 @@ import type { } from 'axe-core'; import type { Options, CallbackFunction, PartialResults } from './types'; +let axeCorePath = ''; +async function loadAxePath() { + if (typeof require === 'function' && typeof require.resolve === 'function') { + axeCorePath = require.resolve('axe-core'); + } else { + const { createRequire } = (await import('node:module')) as any; + // `getFilename` is needed because esm's `import.meta.url` is illegal syntax in cjs + const filename = pathToFileURL(getFilename()).toString(); + + const require = createRequire(filename); + axeCorePath = require.resolve('axe-core'); + } +} +loadAxePath(); + export default class AxeBuilder { private client: Browser; private axeSource: string; @@ -46,9 +63,8 @@ export default class AxeBuilder { if (axeSource) { this.axeSource = axeSource; } else { - const sourceDir = require.resolve('axe-core'); try { - this.axeSource = fs.readFileSync(sourceDir, 'utf-8'); + this.axeSource = fs.readFileSync(axeCorePath, 'utf-8'); } catch (e) { throw new Error( 'Unable to find axe-core source. Is axe-core installed?' diff --git a/packages/webdriverio/tsconfig.json b/packages/webdriverio/tsconfig.json index 51dc1ed5..ad1389bd 100644 --- a/packages/webdriverio/tsconfig.json +++ b/packages/webdriverio/tsconfig.json @@ -3,7 +3,7 @@ "moduleResolution": "node", "target": "esnext", "module": "esnext", - "lib": ["es2015", "es2016", "esnext", "dom"], + "lib": ["esnext", "dom"], "strict": true, "pretty": true, "sourceMap": true, diff --git a/packages/webdriverjs/CHANGELOG.md b/packages/webdriverjs/CHANGELOG.md index 609487b2..e19ce358 100644 --- a/packages/webdriverjs/CHANGELOG.md +++ b/packages/webdriverjs/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [4.7.1](https://github.com/dequelabs/axe-core-npm/compare/v4.7.0...v4.7.1) (2023-05-02) + +**Note:** Version bump only for package @axe-core/webdriverjs + + + + + # [4.7.0](https://github.com/dequelabs/axe-core-npm/compare/v4.6.1...v4.7.0) (2023-04-28) diff --git a/packages/webdriverjs/package-lock.json b/packages/webdriverjs/package-lock.json index 321d811c..aff892be 100644 --- a/packages/webdriverjs/package-lock.json +++ b/packages/webdriverjs/package-lock.json @@ -1,12 +1,12 @@ { "name": "@axe-core/webdriverjs", - "version": "4.7.0", + "version": "4.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@axe-core/webdriverjs", - "version": "4.7.0", + "version": "4.7.1", "license": "MPL-2.0", "dependencies": { "axe-core": "^4.7.0" diff --git a/packages/webdriverjs/package.json b/packages/webdriverjs/package.json index 40aa07a8..ac27a45d 100644 --- a/packages/webdriverjs/package.json +++ b/packages/webdriverjs/package.json @@ -1,6 +1,6 @@ { "name": "@axe-core/webdriverjs", - "version": "4.7.0", + "version": "4.7.1", "description": "Provides a method to inject and analyze web pages using axe", "contributors": [ {