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

test(cli): add test to cover selenium-webdriver <4.17.0 #1038

Merged
merged 7 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
"@types/chromedriver": "^81.0.1",
"@types/mocha": "^10.0.0",
"@types/selenium-webdriver": "^4.1.5",
"@types/sinon": "^17.0.3",
"chai": "^4.3.6",
"execa": "5.1.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"rimraf": "^5.0.5",
"sinon": "^17.0.1",
"tempy": "^1.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/axe-test-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const testPages = async (
const currentUrl = urls[0].replace(/[,;]$/, '');

if (events?.onTestStart) {
events?.onTestStart(currentUrl);
events.onTestStart(currentUrl);
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
}

if (config.timer) {
Expand Down
7 changes: 1 addition & 6 deletions packages/cli/src/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { assert } from 'chai';
import tempy from 'tempy';
import { join } from 'path';
import { mkdirSync, writeFileSync, rmSync } from 'fs';
import { dependencies } from '../../package.json';
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
import * as utils from './utils';

describe('utils', () => {
Expand Down Expand Up @@ -83,11 +82,7 @@ describe('utils', () => {
writeFileSync(join(parentDirname, 'axe.js'), 'parent');

const cliDirname = join(tempDir, 'packages', 'cli');
const nodeModDirname = join(
cliDirname,
'node_modules',
'axe-core'
);
const nodeModDirname = join(cliDirname, 'node_modules', 'axe-core');
mkdirSync(nodeModDirname, { recursive: true });
writeFileSync(join(nodeModDirname, 'axe.js'), 'node modules');

Expand Down
23 changes: 21 additions & 2 deletions packages/cli/src/lib/webdriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { startDriver } from './webdriver';
import { WebDriver } from 'selenium-webdriver';
import chromedriver from 'chromedriver';
import chrome from 'selenium-webdriver/chrome';
import type { Options } from 'selenium-webdriver/chrome';
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
import path from 'path';
import { WebdriverConfigParams } from '../types';
import sinon from 'sinon';

describe('startDriver', () => {
let config: WebdriverConfigParams;
let browser: string;
Expand All @@ -22,7 +23,11 @@ describe('startDriver', () => {
});

afterEach(async () => {
await driver.quit();
// try catch required due to `chrome.options` being mocked with sinon
// and not properly creating a driver
try {
await driver.quit();
} catch (error) {}
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
});

it('creates a driver', async () => {
Expand Down Expand Up @@ -101,4 +106,18 @@ describe('startDriver', () => {
assert.isObject(timeoutValue);
assert.deepEqual(timeoutValue.script, 10000000);
});

it('invokes `options.headless()` on versions of selenium-webdriver < 4.17.0', async () => {
const stub = sinon.stub(chrome, 'Options').returns({
headless: () => {}
});

// try catch required due to `chrome.options` being mocked with sinon
// and not properly creating a driver
try {
driver = await startDriver(config);
} catch (error) {}
michael-siek marked this conversation as resolved.
Show resolved Hide resolved
assert.isTrue(stub.calledOnce);
stub.restore();
});
});
Loading