From 6b5dadaf676de361e05d43a9dbe4a015ea0ace7e Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Wed, 18 Oct 2023 14:52:10 -0600 Subject: [PATCH 1/2] refactor: use new test-fixtures path --- package-lock.json | 5 +- package.json | 2 +- .../playwright/test/axe-playwright.spec.ts | 111 ++++++----- .../playwright/test/fixtures/context.html | 13 -- packages/playwright/test/fixtures/external | 1 - packages/puppeteer/test/axe-puppeteer.spec.ts | 110 +++++------ packages/puppeteer/test/fixtures/context.html | 11 -- packages/puppeteer/test/fixtures/external | 1 - packages/puppeteer/test/utils.ts | 4 +- packages/webdriverio/fixtures/external | 1 - .../webdriverio/test/axe-webdriverio.spec.ts | 17 +- .../webdriverjs/test/axe-webdriverjs.spec.ts | 175 +++++++++--------- .../webdriverjs/test/fixtures/context.html | 15 -- packages/webdriverjs/test/fixtures/external | 1 - .../webdriverjs/test/fixtures/iframe-one.html | 14 -- 15 files changed, 213 insertions(+), 268 deletions(-) delete mode 100644 packages/playwright/test/fixtures/context.html delete mode 120000 packages/playwright/test/fixtures/external delete mode 100644 packages/puppeteer/test/fixtures/context.html delete mode 120000 packages/puppeteer/test/fixtures/external delete mode 120000 packages/webdriverio/fixtures/external delete mode 100644 packages/webdriverjs/test/fixtures/context.html delete mode 120000 packages/webdriverjs/test/fixtures/external delete mode 100644 packages/webdriverjs/test/fixtures/iframe-one.html diff --git a/package-lock.json b/package-lock.json index 9d003f92..3791cebc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,12 +11,12 @@ "test/axe-core" ], "dependencies": { - "axe-test-fixtures": "github:dequelabs/axe-test-fixtures", "browser-driver-manager": "^1.0.4" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.40.0", "@typescript-eslint/parser": "^5.40.0", + "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "eslint": "^8.25.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-react": "^7.31.9", @@ -6401,7 +6401,8 @@ }, "node_modules/axe-test-fixtures": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/dequelabs/axe-test-fixtures.git#3efe1a953a65924cf6dc5195344dbf246ebf4e4c", + "resolved": "git+ssh://git@github.com/dequelabs/axe-test-fixtures.git#72ec3ffa7d0a91d0ca489fdab3961d7c199ba586", + "dev": true, "license": "MPL-2.0" }, "node_modules/axios": { diff --git a/package.json b/package.json index 41b4e89a..bff82d7b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "^5.40.0", "@typescript-eslint/parser": "^5.40.0", + "axe-test-fixtures": "github:dequelabs/axe-test-fixtures#v1", "eslint": "^8.25.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-react": "^7.31.9", @@ -51,7 +52,6 @@ ] }, "dependencies": { - "axe-test-fixtures": "github:dequelabs/axe-test-fixtures", "browser-driver-manager": "^1.0.4" } } diff --git a/packages/playwright/test/axe-playwright.spec.ts b/packages/playwright/test/axe-playwright.spec.ts index 184b7b18..c5dc55db 100644 --- a/packages/playwright/test/axe-playwright.spec.ts +++ b/packages/playwright/test/axe-playwright.spec.ts @@ -8,6 +8,7 @@ import { assert } from 'chai'; import path from 'path'; import { Server, createServer } from 'http'; import { AxeBuilder } from '../src'; +import { fixturesPath } from 'axe-test-fixtures'; describe('@axe-core/playwright', () => { let server: Server; @@ -16,28 +17,26 @@ describe('@axe-core/playwright', () => { const axePath = require.resolve('axe-core'); const axeSource = fs.readFileSync(axePath, 'utf8'); let browser: ChromiumBrowser; - const axeTestFixtures = path.resolve(__dirname, 'fixtures'); - const externalPath = path.resolve(axeTestFixtures, 'external'); const axeLegacySource = fs.readFileSync( - path.join(externalPath, 'axe-core@legacy.js'), + path.join(fixturesPath, 'axe-core@legacy.js'), 'utf-8' ); const axeCrasherSource = fs.readFileSync( - path.join(externalPath, 'axe-crasher.js'), + path.join(fixturesPath, 'axe-crasher.js'), 'utf8' ); const axeForceLegacy = fs.readFileSync( - path.join(externalPath, 'axe-force-legacy.js'), + path.join(fixturesPath, 'axe-force-legacy.js'), 'utf8' ); const axeLargePartial = fs.readFileSync( - path.join(externalPath, 'axe-large-partial.js'), + path.join(fixturesPath, 'axe-large-partial.js'), 'utf8' ); before(async () => { const app = express(); - app.use(express.static(axeTestFixtures)); + app.use(express.static(fixturesPath)); server = createServer(app); addr = await testListen(server); }); @@ -60,7 +59,7 @@ describe('@axe-core/playwright', () => { describe('analyze', () => { it('returns results using a different version of axe-core', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page, axeSource: axeLegacySource @@ -76,7 +75,7 @@ describe('@axe-core/playwright', () => { }); it('returns results', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }).analyze(); assert.equal(res?.status(), 200); @@ -88,7 +87,7 @@ describe('@axe-core/playwright', () => { }); it('returns correct results metadata', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }).analyze(); assert.equal(res?.status(), 200); @@ -101,12 +100,12 @@ describe('@axe-core/playwright', () => { assert.isDefined(results.testEnvironment.windowWidth); assert.isDefined(results.testRunner.name); assert.isDefined(results.toolOptions.reporter); - assert.equal(results.url, `${addr}/external/index.html`); + assert.equal(results.url, `${addr}/index.html`); }); it('properly isolates the call to axe.finishRun', async () => { let err; - const res = await page.goto(`${addr}/external/isolated-finish.html`); + const res = await page.goto(`${addr}/isolated-finish.html`); try { await new AxeBuilder({ page }).analyze(); } catch (e) { @@ -120,7 +119,7 @@ describe('@axe-core/playwright', () => { it('handles large results', async function () { /* this test handles a large amount of partial results a timeout may be required */ this.timeout(1_000_000); - const res = await await page.goto(`${addr}/external/index.html`); + const res = await await page.goto(`${addr}/index.html`); assert.equal(res?.status(), 200); @@ -134,7 +133,7 @@ describe('@axe-core/playwright', () => { }); it('reports frame-tested', async () => { - const res = await page.goto(`${addr}/external/crash-parent.html`); + const res = await page.goto(`${addr}/crash-parent.html`); const results = await new AxeBuilder({ page, axeSource: axeSource + axeCrasherSource @@ -151,7 +150,7 @@ describe('@axe-core/playwright', () => { it('throws when injecting a problematic source', async () => { let error: Error | null = null; - const res = await page.goto(`${addr}/external/crash.html`); + const res = await page.goto(`${addr}/crash.html`); try { await new AxeBuilder({ page, @@ -169,7 +168,7 @@ describe('@axe-core/playwright', () => { let error: Error | null = null; const brokenSource = axeSource + `;window.axe.utils = {}`; - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); try { await new AxeBuilder({ page, axeSource: brokenSource }) .withRules('label') @@ -183,7 +182,7 @@ describe('@axe-core/playwright', () => { }); it('returns the same results from runPartial as from legacy mode', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const legacyResults = await new AxeBuilder({ page, axeSource: axeSource + axeForceLegacy @@ -210,7 +209,7 @@ describe('@axe-core/playwright', () => { describe('disableRules', () => { it('disables the given rules(s) as array', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .disableRules(['region']) .analyze(); @@ -226,7 +225,7 @@ describe('@axe-core/playwright', () => { }); it('disables the given rules(s) as string', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .disableRules('region') .analyze(); @@ -244,7 +243,7 @@ describe('@axe-core/playwright', () => { describe('withRules', () => { it('only runs the provided rules as an array', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .withRules(['region']) .analyze(); @@ -261,7 +260,7 @@ describe('@axe-core/playwright', () => { }); it('only runs the provided rules as a string', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .withRules('region') .analyze(); @@ -280,7 +279,7 @@ describe('@axe-core/playwright', () => { describe('options', () => { it('passes options to axe-core', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .options({ rules: { region: { enabled: false } } }) .analyze(); @@ -298,7 +297,7 @@ describe('@axe-core/playwright', () => { describe('withTags', () => { it('only rules rules with the given tag(s) as an array', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .withTags(['best-practice']) .analyze(); @@ -316,7 +315,7 @@ describe('@axe-core/playwright', () => { }); it('only rules rules with the given tag(s) as a string', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .withTags('best-practice') .analyze(); @@ -335,7 +334,7 @@ describe('@axe-core/playwright', () => { }); it('No results provided when the given tag(s) is invalid', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page }) .withTags(['foobar']) .analyze(); @@ -355,7 +354,7 @@ describe('@axe-core/playwright', () => { describe('frame tests', () => { it('injects into nested iframes', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const { violations } = await new AxeBuilder({ page }) .options({ runOnly: 'label' }) .analyze(); @@ -377,7 +376,7 @@ describe('@axe-core/playwright', () => { }); it('injects into nested frameset', async () => { - const res = await page.goto(`${addr}/external/nested-frameset.html`); + const res = await page.goto(`${addr}/nested-frameset.html`); const { violations } = await new AxeBuilder({ page }) .options({ runOnly: 'label' }) .analyze(); @@ -400,7 +399,7 @@ describe('@axe-core/playwright', () => { }); it('should work on shadow DOM iframes', async () => { - const res = await page.goto(`${addr}/external/shadow-frames.html`); + const res = await page.goto(`${addr}/shadow-frames.html`); const { violations } = await new AxeBuilder({ page }) .options({ runOnly: 'label' }) .analyze(); @@ -420,7 +419,7 @@ describe('@axe-core/playwright', () => { }); it('injects once per iframe', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const builder = new AxeBuilder({ page }); const origScript = (builder as any).script; @@ -439,7 +438,7 @@ describe('@axe-core/playwright', () => { }); it('handles unloaded iframes (e.g. loading=lazy)', async () => { - const res = await page.goto(`${addr}/external/lazy-loaded-iframe.html`); + const res = await page.goto(`${addr}/lazy-loaded-iframe.html`); const results = await new AxeBuilder({ page }) .options({ runOnly: ['label', 'frame-tested'] }) @@ -468,10 +467,10 @@ describe('@axe-core/playwright', () => { }, []); }; it('with include and exclude', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .include('.include') - .exclude('.exclude') + // .exclude('.exclude') .analyze(); const flattenTarget = flatPassesTargets(results); @@ -481,7 +480,7 @@ describe('@axe-core/playwright', () => { }); it('with only include', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .include('.include') .analyze(); @@ -492,7 +491,7 @@ describe('@axe-core/playwright', () => { }); it('with only exclude', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .exclude('.exclude') .analyze(); @@ -503,7 +502,7 @@ describe('@axe-core/playwright', () => { }); it('with chaining includes', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .include('.include') @@ -519,7 +518,7 @@ describe('@axe-core/playwright', () => { }); it('with chaining excludes', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .exclude('.exclude') .exclude('.exclude2') @@ -532,7 +531,7 @@ describe('@axe-core/playwright', () => { }); it('with chaining includes and excludes', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .include('.include') .include('.include2') @@ -549,7 +548,7 @@ describe('@axe-core/playwright', () => { }); it('with include using an array of strings', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const expected = ['.selector-one', '.selector-two', '.selector-three']; const axeSource = ` @@ -573,7 +572,7 @@ describe('@axe-core/playwright', () => { }); it('with exclude using an array of strings', async () => { - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); const expected = ['.selector-one', '.selector-two', '.selector-three']; const axeSource = ` @@ -597,7 +596,7 @@ describe('@axe-core/playwright', () => { }); it('with labelled frame', async () => { - await page.goto(`${addr}/external/context-include-exclude.html`); + await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder({ page }) .include({ fromFrames: ['#ifr-inc-excl', 'html'] }) .exclude({ fromFrames: ['#ifr-inc-excl', '#foo-bar'] }) @@ -613,7 +612,7 @@ describe('@axe-core/playwright', () => { }); it('with include shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxeBuilder({ page }) .include([['#shadow-root-1', '#shadow-button-1']]) .include([['#shadow-root-2', '#shadow-button-2']]) @@ -624,7 +623,7 @@ describe('@axe-core/playwright', () => { }); it('with exclude shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxeBuilder({ page }) .exclude([['#shadow-root-1', '#shadow-button-1']]) .exclude([['#shadow-root-2', '#shadow-button-2']]) @@ -635,7 +634,7 @@ describe('@axe-core/playwright', () => { }); it('with labelled shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxeBuilder({ page }) .include({ fromShadowDom: ['#shadow-root-1', '#shadow-button-1'] }) .exclude({ fromShadowDom: ['#shadow-root-2', '#shadow-button-2'] }) @@ -645,7 +644,7 @@ describe('@axe-core/playwright', () => { }); it('with labelled iframe and shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-frames.html`); + await page.goto(`${addr}/shadow-frames.html`); const { violations } = await new AxeBuilder({ page }) .exclude({ fromFrames: [ @@ -669,7 +668,7 @@ describe('@axe-core/playwright', () => { const finishRunThrows = `;axe.finishRun = () => { throw new Error("No finishRun")}`; it('throws an error if axe.finishRun throws', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore delete page.context().newPage; @@ -699,7 +698,7 @@ describe('@axe-core/playwright', () => { }); it('throw an error with modified url', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); // eslint-disable-next-line @typescript-eslint/ban-ts-comment //@ts-ignore delete page.context().newPage; @@ -731,7 +730,7 @@ describe('@axe-core/playwright', () => { }); it('throws an error if axe.finishRun throws', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); assert.equal(res?.status(), 200); try { @@ -759,7 +758,7 @@ describe('@axe-core/playwright', () => { describe('setLegacyMode', () => { const runPartialThrows = `;axe.runPartial = () => { throw new Error("No runPartial")}`; it('runs legacy mode when used', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page, axeSource: axeSource + runPartialThrows @@ -772,7 +771,7 @@ describe('@axe-core/playwright', () => { }); it('prevents cross-origin frame testing', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxeBuilder({ page, axeSource: axeSource + runPartialThrows @@ -789,7 +788,7 @@ describe('@axe-core/playwright', () => { }); it('can be disabled again', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxeBuilder({ page }) .withRules('frame-tested') .setLegacyMode() @@ -807,7 +806,7 @@ describe('@axe-core/playwright', () => { describe('for versions without axe.runPartial', () => { describe('analyze', () => { it('returns results', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxeBuilder({ page, axeSource: axeLegacySource @@ -824,7 +823,7 @@ describe('@axe-core/playwright', () => { it('throws if axe errors out on the top window', async () => { let error: Error | null = null; - const res = await page.goto(`${addr}/external/crash.html`); + const res = await page.goto(`${addr}/crash.html`); try { await new AxeBuilder({ page, @@ -839,7 +838,7 @@ describe('@axe-core/playwright', () => { }); it('tests cross-origin pages', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxeBuilder({ page, axeSource: axeLegacySource @@ -858,7 +857,7 @@ describe('@axe-core/playwright', () => { describe('frame tests', () => { it('injects into nested iframes', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const { violations } = await new AxeBuilder({ page, axeSource: axeLegacySource @@ -883,7 +882,7 @@ describe('@axe-core/playwright', () => { }); it('injects into nested frameset', async () => { - const res = await page.goto(`${addr}/external/nested-frameset.html`); + const res = await page.goto(`${addr}/nested-frameset.html`); const { violations } = await new AxeBuilder({ page, axeSource: axeLegacySource @@ -909,7 +908,7 @@ describe('@axe-core/playwright', () => { }); it('should work on shadow DOM iframes', async () => { - const res = await page.goto(`${addr}/external/shadow-frames.html`); + const res = await page.goto(`${addr}/shadow-frames.html`); const { violations } = await new AxeBuilder({ page, axeSource: axeLegacySource diff --git a/packages/playwright/test/fixtures/context.html b/packages/playwright/test/fixtures/context.html deleted file mode 100644 index 47bc906c..00000000 --- a/packages/playwright/test/fixtures/context.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Context Test - - -

Context Test

-
include me
-
include me
-
exclude me
-
exclude me
- - diff --git a/packages/playwright/test/fixtures/external b/packages/playwright/test/fixtures/external deleted file mode 120000 index 817a08c2..00000000 --- a/packages/playwright/test/fixtures/external +++ /dev/null @@ -1 +0,0 @@ -../../../../node_modules/axe-test-fixtures/fixtures \ No newline at end of file diff --git a/packages/puppeteer/test/axe-puppeteer.spec.ts b/packages/puppeteer/test/axe-puppeteer.spec.ts index d016e5bd..d9b0ea5e 100644 --- a/packages/puppeteer/test/axe-puppeteer.spec.ts +++ b/packages/puppeteer/test/axe-puppeteer.spec.ts @@ -14,6 +14,7 @@ import { expectAsync, expectAsyncToNotThrow } from './utils'; +import { fixturesPath } from 'axe-test-fixtures'; type SinonSpy = sinon.SinonSpy; @@ -38,17 +39,16 @@ describe('AxePuppeteer', function () { before(async () => { const axePath = require.resolve('axe-core'); axeSource = fs.readFileSync(axePath, 'utf8'); - const externalPath = path.resolve(__dirname, 'fixtures', 'external'); axeCrasherSource = fs.readFileSync( - path.join(externalPath, 'axe-crasher.js'), + path.join(fixturesPath, 'axe-crasher.js'), 'utf8' ); axeForceLegacy = fs.readFileSync( - path.join(externalPath, 'axe-force-legacy.js'), + path.join(fixturesPath, 'axe-force-legacy.js'), 'utf8' ); axeLargePartial = fs.readFileSync( - path.join(externalPath, 'axe-large-partial.js'), + path.join(fixturesPath, 'axe-large-partial.js'), 'utf8' ); }); @@ -75,7 +75,7 @@ describe('AxePuppeteer', function () { it('runs in parallel', async () => { // Just to prove Puppeteer runs scripts in parallel, // and so axe-core/puppeteer should too - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const p1 = page.evaluate(() => { window.parallel = true; return new Promise(res => { @@ -94,7 +94,7 @@ describe('AxePuppeteer', function () { describe('constructor', () => { it('accepts a Page', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const axePup = new AxePuppeteer(page); assert.equal(res?.status(), 200); @@ -102,7 +102,7 @@ describe('AxePuppeteer', function () { }); it('accepts a Frame', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const axePup = new AxePuppeteer(page.mainFrame()); assert.equal(res?.status(), 200); @@ -116,7 +116,7 @@ describe('AxePuppeteer', function () { configure: () => {} } `; - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const evalSpy: SinonSpy = sinon.spy(page.mainFrame(), 'evaluate'); await new AxePuppeteer(page, axeSource).analyze(); @@ -137,7 +137,7 @@ describe('AxePuppeteer', function () { describe('.analyze()', () => { it('sets the helpUrl application string', async () => { - const res = await page.goto(`${addr}/external/iframes/baz.html`); + const res = await page.goto(`${addr}/iframes/baz.html`); const { violations } = await new AxePuppeteer(page) .withRules('label') .analyze(); @@ -147,7 +147,7 @@ describe('AxePuppeteer', function () { }); it('returns correct results metadata', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page).analyze(); assert.equal(res?.status(), 200); @@ -160,12 +160,12 @@ describe('AxePuppeteer', function () { assert.isDefined(results.testEnvironment.windowWidth); assert.isDefined(results.testRunner.name); assert.isDefined(results.toolOptions.reporter); - assert.equal(results.url, `${addr}/external/index.html`); + assert.equal(results.url, `${addr}/index.html`); }); it('properly isolates the call to axe.finishRun', async () => { let err; - const res = await page.goto(`${addr}/external/isolated-finish.html`); + const res = await page.goto(`${addr}/isolated-finish.html`); try { await new AxePuppeteer(page).analyze(); } catch (e) { @@ -179,7 +179,7 @@ describe('AxePuppeteer', function () { it('handles large results', async function () { /* this test handles a large amount of partial results a timeout may be required */ this.timeout(50_000); - const res = await await page.goto(`${addr}/external/index.html`); + const res = await await page.goto(`${addr}/index.html`); assert.equal(res?.status(), 200); @@ -193,7 +193,7 @@ describe('AxePuppeteer', function () { }); it('returns the same results from runPartial as from legacy mode', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const legacyResults = await new AxePuppeteer( page, axeSource + axeForceLegacy @@ -210,7 +210,7 @@ describe('AxePuppeteer', function () { describe('returned promise', () => { it("returns results through analyze's promise", async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) .withRules('label') .analyze(); @@ -231,7 +231,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const axePup = new AxePuppeteer(page, axeSource); @@ -242,7 +242,7 @@ describe('AxePuppeteer', function () { describe('analyze callback', () => { it('returns results through the callback if passed', done => { - page.goto(`${addr}/external/index.html`).then(res => { + page.goto(`${addr}/index.html`).then(res => { new AxePuppeteer(page).analyze((err, results) => { try { assert.equal(res?.status(), 200); @@ -268,7 +268,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); assert.equal(res?.status(), 200); @@ -283,7 +283,7 @@ describe('AxePuppeteer', function () { describe('error reporting', () => { it('throws if axe errors out on the top window', done => { page - .goto(`${addr}/external/crash.html`) + .goto(`${addr}/crash.html`) .then(res => { assert.equal(res?.status(), 200); return new AxePuppeteer( @@ -299,7 +299,7 @@ describe('AxePuppeteer', function () { it('throws when injecting a problematic source', done => { page - .goto(`${addr}/external/crash.html`) + .goto(`${addr}/crash.html`) .then(res => { assert.equal(res?.status(), 200); return new AxePuppeteer(page, 'throw new Error()').analyze(); @@ -313,7 +313,7 @@ describe('AxePuppeteer', function () { it('throws when a setup fails', done => { const brokenSource = axeSource + `;window.axe.utils = {}`; page - .goto(`${addr}/external/index.html`) + .goto(`${addr}/index.html`) .then(res => { assert.equal(res?.status(), 200); return new AxePuppeteer(page, brokenSource) @@ -364,7 +364,7 @@ describe('AxePuppeteer', function () { it('gives a helpful error', done => { page - .goto(`${addr2}/external/index.html`) + .goto(`${addr2}/index.html`) .then(res => { assert.equal(res?.status(), 200); }) @@ -426,7 +426,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); assert.equal(res?.status(), 200); const axePip = new AxePuppeteer(page, axeSource) @@ -437,7 +437,7 @@ describe('AxePuppeteer', function () { }); it('with labelled frame', async () => { - await page.goto(`${addr}/external/context-include-exclude.html`); + await page.goto(`${addr}/context-include-exclude.html`); const results = await new AxePuppeteer(page) .include({ fromFrames: ['#ifr-inc-excl', 'html'] }) .exclude({ fromFrames: ['#ifr-inc-excl', '#foo-bar'] }) @@ -453,7 +453,7 @@ describe('AxePuppeteer', function () { }); it('with include shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxePuppeteer(page) .include([['#shadow-root-1', '#shadow-button-1']]) .include([['#shadow-root-2', '#shadow-button-2']]) @@ -464,7 +464,7 @@ describe('AxePuppeteer', function () { }); it('with exclude shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxePuppeteer(page) .exclude([['#shadow-root-1', '#shadow-button-1']]) .exclude([['#shadow-root-2', '#shadow-button-2']]) @@ -475,7 +475,7 @@ describe('AxePuppeteer', function () { }); it('with labelled shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-dom.html`); + await page.goto(`${addr}/shadow-dom.html`); const results = await new AxePuppeteer(page) .include({ fromShadowDom: ['#shadow-root-1', '#shadow-button-1'] }) .exclude({ fromShadowDom: ['#shadow-root-2', '#shadow-button-2'] }) @@ -485,7 +485,7 @@ describe('AxePuppeteer', function () { }); it('with labelled iframe and shadow DOM', async () => { - await page.goto(`${addr}/external/shadow-frames.html`); + await page.goto(`${addr}/shadow-frames.html`); const { violations } = await new AxePuppeteer(page) .exclude({ fromFrames: [ @@ -519,7 +519,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); assert.equal(res?.status(), 200); const axePip = new AxePuppeteer(page, axeSource) @@ -553,7 +553,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); assert.equal(res?.status(), 200); const axePip = new AxePuppeteer(page, axeSource).include('.include'); @@ -584,7 +584,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); assert.equal(res?.status(), 200); const axePip = new AxePuppeteer(page, axeSource).exclude('.exclude'); @@ -607,7 +607,7 @@ describe('AxePuppeteer', function () { } `; - const res = await page.goto(`${addr}/context.html`); + const res = await page.goto(`${addr}/context-include-exclude.html`); assert.equal(res?.status(), 200); const axePip = new AxePuppeteer(page, axeSource); @@ -617,7 +617,7 @@ describe('AxePuppeteer', function () { describe('.disableFrame()', () => { it('disables the given rule(s)', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const results = await new AxePuppeteer(page) // Ignore all frames .disableFrame('#ifr-foo, #ifr-bar') @@ -654,7 +654,7 @@ describe('AxePuppeteer', function () { ] }; - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) .configure(config) .withRules(['foo']) @@ -684,7 +684,7 @@ describe('AxePuppeteer', function () { describe('options', () => { describe('.options()', () => { it('passes options to axe-core', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) // Disable the `region` rule @@ -705,7 +705,7 @@ describe('AxePuppeteer', function () { describe('.withTags()', () => { it('only rules with the given tag(s)', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) .withTags(['best-practice']) @@ -729,7 +729,7 @@ describe('AxePuppeteer', function () { describe('.withRules()', () => { it('only rules with the given rule(s)', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) // Only enable the `region` rule @@ -751,7 +751,7 @@ describe('AxePuppeteer', function () { describe('.disableRules()', () => { it('disables the given rule(s)', async function () { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page) // Disable the `region` rule @@ -773,7 +773,7 @@ describe('AxePuppeteer', function () { describe('frame tests', () => { it('injects into nested iframes', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const { violations } = await new AxePuppeteer(page) .options({ runOnly: 'label' }) @@ -796,7 +796,7 @@ describe('AxePuppeteer', function () { }); it('tests framesets', async () => { - const res = await page.goto(`${addr}/external/nested-frameset.html`); + const res = await page.goto(`${addr}/nested-frameset.html`); const { violations } = await new AxePuppeteer(page) .options({ runOnly: 'label' }) .analyze(); @@ -818,7 +818,7 @@ describe('AxePuppeteer', function () { }); it('tests frames in shadow DOM', async () => { - const res = await page.goto(`${addr}/external/shadow-frames.html`); + const res = await page.goto(`${addr}/shadow-frames.html`); const { violations } = await new AxePuppeteer(page) .options({ runOnly: 'label' }) .analyze(); @@ -837,7 +837,7 @@ describe('AxePuppeteer', function () { }); it('reports erroring frames in frame-tested', async () => { - const res = await page.goto(`${addr}/external/crash-parent.html`); + const res = await page.goto(`${addr}/crash-parent.html`); const results = await new AxePuppeteer(page, axeSource + axeCrasherSource) .options({ runOnly: ['label', 'frame-tested'] }) .analyze(); @@ -860,7 +860,7 @@ describe('AxePuppeteer', function () { }); it('runs the same when passed a Frame', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const pageResults = await new AxePuppeteer(page).analyze(); // Calling AxePuppeteer with a frame is deprecated, and will show a warning @@ -874,7 +874,7 @@ describe('AxePuppeteer', function () { }); it('skips unloaded iframes (e.g. loading=lazy)', async () => { - const res = await page.goto(`${addr}/external/lazy-loaded-iframe.html`); + const res = await page.goto(`${addr}/lazy-loaded-iframe.html`); const results = await new AxePuppeteer(page) .options({ runOnly: ['label', 'frame-tested'] }) .analyze(); @@ -899,7 +899,7 @@ describe('AxePuppeteer', function () { describe('axe.finishRun errors', () => { const finishRunThrows = `;axe.finishRun = () => { throw new Error("No finishRun")}`; it('throws an error if window.open throws', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore delete page.browser().newPage(); @@ -926,7 +926,7 @@ describe('AxePuppeteer', function () { }); it('throw an error with modified url', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore delete page.browser().newPage(); @@ -955,7 +955,7 @@ describe('AxePuppeteer', function () { }); it('throws an error if axe.finishRun throws', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); assert.equal(res?.status(), 200); try { @@ -970,7 +970,7 @@ describe('AxePuppeteer', function () { describe('setLegacyMode', () => { const runPartialThrows = `;axe.runPartial = () => { throw new Error("No runPartial")}`; it('runs legacy mode when used', async () => { - const res = await page.goto(`${addr}/external/index.html`); + const res = await page.goto(`${addr}/index.html`); const results = await new AxePuppeteer(page, axeSource + runPartialThrows) .setLegacyMode() .analyze(); @@ -980,7 +980,7 @@ describe('AxePuppeteer', function () { }); it('prevents cross-origin frame testing', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxePuppeteer(page, axeSource + runPartialThrows) .withRules('frame-tested') .setLegacyMode() @@ -995,7 +995,7 @@ describe('AxePuppeteer', function () { }); it('can be disabled again', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxePuppeteer(page) .withRules('frame-tested') .setLegacyMode() @@ -1014,12 +1014,12 @@ describe('AxePuppeteer', function () { describe('without runPartial', () => { let axe403Source: string; before(() => { - const axePath = require.resolve('./fixtures/external/axe-core@legacy.js'); + const axePath = path.join(fixturesPath, 'axe-core@legacy.js'); axe403Source = fs.readFileSync(axePath, 'utf8'); }); it('can run', async () => { - const res = await page.goto(`${addr}/external/nested-iframes.html`); + const res = await page.goto(`${addr}/nested-iframes.html`); const results = await new AxePuppeteer(page, axe403Source) .withRules('label') .analyze(); @@ -1033,7 +1033,7 @@ describe('AxePuppeteer', function () { it('throws if the top level errors', done => { const source = axe403Source + axeCrasherSource; page - .goto(`${addr}/external/crash.html`) + .goto(`${addr}/crash.html`) .then(() => { return new AxePuppeteer(page, source).withRules('label').analyze(); }) @@ -1047,7 +1047,7 @@ describe('AxePuppeteer', function () { }); it('reports frame-tested', async () => { - const res = await page.goto(`${addr}/external/crash-parent.html`); + const res = await page.goto(`${addr}/crash-parent.html`); const results = await new AxePuppeteer(page, axeSource + axeCrasherSource) .withRules(['label', 'frame-tested']) .analyze(); @@ -1060,7 +1060,7 @@ describe('AxePuppeteer', function () { }); it('tests cross-origin pages', async () => { - const res = await page.goto(`${addr}/external/cross-origin.html`); + const res = await page.goto(`${addr}/cross-origin.html`); const results = await new AxePuppeteer(page, axe403Source) .withRules('frame-tested') .analyze(); diff --git a/packages/puppeteer/test/fixtures/context.html b/packages/puppeteer/test/fixtures/context.html deleted file mode 100644 index aa354429..00000000 --- a/packages/puppeteer/test/fixtures/context.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - Context Test - - -

Context Test

-
include me
-
exclude me
- - diff --git a/packages/puppeteer/test/fixtures/external b/packages/puppeteer/test/fixtures/external deleted file mode 120000 index 817a08c2..00000000 --- a/packages/puppeteer/test/fixtures/external +++ /dev/null @@ -1 +0,0 @@ -../../../../node_modules/axe-test-fixtures/fixtures \ No newline at end of file diff --git a/packages/puppeteer/test/utils.ts b/packages/puppeteer/test/utils.ts index 0f59b8ae..46ed60d4 100644 --- a/packages/puppeteer/test/utils.ts +++ b/packages/puppeteer/test/utils.ts @@ -1,9 +1,9 @@ -import * as path from 'path'; import express from 'express'; import { createServer, Server } from 'http'; import testListen from 'test-listen'; import { expect } from 'chai'; import type { PuppeteerLaunchOptions } from 'puppeteer'; +import { fixturesPath } from 'axe-test-fixtures'; export async function expectAsync( fn: () => Promise @@ -27,7 +27,7 @@ export async function expectAsyncToNotThrow( export async function startServer(): Promise<{ server: Server; addr: string }> { const app: express.Application = express(); - app.use(express.static(path.resolve(__dirname, 'fixtures'))); + app.use(express.static(fixturesPath)); const server: Server = createServer(app); const addr = await testListen(server); diff --git a/packages/webdriverio/fixtures/external b/packages/webdriverio/fixtures/external deleted file mode 120000 index 90a0d6c9..00000000 --- a/packages/webdriverio/fixtures/external +++ /dev/null @@ -1 +0,0 @@ -../../../node_modules/axe-test-fixtures/fixtures \ No newline at end of file diff --git a/packages/webdriverio/test/axe-webdriverio.spec.ts b/packages/webdriverio/test/axe-webdriverio.spec.ts index 84e33810..f05c793a 100644 --- a/packages/webdriverio/test/axe-webdriverio.spec.ts +++ b/packages/webdriverio/test/axe-webdriverio.spec.ts @@ -13,6 +13,7 @@ import { logOrRethrowError } from '../src/utils'; import type { AxeResults, Result } from 'axe-core'; import child_process from 'child_process'; import { ChildProcessWithoutNullStreams } from 'child_process'; +import { fixturesPath } from 'axe-test-fixtures'; const connectToChromeDriver = (port: number): Promise => { let socket: net.Socket; @@ -73,33 +74,27 @@ describe('@axe-core/webdriverio', () => { let client: webdriverio.Browser; const axePath = require.resolve('axe-core'); const axeSource = fs.readFileSync(axePath, 'utf8'); - const axeTestFixtures = path.resolve( - __dirname, - '..', - 'fixtures', - 'external' - ); const axeLegacySource = fs.readFileSync( - path.resolve(axeTestFixtures, 'axe-core@legacy.js'), + path.resolve(fixturesPath, 'axe-core@legacy.js'), 'utf-8' ); const axeCrasherSource = fs.readFileSync( - path.join(axeTestFixtures, 'axe-crasher.js'), + path.join(fixturesPath, 'axe-crasher.js'), 'utf8' ); const axeForceLegacy = fs.readFileSync( - path.join(axeTestFixtures, 'axe-force-legacy.js'), + path.join(fixturesPath, 'axe-force-legacy.js'), 'utf8' ); const axeLargePartial = fs.readFileSync( - path.join(axeTestFixtures, 'axe-large-partial.js'), + path.join(fixturesPath, 'axe-large-partial.js'), 'utf8' ); beforeEach(async () => { const app = express(); let binaryPath; - app.use(express.static(axeTestFixtures)); + app.use(express.static(fixturesPath)); server = createServer(app); addr = await testListen(server); if ( diff --git a/packages/webdriverjs/test/axe-webdriverjs.spec.ts b/packages/webdriverjs/test/axe-webdriverjs.spec.ts index 73ca0bbe..ed27baaf 100644 --- a/packages/webdriverjs/test/axe-webdriverjs.spec.ts +++ b/packages/webdriverjs/test/axe-webdriverjs.spec.ts @@ -10,12 +10,10 @@ import { Server, createServer } from 'http'; import { Webdriver } from './test-utils'; import { AxeBuilder } from '../src'; import { axeRunPartial } from '../src/browser'; +import { fixturesPath } from 'axe-test-fixtures'; const dylangConfig = JSON.parse( - fs.readFileSync( - require.resolve('./fixtures/external/dylang-config.json'), - 'utf8' - ) + fs.readFileSync(path.join(fixturesPath, 'dylang-config.json'), 'utf8') ); describe('@axe-core/webdriverjs', () => { @@ -30,22 +28,21 @@ describe('@axe-core/webdriverjs', () => { before(async () => { const axePath = require.resolve('axe-core'); axeSource = fs.readFileSync(axePath, 'utf8'); - const externalPath = path.resolve(__dirname, 'fixtures', 'external'); axeCrasherSource = fs.readFileSync( - path.join(externalPath, 'axe-crasher.js'), + path.join(fixturesPath, 'axe-crasher.js'), 'utf8' ); axeForceLegacy = fs.readFileSync( - path.join(externalPath, 'axe-force-legacy.js'), + path.join(fixturesPath, 'axe-force-legacy.js'), 'utf8' ); axeLargePartial = fs.readFileSync( - path.join(externalPath, 'axe-large-partial.js'), + path.join(fixturesPath, 'axe-large-partial.js'), 'utf8' ); const app = express(); - app.use(express.static(path.resolve(__dirname, 'fixtures'))); + app.use(express.static(fixturesPath)); server = createServer(app); addr = await testListen(server); }); @@ -64,7 +61,7 @@ describe('@axe-core/webdriverjs', () => { describe('analyze', () => { it('returns results', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver).analyze(); @@ -77,7 +74,7 @@ describe('@axe-core/webdriverjs', () => { }); it('handles undefineds', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver).analyze(); @@ -90,7 +87,7 @@ describe('@axe-core/webdriverjs', () => { }); it('returns correct results metadata', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver).analyze(); @@ -104,12 +101,12 @@ describe('@axe-core/webdriverjs', () => { assert.isDefined(results.testEnvironment.windowWidth); assert.isDefined(results.testRunner.name); assert.isDefined(results.toolOptions.reporter); - assert.equal(results.url, `${addr}/external/index.html`); + assert.equal(results.url, `${addr}/index.html`); }); it('properly isolates the call to axe.finishRun', async () => { let err; - await driver.get(`${addr}/external/isolated-finish.html`); + await driver.get(`${addr}/isolated-finish.html`); const title = await driver.getTitle(); try { await new AxeBuilder(driver).analyze(); @@ -124,7 +121,7 @@ describe('@axe-core/webdriverjs', () => { it('handles large results', async function () { /* this test handles a large amount of partial results a timeout may be required */ this.timeout(60_000); - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const results = await new AxeBuilder( driver, @@ -136,7 +133,7 @@ describe('@axe-core/webdriverjs', () => { }); it('throws if axe errors out on the top window', async () => { - await driver.get(`${addr}/external/crash.html`); + await driver.get(`${addr}/crash.html`); const title = await driver.getTitle(); let err; @@ -151,7 +148,7 @@ describe('@axe-core/webdriverjs', () => { }); it('throws when injecting a problematic source', async () => { - await driver.get(`${addr}/external/crash.html`); + await driver.get(`${addr}/crash.html`); const title = await driver.getTitle(); let err; @@ -167,7 +164,7 @@ describe('@axe-core/webdriverjs', () => { it('throws when a setup fails', async () => { const brokenSource = axeSource + `;window.axe.utils = {}`; - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); let err; @@ -194,7 +191,7 @@ describe('@axe-core/webdriverjs', () => { describe('configure', () => { it('should find configured violations in all iframes', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -208,7 +205,7 @@ describe('@axe-core/webdriverjs', () => { }); it('should find configured violations in all framesets', async () => { - await driver.get(`${addr}/external/nested-frameset.html`); + await driver.get(`${addr}/nested-frameset.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -232,7 +229,7 @@ describe('@axe-core/webdriverjs', () => { describe('disableRules', () => { it('disables the given rules(s) as array', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -250,7 +247,7 @@ describe('@axe-core/webdriverjs', () => { }); it('disables the given rules(s) as string', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -270,7 +267,7 @@ describe('@axe-core/webdriverjs', () => { describe('frame tests', () => { it('injects into nested iframes', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); const { violations } = await new AxeBuilder(driver) @@ -294,7 +291,7 @@ describe('@axe-core/webdriverjs', () => { }); it('injects into nested frameset', async () => { - await driver.get(`${addr}/external/nested-frameset.html`); + await driver.get(`${addr}/nested-frameset.html`); const title = await driver.getTitle(); const { violations } = await new AxeBuilder(driver) @@ -319,7 +316,7 @@ describe('@axe-core/webdriverjs', () => { }); it('should work on shadow DOM iframes', async () => { - await driver.get(`${addr}/external/shadow-frames.html`); + await driver.get(`${addr}/shadow-frames.html`); const title = await driver.getTitle(); const { violations } = await new AxeBuilder(driver) @@ -340,7 +337,7 @@ describe('@axe-core/webdriverjs', () => { }); it('reports erroring frames in frame-tested', async () => { - await driver.get(`${addr}/external/crash-parent.html`); + await driver.get(`${addr}/crash-parent.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axeSource + axeCrasherSource) @@ -365,7 +362,7 @@ describe('@axe-core/webdriverjs', () => { }); it('returns the same results from runPartial as from legacy mode', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); const legacyResults = await new AxeBuilder( @@ -383,7 +380,7 @@ describe('@axe-core/webdriverjs', () => { }); it('skips unloaded iframes (e.g. loading=lazy)', async () => { - await driver.get(`${addr}/external/lazy-loaded-iframe.html`); + await driver.get(`${addr}/lazy-loaded-iframe.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -407,7 +404,7 @@ describe('@axe-core/webdriverjs', () => { }); it('resets pageLoad timeout to user setting', async () => { - await driver.get(`${addr}/external/lazy-loaded-iframe.html`); + await driver.get(`${addr}/lazy-loaded-iframe.html`); driver.manage().setTimeouts({ pageLoad: 500 }); await driver.getTitle(); @@ -422,7 +419,7 @@ describe('@axe-core/webdriverjs', () => { describe('withRules', () => { it('only runs the provided rules as an array', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -441,7 +438,7 @@ describe('@axe-core/webdriverjs', () => { }); it('only runs the provided rules as a string', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -462,7 +459,7 @@ describe('@axe-core/webdriverjs', () => { describe('options', () => { it('passes options to axe-core', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -482,7 +479,7 @@ describe('@axe-core/webdriverjs', () => { describe('withTags', () => { it('only rules rules with the given tag(s) as an array', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -503,7 +500,7 @@ describe('@axe-core/webdriverjs', () => { }); it('only rules rules with the given tag(s) as a string', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -524,7 +521,7 @@ describe('@axe-core/webdriverjs', () => { }); it('No results provided when the given tag(s) is invalid', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -555,7 +552,7 @@ describe('@axe-core/webdriverjs', () => { }, []); }; it('with include and exclude', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver) @@ -569,7 +566,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with only include', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver).include('.include'); @@ -580,7 +577,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with only exclude', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver).exclude('.exclude'); @@ -591,7 +588,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with chaining only include', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver) @@ -605,7 +602,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with chaining only exclude', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver) @@ -619,7 +616,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with chaining include and exclude', async () => { - await driver.get(`${addr}/context.html`); + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); const builder = new AxeBuilder(driver) @@ -636,38 +633,53 @@ describe('@axe-core/webdriverjs', () => { assert.isFalse(flatPassesTargets(results).includes('.exclude2')); }); - it('with include and exclude iframe selectors with no violations', async () => { - await driver.get(`${addr}/context.html`); + it('with include and exclude iframes', async () => { + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); - const builder = new AxeBuilder(driver) - .include(['#ifr-one', 'html']) - .exclude(['#ifr-one', 'main']) - .exclude(['#ifr-one', 'img']); - - const results = await builder.analyze(); + const results = await new AxeBuilder(driver) + .include(['#ifr-inc-excl', 'html']) + .exclude(['#ifr-inc-excl', '#foo-bar']) + .include(['#ifr-inc-excl', '#foo-baz', 'html']) + .exclude(['#ifr-inc-excl', '#foo-baz', 'input']) + .analyze(); + const labelResult = results.violations.find( + (r: Result) => r.id === 'label' + ); assert.notEqual(title, 'Error'); - assert.lengthOf(results.violations, 0); + assert.isFalse(flatPassesTargets(results).includes('#foo-bar')); + assert.isFalse(flatPassesTargets(results).includes('input')); + assert.isUndefined(labelResult); }); - it('with include and exclude iframe selectors with violations', async () => { - await driver.get(`${addr}/context.html`); + it('with include iframes', async () => { + await driver.get(`${addr}/context-include-exclude.html`); const title = await driver.getTitle(); - const builder = new AxeBuilder(driver) - .include(['#ifr-one', 'html']) - .exclude(['#ifr-one', 'main']); - const results = await builder.analyze(); + const results = await new AxeBuilder(driver) + .include(['#ifr-inc-excl', '#foo-baz', 'html']) + .include(['#ifr-inc-excl', '#foo-baz', 'input']) + // does not exist + .include(['#hazaar', 'html']) + .analyze(); + + const labelResult = results.violations.find( + (r: Result) => r.id === 'label' + ); assert.notEqual(title, 'Error'); - assert.lengthOf(results.violations, 2); - assert.strictEqual(results.violations[0].id, 'image-alt'); - assert.strictEqual(results.violations[1].id, 'region'); + assert.isTrue(flatPassesTargets(results).includes('#ifr-inc-excl')); + assert.isTrue(flatPassesTargets(results).includes('#foo-baz')); + assert.isTrue(flatPassesTargets(results).includes('input')); + assert.isFalse(flatPassesTargets(results).includes('#foo-bar')); + // does not exist + assert.isFalse(flatPassesTargets(results).includes('#hazaar')); + assert.isDefined(labelResult); }); it('with labelled frame', async () => { - await driver.get(`${addr}/external/context-include-exclude.html`); + await driver.get(`${addr}/context-include-exclude.html`); const results = await new AxeBuilder(driver) .include({ fromFrames: ['#ifr-inc-excl', 'html'] }) .exclude({ fromFrames: ['#ifr-inc-excl', '#foo-bar'] }) @@ -683,7 +695,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with include shadow DOM', async () => { - await driver.get(`${addr}/external/shadow-dom.html`); + await driver.get(`${addr}/shadow-dom.html`); const results = await new AxeBuilder(driver) .include([['#shadow-root-1', '#shadow-button-1']]) .include([['#shadow-root-2', '#shadow-button-2']]) @@ -694,7 +706,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with exclude shadow DOM', async () => { - await driver.get(`${addr}/external/shadow-dom.html`); + await driver.get(`${addr}/shadow-dom.html`); const results = await new AxeBuilder(driver) .exclude([['#shadow-root-1', '#shadow-button-1']]) .exclude([['#shadow-root-2', '#shadow-button-2']]) @@ -705,7 +717,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with labelled shadow DOM', async () => { - await driver.get(`${addr}/external/shadow-dom.html`); + await driver.get(`${addr}/shadow-dom.html`); const results = await new AxeBuilder(driver) .include({ fromShadowDom: ['#shadow-root-1', '#shadow-button-1'] }) .exclude({ fromShadowDom: ['#shadow-root-2', '#shadow-button-2'] }) @@ -715,7 +727,7 @@ describe('@axe-core/webdriverjs', () => { }); it('with labelled iframe and shadow DOM', async () => { - await driver.get(`${addr}/external/shadow-frames.html`); + await driver.get(`${addr}/shadow-frames.html`); const { violations } = await new AxeBuilder(driver) .exclude({ fromFrames: [ @@ -737,7 +749,7 @@ describe('@axe-core/webdriverjs', () => { describe('callback()', () => { it('returns an error as the first argument', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -749,7 +761,7 @@ describe('@axe-core/webdriverjs', () => { }); it('returns as the second argument', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -771,7 +783,7 @@ describe('@axe-core/webdriverjs', () => { it('throws an error if window.open throws', async () => { const source = axeSource + windowOpenThrows; - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -786,7 +798,7 @@ describe('@axe-core/webdriverjs', () => { it('throws an error if axe.finishRun throws', async () => { const source = axeSource + finishRunThrows; - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -805,7 +817,7 @@ describe('@axe-core/webdriverjs', () => { it('throw an error with modified url', async () => { const source = axeSource + finishRunThrows; - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -828,7 +840,7 @@ describe('@axe-core/webdriverjs', () => { describe('setLegacyMode', () => { const runPartialThrows = `;axe.runPartial = () => { throw new Error("No runPartial")}`; it('runs legacy mode when used', async () => { - await driver.get(`${addr}/external/index.html`); + await driver.get(`${addr}/index.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axeSource + runPartialThrows) @@ -840,7 +852,7 @@ describe('@axe-core/webdriverjs', () => { }); it('prevents cross-origin frame testing', async () => { - await driver.get(`${addr}/external/cross-origin.html`); + await driver.get(`${addr}/cross-origin.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axeSource + runPartialThrows) @@ -857,7 +869,7 @@ describe('@axe-core/webdriverjs', () => { }); it('can be disabled again', async () => { - await driver.get(`${addr}/external/cross-origin.html`); + await driver.get(`${addr}/cross-origin.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver) @@ -877,7 +889,7 @@ describe('@axe-core/webdriverjs', () => { describe('browser functions', () => { it('serializes results', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); assert.notEqual(title, 'Error'); @@ -894,17 +906,12 @@ describe('@axe-core/webdriverjs', () => { describe('for versions without axe.runPartial', () => { let axe403Source: string; before(() => { - const axe403Path = path.resolve( - __dirname, - 'fixtures', - 'external', - 'axe-core@legacy.js' - ); + const axe403Path = path.join(fixturesPath, 'axe-core@legacy.js'); axe403Source = fs.readFileSync(axe403Path, 'utf8'); }); it('can run', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axe403Source) @@ -919,7 +926,7 @@ describe('@axe-core/webdriverjs', () => { it('throws if the top level errors', done => { driver - .get(`${addr}/external/crash.html`) + .get(`${addr}/crash.html`) .then(() => { return new AxeBuilder( driver, @@ -933,7 +940,7 @@ describe('@axe-core/webdriverjs', () => { }); it('can be configured', async () => { - await driver.get(`${addr}/external/nested-iframes.html`); + await driver.get(`${addr}/nested-iframes.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axe403Source) @@ -946,7 +953,7 @@ describe('@axe-core/webdriverjs', () => { }); it('reports frame-tested', async () => { - await driver.get(`${addr}/external/crash-parent.html`); + await driver.get(`${addr}/crash-parent.html`); const title = await driver.getTitle(); const results = await new AxeBuilder( @@ -964,7 +971,7 @@ describe('@axe-core/webdriverjs', () => { }); it('tests cross-origin pages', async () => { - await driver.get(`${addr}/external/cross-origin.html`); + await driver.get(`${addr}/cross-origin.html`); const title = await driver.getTitle(); const results = await new AxeBuilder(driver, axe403Source) diff --git a/packages/webdriverjs/test/fixtures/context.html b/packages/webdriverjs/test/fixtures/context.html deleted file mode 100644 index 61913366..00000000 --- a/packages/webdriverjs/test/fixtures/context.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - Context Test - - -

Context Test

-
include me
-
include me two
-
exclude me
-
exclude me two
- - - - diff --git a/packages/webdriverjs/test/fixtures/external b/packages/webdriverjs/test/fixtures/external deleted file mode 120000 index 817a08c2..00000000 --- a/packages/webdriverjs/test/fixtures/external +++ /dev/null @@ -1 +0,0 @@ -../../../../node_modules/axe-test-fixtures/fixtures \ No newline at end of file diff --git a/packages/webdriverjs/test/fixtures/iframe-one.html b/packages/webdriverjs/test/fixtures/iframe-one.html deleted file mode 100644 index ec224b9c..00000000 --- a/packages/webdriverjs/test/fixtures/iframe-one.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - iframe one - - -
-

iframe context test

- -
- - - - From 9180d8171209a2bb4e47facb9cf8d48bdcd61808 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Wed, 18 Oct 2023 15:07:44 -0600 Subject: [PATCH 2/2] fix esm tests --- packages/puppeteer/test/esmTest.mjs | 4 ++-- packages/webdriverio/test/esmTest.mjs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/puppeteer/test/esmTest.mjs b/packages/puppeteer/test/esmTest.mjs index dcd86e1a..f1d61ba2 100644 --- a/packages/puppeteer/test/esmTest.mjs +++ b/packages/puppeteer/test/esmTest.mjs @@ -3,6 +3,7 @@ import assert from 'assert'; import puppeteer from 'puppeteer'; import { fileURLToPath, pathToFileURL } from 'url'; import { join } from 'path'; +import { fixturesPath } from 'axe-test-fixtures'; const exportIsFunction = typeof defaultExport === 'function'; const exportIsSame = defaultExport === AxePuppeteer; @@ -18,8 +19,7 @@ if (process.env.CI) { } async function integrationTest() { - let path = fileURLToPath(new URL('.', import.meta.url)); - path = join(path, './fixtures/external/index.html'); + const path = join(fixturesPath, 'index.html'); const browser = await puppeteer.launch(options); const page = await browser.newPage(); diff --git a/packages/webdriverio/test/esmTest.mjs b/packages/webdriverio/test/esmTest.mjs index 0f680bad..d0544c51 100644 --- a/packages/webdriverio/test/esmTest.mjs +++ b/packages/webdriverio/test/esmTest.mjs @@ -3,13 +3,13 @@ import assert from 'assert'; import * as webdriverio from 'webdriverio'; import { fileURLToPath, pathToFileURL } from 'url'; import { join } from 'path'; +import { fixturesPath } from 'axe-test-fixtures'; 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, '../fixtures/external/index.html'); + const path = join(fixturesPath, 'index.html'); const options = { automationProtocol: 'devtools',