@axe-core/watcher 3.12.0 → 3.13.1-rc.bb823fcd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Controller.js +3 -3
- package/dist/Controller.js.map +1 -1
- package/dist/cypress.d.ts +1 -1
- package/dist/cypress.js +8 -5
- package/dist/cypress.js.map +1 -1
- package/dist/git.d.ts +2 -1
- package/dist/git.js +5 -4
- package/dist/git.js.map +1 -1
- package/dist/playwright.d.ts +1 -1
- package/dist/playwright.js +6 -4
- package/dist/playwright.js.map +1 -1
- package/dist/playwrightTest.js +7 -3
- package/dist/playwrightTest.js.map +1 -1
- package/dist/playwrightWrapping.d.ts +1 -1
- package/dist/playwrightWrapping.js +41 -41
- package/dist/playwrightWrapping.js.map +1 -1
- package/dist/puppeteer.d.ts +1 -1
- package/dist/puppeteer.js +7 -5
- package/dist/puppeteer.js.map +1 -1
- package/dist/puppeteerWrapping.d.ts +1 -1
- package/dist/puppeteerWrapping.js +45 -45
- package/dist/puppeteerWrapping.js.map +1 -1
- package/dist/sendResultsToServer.js +3 -43
- package/dist/sendResultsToServer.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.js +16 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/headlessNotSupportedError.d.ts +5 -0
- package/dist/utils/headlessNotSupportedError.js +17 -0
- package/dist/utils/headlessNotSupportedError.js.map +1 -0
- package/dist/utils/headlessNotSupportedError.test.d.ts +1 -0
- package/dist/utils/headlessNotSupportedError.test.js +21 -0
- package/dist/utils/headlessNotSupportedError.test.js.map +1 -0
- package/dist/utils/isValidExcludePattern.d.ts +2 -0
- package/dist/utils/isValidExcludePattern.js +10 -0
- package/dist/utils/isValidExcludePattern.js.map +1 -0
- package/dist/utils/isValidExcludePattern.test.d.ts +1 -0
- package/dist/utils/isValidExcludePattern.test.js +17 -0
- package/dist/utils/isValidExcludePattern.test.js.map +1 -0
- package/dist/utils/mergeChromeArgs.d.ts +12 -0
- package/dist/utils/mergeChromeArgs.js +73 -0
- package/dist/utils/mergeChromeArgs.js.map +1 -0
- package/dist/utils/mergeChromeArgs.test.d.ts +1 -0
- package/dist/utils/mergeChromeArgs.test.js +260 -0
- package/dist/utils/mergeChromeArgs.test.js.map +1 -0
- package/dist/utils/proxyHandlers.d.ts +12 -0
- package/dist/utils/proxyHandlers.js +62 -0
- package/dist/utils/proxyHandlers.js.map +1 -0
- package/dist/utils/proxyHandlers.test.d.ts +1 -0
- package/dist/utils/proxyHandlers.test.js +28 -0
- package/dist/utils/proxyHandlers.test.js.map +1 -0
- package/dist/utils/readVariables.d.ts +7 -0
- package/dist/utils/readVariables.js +17 -0
- package/dist/utils/readVariables.js.map +1 -0
- package/dist/utils/updateAutoAnalyze.d.ts +7 -0
- package/dist/utils/updateAutoAnalyze.js +20 -0
- package/dist/utils/updateAutoAnalyze.js.map +1 -0
- package/dist/utils/validateApiKey.d.ts +7 -0
- package/dist/utils/validateApiKey.js +34 -0
- package/dist/utils/validateApiKey.js.map +1 -0
- package/dist/utils/validateApiKey.test.d.ts +1 -0
- package/dist/utils/validateApiKey.test.js +66 -0
- package/dist/utils/validateApiKey.test.js.map +1 -0
- package/dist/utils/writeExtensionManifest.d.ts +7 -0
- package/dist/utils/writeExtensionManifest.js +18 -0
- package/dist/utils/writeExtensionManifest.js.map +1 -0
- package/dist/utils/writeVariables.d.ts +77 -0
- package/dist/utils/writeVariables.js +124 -0
- package/dist/utils/writeVariables.js.map +1 -0
- package/dist/utils/writeVariables.test.d.ts +1 -0
- package/dist/utils/writeVariables.test.js +220 -0
- package/dist/utils/writeVariables.test.js.map +1 -0
- package/dist/wdio.d.ts +1 -1
- package/dist/wdio.js +12 -9
- package/dist/wdio.js.map +1 -1
- package/dist/webdriver.d.ts +1 -1
- package/dist/webdriver.js +6 -4
- package/dist/webdriver.js.map +1 -1
- package/dist/webdriverWrapping.d.ts +1 -1
- package/dist/webdriverWrapping.js +16 -16
- package/dist/webdriverWrapping.js.map +1 -1
- package/extension/background.js +1 -1
- package/extension/content.js +1 -1
- package/package.json +2 -2
- package/dist/util.d.ts +0 -96
- package/dist/util.js +0 -243
- package/dist/util.js.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -20
- package/dist/utils/index.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
require("mocha");
|
|
7
|
+
const chai_1 = require("chai");
|
|
8
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
9
|
+
const proxyquire_1 = __importDefault(require("proxyquire"));
|
|
10
|
+
describe('validateApiKey', () => {
|
|
11
|
+
describe('when the server returns a non-200 response', () => {
|
|
12
|
+
it('throws an error', () => {
|
|
13
|
+
const requestStub = sinon_1.default
|
|
14
|
+
.stub()
|
|
15
|
+
.returns({ statusCode: 500, getBody: () => '{"error":"boom"}' });
|
|
16
|
+
const fn = (0, proxyquire_1.default)('./validateApiKey', {
|
|
17
|
+
'sync-request': requestStub
|
|
18
|
+
}).default;
|
|
19
|
+
chai_1.assert.throws(() => {
|
|
20
|
+
fn({ apiKey: 'abc', serverURL: 'http://localhost:3000' });
|
|
21
|
+
}, 'boom');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('when the server returns a 200 response', () => {
|
|
25
|
+
it('does not throw an error', () => {
|
|
26
|
+
const requestStub = sinon_1.default
|
|
27
|
+
.stub()
|
|
28
|
+
.returns({ statusCode: 200, getBody: () => '{}' });
|
|
29
|
+
const fn = (0, proxyquire_1.default)('./validateApiKey', {
|
|
30
|
+
'sync-request': requestStub
|
|
31
|
+
}).default;
|
|
32
|
+
chai_1.assert.doesNotThrow(() => {
|
|
33
|
+
fn({ apiKey: 'abc', serverURL: 'http://localhost:3000' });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('throws an error when a user provides an empty string as an API key', () => {
|
|
37
|
+
const requestStub = sinon_1.default
|
|
38
|
+
.stub()
|
|
39
|
+
.returns({ statusCode: 200, getBody: () => '{}' });
|
|
40
|
+
const fn = (0, proxyquire_1.default)('./validateApiKey', {
|
|
41
|
+
'sync-request': requestStub
|
|
42
|
+
}).default;
|
|
43
|
+
chai_1.assert.throws(() => {
|
|
44
|
+
fn({ apiKey: '', serverURL: 'http://localhost:3000' });
|
|
45
|
+
}, 'API key is required');
|
|
46
|
+
});
|
|
47
|
+
it('sends API key authentication request with correct format', () => {
|
|
48
|
+
const requestStub = sinon_1.default
|
|
49
|
+
.stub()
|
|
50
|
+
.returns({ statusCode: 200, getBody: () => '{}' });
|
|
51
|
+
const fn = (0, proxyquire_1.default)('./validateApiKey', {
|
|
52
|
+
'sync-request': requestStub
|
|
53
|
+
}).default;
|
|
54
|
+
const apiKey = 'test-api-key';
|
|
55
|
+
const serverURL = 'http://localhost:3000';
|
|
56
|
+
fn({ apiKey, serverURL });
|
|
57
|
+
(0, chai_1.assert)(requestStub.calledOnce, 'api-key authentication requested more than once');
|
|
58
|
+
const callArgs = requestStub.getCall(0).args;
|
|
59
|
+
const [method, url, options] = callArgs;
|
|
60
|
+
chai_1.assert.strictEqual(method, 'GET', 'Request method is not GET');
|
|
61
|
+
chai_1.assert.strictEqual(url, `${serverURL}/api/api-keys/validate/axe-devtools-watcher`, 'URL does not match');
|
|
62
|
+
chai_1.assert.strictEqual(options.headers['X-API-Key'], apiKey, 'X-API-Key header does not match');
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=validateApiKey.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateApiKey.test.js","sourceRoot":"","sources":["../../src/utils/validateApiKey.test.ts"],"names":[],"mappings":";;;;;AAAA,iBAAc;AACd,+B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AAM,CAAC,WAAW,CAChB,GAAG,EACH,GAAG,SAAS,6CAA6C,EACzD,oBAAoB,CACrB,CAAA;YACD,aAAM,CAAC,WAAW,CAChB,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAC5B,MAAM,EACN,iCAAiC,CAClC,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
/** Update the extension manifest file. */
|
|
10
|
+
function writeManifest({ all_frames, exclude_globs }) {
|
|
11
|
+
const manifestPath = path_1.default.join(constants_1.PATH_TO_EXTENSION, 'manifest.json');
|
|
12
|
+
const manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf-8'));
|
|
13
|
+
manifest.content_scripts[0].all_frames = all_frames;
|
|
14
|
+
manifest.content_scripts[0].exclude_globs = exclude_globs;
|
|
15
|
+
fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
16
|
+
}
|
|
17
|
+
exports.default = writeManifest;
|
|
18
|
+
//# sourceMappingURL=writeExtensionManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeExtensionManifest.js","sourceRoot":"","sources":["../../src/utils/writeExtensionManifest.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AACvB,4CAAmB;AACnB,2CAA+C;AAO/C,0CAA0C;AAC1C,SAAS,aAAa,CAAC,EACrB,UAAU,EACV,aAAa,EACO;IACpB,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,6BAAiB,EAAE,eAAe,CAAC,CAAA;IAClE,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IACnE,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,UAAU,CAAA;IACnD,QAAQ,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,aAAa,CAAA;IACzD,YAAE,CAAC,aAAa,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC;AAED,kBAAe,aAAa,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type axe from 'axe-core';
|
|
2
|
+
import { type RunOptions } from './validateAxeRunOptions';
|
|
3
|
+
export interface GitData {
|
|
4
|
+
git_branch?: string | null;
|
|
5
|
+
git_tag?: string | null;
|
|
6
|
+
git_default_branch?: string | null;
|
|
7
|
+
git_commit_message?: string | null;
|
|
8
|
+
git_commit_sha?: string | null;
|
|
9
|
+
git_commit_author?: string | null;
|
|
10
|
+
git_commit_email?: string | null;
|
|
11
|
+
git_url?: string | null;
|
|
12
|
+
git_is_dirty?: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface AxeConfiguration {
|
|
15
|
+
/** Your axe API key. */
|
|
16
|
+
apiKey: string;
|
|
17
|
+
/** Custom axe server URL. */
|
|
18
|
+
serverURL?: string;
|
|
19
|
+
/** Your session ID. */
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not to automatically run axe on the page when loaded and
|
|
23
|
+
* when changes are made.
|
|
24
|
+
*/
|
|
25
|
+
autoAnalyze?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* By default we'll scan the entire page. Provide a context object to limit
|
|
28
|
+
* the scope of the scan.
|
|
29
|
+
*
|
|
30
|
+
* @see https://www.deque.com/axe/core-documentation/api-documentation/#context-parameter
|
|
31
|
+
*/
|
|
32
|
+
runContext?: axe.ElementContext;
|
|
33
|
+
/**
|
|
34
|
+
* Provide options on how to run axe.
|
|
35
|
+
* - `rules`: Enable or disable rules using the enabled property
|
|
36
|
+
* - `runOnly`: Limit which rules are executed, based on names or tags
|
|
37
|
+
* - `ancestry`: Return CSS selector for elements, with all the element's ancestors
|
|
38
|
+
*
|
|
39
|
+
* @see https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter
|
|
40
|
+
*/
|
|
41
|
+
runOptions?: RunOptions;
|
|
42
|
+
/** Whether to take and send screenshots to the perf endpoint */
|
|
43
|
+
/** Run experimental advanced rules */
|
|
44
|
+
/**
|
|
45
|
+
* Exclude URLs from being scanned by axe-core/watcher by providing an array of minimatch patterns.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* excludeUrlPatterns: ['example.com', 'example.org']
|
|
50
|
+
* excludeUrlPatterns: ['example.com/*', 'example.org/*']
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
excludeUrlPatterns?: string[];
|
|
54
|
+
}
|
|
55
|
+
export interface Configuration {
|
|
56
|
+
axe: AxeConfiguration;
|
|
57
|
+
}
|
|
58
|
+
interface WriteVariablesParams extends AxeConfiguration {
|
|
59
|
+
cypress?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/** variables.json shape. */
|
|
62
|
+
export interface Variables {
|
|
63
|
+
api_key: string;
|
|
64
|
+
server_url: string;
|
|
65
|
+
auto_analyze: boolean;
|
|
66
|
+
cypress: boolean;
|
|
67
|
+
session_id?: string;
|
|
68
|
+
run_context: axe.ElementContext | null;
|
|
69
|
+
run_options: RunOptions | null;
|
|
70
|
+
git_data?: GitData;
|
|
71
|
+
take_screenshots?: boolean;
|
|
72
|
+
experimental_advanced_rules?: boolean;
|
|
73
|
+
exclude_url_patterns: string[] | null;
|
|
74
|
+
}
|
|
75
|
+
/** Write the user's settings to the disk, so the extension can load them. */
|
|
76
|
+
declare function writeVariables({ apiKey, autoAnalyze, cypress, serverURL, sessionId, runContext, runOptions, takeScreenshots, experimentalAdvancedRules, excludeUrlPatterns }: WriteVariablesParams): void;
|
|
77
|
+
export default writeVariables;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const git = __importStar(require("../git"));
|
|
30
|
+
const fs_1 = __importDefault(require("fs"));
|
|
31
|
+
const uuid_1 = require("uuid");
|
|
32
|
+
const constants_1 = require("./constants");
|
|
33
|
+
const validateAxeRunOptions_1 = require("./validateAxeRunOptions");
|
|
34
|
+
const createDebugger_1 = __importDefault(require("../createDebugger"));
|
|
35
|
+
const validateApiKey_1 = __importDefault(require("./validateApiKey"));
|
|
36
|
+
const validateAxeRunContext_1 = require("./validateAxeRunContext");
|
|
37
|
+
const isValidExcludePattern_1 = __importDefault(require("./isValidExcludePattern"));
|
|
38
|
+
const debugLogger = (0, createDebugger_1.default)('config:writeVariables');
|
|
39
|
+
/** Write the user's settings to the disk, so the extension can load them. */
|
|
40
|
+
function writeVariables({ apiKey, autoAnalyze, cypress, serverURL, sessionId, runContext, runOptions,
|
|
41
|
+
// @ts-expect-error Feature flag, not part of public type
|
|
42
|
+
takeScreenshots,
|
|
43
|
+
// @ts-expect-error Feature flag, not part of public type
|
|
44
|
+
experimentalAdvancedRules, excludeUrlPatterns }) {
|
|
45
|
+
// only log the properties if they are not undefined
|
|
46
|
+
debugLogger('Received configuration:', {
|
|
47
|
+
apiKey: '<redacted>',
|
|
48
|
+
...(autoAnalyze !== undefined && { autoAnalyze }),
|
|
49
|
+
...(serverURL !== undefined && { serverURL }),
|
|
50
|
+
...(sessionId !== undefined && { sessionId }),
|
|
51
|
+
...(runContext !== undefined && { runContext }),
|
|
52
|
+
...(runOptions !== undefined && { runOptions })
|
|
53
|
+
});
|
|
54
|
+
if (!serverURL) {
|
|
55
|
+
serverURL = constants_1.DEFAULT_SERVER_URL;
|
|
56
|
+
}
|
|
57
|
+
let urlString;
|
|
58
|
+
try {
|
|
59
|
+
urlString = new URL(serverURL).toString();
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
throw new Error(`Error when converting serverURL to URL. Ensure it is formatted properly: ${err}`);
|
|
63
|
+
}
|
|
64
|
+
if (typeof runContext !== 'undefined') {
|
|
65
|
+
(0, validateAxeRunContext_1.validateAxeRunContext)(runContext);
|
|
66
|
+
debugLogger('Validated runContext:', runContext);
|
|
67
|
+
}
|
|
68
|
+
if (typeof runOptions !== 'undefined') {
|
|
69
|
+
(0, validateAxeRunOptions_1.validateAxeRunOptions)(runOptions);
|
|
70
|
+
debugLogger('Validated runOptions:', runOptions);
|
|
71
|
+
}
|
|
72
|
+
const gitData = {};
|
|
73
|
+
const isGitRepo = git.isRepository();
|
|
74
|
+
if (isGitRepo) {
|
|
75
|
+
debugLogger('Is this a git project?', { isGitRepo });
|
|
76
|
+
gitData.git_branch = git.getBranchName();
|
|
77
|
+
gitData.git_tag = git.getTag();
|
|
78
|
+
gitData.git_default_branch = git.getDefaultBranchName();
|
|
79
|
+
gitData.git_url = git.getRemoteURL();
|
|
80
|
+
gitData.git_is_dirty = git.isDirty();
|
|
81
|
+
const info = git.getCommitInfo();
|
|
82
|
+
gitData.git_commit_sha = info === null || info === void 0 ? void 0 : info.hash;
|
|
83
|
+
gitData.git_commit_author = info === null || info === void 0 ? void 0 : info.author;
|
|
84
|
+
gitData.git_commit_email = info === null || info === void 0 ? void 0 : info.email;
|
|
85
|
+
gitData.git_commit_message = info === null || info === void 0 ? void 0 : info.message;
|
|
86
|
+
}
|
|
87
|
+
debugLogger('Validating API key');
|
|
88
|
+
(0, validateApiKey_1.default)({ apiKey, serverURL: urlString });
|
|
89
|
+
if (typeof autoAnalyze === 'undefined') {
|
|
90
|
+
autoAnalyze = true;
|
|
91
|
+
}
|
|
92
|
+
if (excludeUrlPatterns === null || excludeUrlPatterns === void 0 ? void 0 : excludeUrlPatterns.length) {
|
|
93
|
+
(0, isValidExcludePattern_1.default)(excludeUrlPatterns);
|
|
94
|
+
}
|
|
95
|
+
// When a custom session ID is not provided, attempt to read it from the filesystem.
|
|
96
|
+
// This enables multi-process/multi-browser test suites to all use the same session ID.
|
|
97
|
+
if (!sessionId && fs_1.default.existsSync(constants_1.PATH_TO_SESSION_FILE)) {
|
|
98
|
+
debugLogger('Reading session ID from file for WDIO Test Runner');
|
|
99
|
+
try {
|
|
100
|
+
const data = JSON.parse(fs_1.default.readFileSync(constants_1.PATH_TO_SESSION_FILE, 'utf8'));
|
|
101
|
+
sessionId = data.id;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw new Error(`Unable to read session configuration: ${error}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const variables = {
|
|
108
|
+
api_key: apiKey,
|
|
109
|
+
server_url: urlString,
|
|
110
|
+
/* Ensure only one session ID is created per test run if `sessionId` is not provided */
|
|
111
|
+
session_id: sessionId || (0, uuid_1.v4)(),
|
|
112
|
+
take_screenshots: !!takeScreenshots,
|
|
113
|
+
auto_analyze: !!autoAnalyze,
|
|
114
|
+
cypress: !!cypress,
|
|
115
|
+
experimental_advanced_rules: !!experimentalAdvancedRules,
|
|
116
|
+
run_context: runContext || null,
|
|
117
|
+
run_options: runOptions || null,
|
|
118
|
+
git_data: gitData,
|
|
119
|
+
exclude_url_patterns: excludeUrlPatterns || null
|
|
120
|
+
};
|
|
121
|
+
fs_1.default.writeFileSync(constants_1.PATH_TO_EXTENSION_VARIABLES, JSON.stringify(variables));
|
|
122
|
+
}
|
|
123
|
+
exports.default = writeVariables;
|
|
124
|
+
//# sourceMappingURL=writeVariables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeVariables.js","sourceRoot":"","sources":["../../src/utils/writeVariables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA6B;AAC7B,4CAAmB;AACnB,+BAAiC;AACjC,2CAIoB;AACpB,mEAAgF;AAChF,uEAA8C;AAC9C,sEAA6C;AAC7C,mEAA+D;AAC/D,oFAA2D;AAE3D,MAAM,WAAW,GAAG,IAAA,wBAAc,EAAC,uBAAuB,CAAC,CAAA;AAoF3D,6EAA6E;AAC7E,SAAS,cAAc,CAAC,EACtB,MAAM,EACN,WAAW,EACX,OAAO,EACP,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU;AACV,yDAAyD;AAC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,CAAC,CAAA;QAChE,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,gCAAoB,EAAE,MAAM,CAAC,CAAC,CAAA;YACtE,SAAS,GAAG,IAAI,CAAC,EAAY,CAAA;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,yCAAyC,KAAK,EAAE,CAAC,CAAA;QACnE,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAc;QAC3B,OAAO,EAAE,MAAM;QACf,UAAU,EAAE,SAAS;QACrB,uFAAuF;QACvF,UAAU,EAAE,SAAS,IAAI,IAAA,SAAI,GAAE;QAC/B,gBAAgB,EAAE,CAAC,CAAC,eAAe;QACnC,YAAY,EAAE,CAAC,CAAC,WAAW;QAC3B,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,2BAA2B,EAAE,CAAC,CAAC,yBAAyB;QACxD,WAAW,EAAE,UAAU,IAAI,IAAI;QAC/B,WAAW,EAAE,UAAU,IAAI,IAAI;QAC/B,QAAQ,EAAE,OAAO;QACjB,oBAAoB,EAAE,kBAAkB,IAAI,IAAI;KACjD,CAAA;IAED,YAAE,CAAC,aAAa,CAAC,uCAA2B,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED,kBAAe,cAAc,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'mocha';
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
require("mocha");
|
|
30
|
+
const chai_1 = require("chai");
|
|
31
|
+
const sinon_1 = __importDefault(require("sinon"));
|
|
32
|
+
const fs_1 = __importDefault(require("fs"));
|
|
33
|
+
const git = __importStar(require("../git"));
|
|
34
|
+
const validateApiKeyImp = __importStar(require("./validateApiKey"));
|
|
35
|
+
const writeVariables_1 = __importDefault(require("./writeVariables"));
|
|
36
|
+
describe('writeVariables', () => {
|
|
37
|
+
let validateApiKey;
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
validateApiKey = sinon_1.default.stub(validateApiKeyImp, 'default').returns();
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
sinon_1.default.restore();
|
|
43
|
+
});
|
|
44
|
+
describe('when validateApiKey=true', () => {
|
|
45
|
+
describe('when given an invalid API key', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
;
|
|
48
|
+
validateApiKey.throws(new Error('Invalid API key'));
|
|
49
|
+
});
|
|
50
|
+
it('should throw', () => {
|
|
51
|
+
chai_1.assert.throws(() => {
|
|
52
|
+
(0, writeVariables_1.default)({
|
|
53
|
+
apiKey: 'abc',
|
|
54
|
+
serverURL: 'http://localhost:3000',
|
|
55
|
+
// @ts-expect-error // Feature flag, not part of public type
|
|
56
|
+
takeScreenshots: true
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
describe('given `sessionId` variable', () => {
|
|
63
|
+
describe('when provided', () => {
|
|
64
|
+
it('should write to variables.json', () => {
|
|
65
|
+
const gitStub = sinon_1.default.stub(git);
|
|
66
|
+
gitStub.getBranchName.returns('main');
|
|
67
|
+
gitStub.getDefaultBranchName.returns('main');
|
|
68
|
+
gitStub.getRemoteURL.returns('url');
|
|
69
|
+
gitStub.isRepository.returns(true);
|
|
70
|
+
gitStub.isDirty.returns(false);
|
|
71
|
+
gitStub.getTag.returns(null);
|
|
72
|
+
gitStub.getCommitInfo.returns({
|
|
73
|
+
message: 'message',
|
|
74
|
+
author: 'author',
|
|
75
|
+
email: 'email',
|
|
76
|
+
hash: 'hash'
|
|
77
|
+
});
|
|
78
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
79
|
+
(0, writeVariables_1.default)({
|
|
80
|
+
apiKey: 'abc',
|
|
81
|
+
serverURL: 'http://localhost:3000/',
|
|
82
|
+
sessionId: '123',
|
|
83
|
+
// @ts-expect-error // Feature flag, not part of public type
|
|
84
|
+
takeScreenshots: true,
|
|
85
|
+
experimentalAdvancedRules: true
|
|
86
|
+
});
|
|
87
|
+
chai_1.assert.isTrue(writeFileSync.calledOnce);
|
|
88
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
89
|
+
chai_1.assert.deepEqual(stored, {
|
|
90
|
+
api_key: 'abc',
|
|
91
|
+
server_url: 'http://localhost:3000/',
|
|
92
|
+
auto_analyze: true,
|
|
93
|
+
session_id: '123',
|
|
94
|
+
cypress: false,
|
|
95
|
+
take_screenshots: true,
|
|
96
|
+
experimental_advanced_rules: true,
|
|
97
|
+
run_context: null,
|
|
98
|
+
run_options: null,
|
|
99
|
+
exclude_url_patterns: null,
|
|
100
|
+
git_data: {
|
|
101
|
+
git_branch: 'main',
|
|
102
|
+
git_default_branch: 'main',
|
|
103
|
+
git_url: 'url',
|
|
104
|
+
git_tag: null,
|
|
105
|
+
git_commit_message: 'message',
|
|
106
|
+
git_commit_author: 'author',
|
|
107
|
+
git_commit_email: 'email',
|
|
108
|
+
git_commit_sha: 'hash',
|
|
109
|
+
git_is_dirty: false
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('when not provided', () => {
|
|
115
|
+
it('creates a session ID and writes it to variables.json', () => {
|
|
116
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
117
|
+
(0, writeVariables_1.default)({
|
|
118
|
+
apiKey: 'abc'
|
|
119
|
+
});
|
|
120
|
+
chai_1.assert.isTrue(writeFileSync.calledOnce);
|
|
121
|
+
const variables = JSON.parse(writeFileSync.args[0][1]);
|
|
122
|
+
chai_1.assert.exists(variables.session_id);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe(`runContext`, () => {
|
|
127
|
+
describe('when provided', () => {
|
|
128
|
+
it('should write to variables.json', () => {
|
|
129
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
130
|
+
(0, writeVariables_1.default)({
|
|
131
|
+
apiKey: 'abc',
|
|
132
|
+
runContext: { include: 'foo', exclude: 'bar' }
|
|
133
|
+
});
|
|
134
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
135
|
+
const runContext = stored.run_context;
|
|
136
|
+
chai_1.assert.isDefined(runContext);
|
|
137
|
+
chai_1.assert.deepEqual(runContext, { include: 'foo', exclude: 'bar' });
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
describe('when not provided', () => {
|
|
141
|
+
it('should not write to variables.json', () => {
|
|
142
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
143
|
+
(0, writeVariables_1.default)({
|
|
144
|
+
apiKey: 'abc'
|
|
145
|
+
});
|
|
146
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
147
|
+
chai_1.assert.isNull(stored.run_context);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe(`runOptions`, () => {
|
|
152
|
+
describe('when provided', () => {
|
|
153
|
+
it('should write to variables.json', () => {
|
|
154
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
155
|
+
(0, writeVariables_1.default)({
|
|
156
|
+
apiKey: 'abc',
|
|
157
|
+
runOptions: {
|
|
158
|
+
ancestry: true,
|
|
159
|
+
rules: { 'color-contrast': { enabled: false } },
|
|
160
|
+
runOnly: { type: 'rules', values: ['color-contrast'] }
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
164
|
+
const runOptions = stored.run_options;
|
|
165
|
+
chai_1.assert.isDefined(runOptions);
|
|
166
|
+
chai_1.assert.deepEqual(runOptions, {
|
|
167
|
+
ancestry: true,
|
|
168
|
+
rules: { 'color-contrast': { enabled: false } },
|
|
169
|
+
runOnly: { type: 'rules', values: ['color-contrast'] }
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('when not provided', () => {
|
|
174
|
+
it('should not write to variables.json', () => {
|
|
175
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
176
|
+
(0, writeVariables_1.default)({
|
|
177
|
+
apiKey: 'abc'
|
|
178
|
+
});
|
|
179
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
180
|
+
chai_1.assert.isNull(stored.run_options);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
describe(`excludeUrlPatterns`, () => {
|
|
185
|
+
describe('when provided', () => {
|
|
186
|
+
it('should write to variables.json', () => {
|
|
187
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
188
|
+
(0, writeVariables_1.default)({
|
|
189
|
+
apiKey: 'abc',
|
|
190
|
+
excludeUrlPatterns: ['foo', 'bar']
|
|
191
|
+
});
|
|
192
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
193
|
+
const excludeUrlPatterns = stored.exclude_url_patterns;
|
|
194
|
+
chai_1.assert.isDefined(excludeUrlPatterns);
|
|
195
|
+
chai_1.assert.deepEqual(excludeUrlPatterns, ['foo', 'bar']);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('when not provided', () => {
|
|
199
|
+
it('should not write to variables.json', () => {
|
|
200
|
+
const writeFileSync = sinon_1.default.stub(fs_1.default, 'writeFileSync');
|
|
201
|
+
(0, writeVariables_1.default)({
|
|
202
|
+
apiKey: 'abc'
|
|
203
|
+
});
|
|
204
|
+
const stored = JSON.parse(writeFileSync.args[0][1]);
|
|
205
|
+
chai_1.assert.isNull(stored.exclude_url_patterns);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
describe('throws when invalid', () => {
|
|
209
|
+
it('should throw', () => {
|
|
210
|
+
chai_1.assert.throws(() => {
|
|
211
|
+
(0, writeVariables_1.default)({
|
|
212
|
+
apiKey: 'abc',
|
|
213
|
+
excludeUrlPatterns: ['foo', 'bar', 1]
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
//# sourceMappingURL=writeVariables.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeVariables.test.js","sourceRoot":"","sources":["../../src/utils/writ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M,CAAC,GAAG,EAAE;oBACjB,IAAA,wBAAc,EAAC;wBACb,MAAM,EAAE,KAAK;wBACb,kBAAkB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAQ;qBAC7C,CAAC,CAAA;gBACJ,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/wdio.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Options } from '@wdio/types';
|
|
2
2
|
import type { Browser, BrowserCommandsType, ElementCommandsType, RemoteOptions } from 'webdriverio';
|
|
3
|
-
import { type Configuration } from './util';
|
|
4
3
|
import Controller from './Controller';
|
|
4
|
+
import { type Configuration } from './utils/writeVariables';
|
|
5
5
|
type Options = RemoteOptions & Configuration;
|
|
6
6
|
/**
|
|
7
7
|
* Creates a WebDriverIO config that uses axe extension
|
package/dist/wdio.js
CHANGED
|
@@ -7,8 +7,11 @@ exports.wrapWdio = exports.WRAPPED_ELEMENT_METHODS = exports.WRAPPED_BROWSER_MET
|
|
|
7
7
|
exports.wdioConfig = wdioConfig;
|
|
8
8
|
exports.wdioTestRunner = wdioTestRunner;
|
|
9
9
|
const fs_1 = __importDefault(require("fs"));
|
|
10
|
-
const util_1 = require("./util");
|
|
11
10
|
const Controller_1 = __importDefault(require("./Controller"));
|
|
11
|
+
const writeVariables_1 = __importDefault(require("./utils/writeVariables"));
|
|
12
|
+
const constants_1 = require("./utils/constants");
|
|
13
|
+
const headlessNotSupportedError_1 = require("./utils/headlessNotSupportedError");
|
|
14
|
+
const mergeChromeArgs_1 = __importDefault(require("./utils/mergeChromeArgs"));
|
|
12
15
|
const noop = () => {
|
|
13
16
|
// Nothing.
|
|
14
17
|
};
|
|
@@ -19,13 +22,13 @@ const noop = () => {
|
|
|
19
22
|
*/
|
|
20
23
|
function wdioConfig({ axe, ...options }) {
|
|
21
24
|
var _a;
|
|
22
|
-
(0,
|
|
25
|
+
(0, writeVariables_1.default)(axe);
|
|
23
26
|
// Disable eslint. Wdio doesn't export this property even though they support it.
|
|
24
27
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
25
28
|
const chromeOpts = ((_a = options.capabilities) === null || _a === void 0 ? void 0 : _a['goog:chromeOptions']) || {};
|
|
26
29
|
const args = chromeOpts.args || [];
|
|
27
30
|
if (['headless', '--headless'].some(flag => args.includes(flag))) {
|
|
28
|
-
throw new
|
|
31
|
+
throw new headlessNotSupportedError_1.HeadlessNotSupportedError(`In WebdriverIO, use "headless=new" instead of "headless" in the "args" property of your "${CHROME_OPTIONS}" browser capability configuration.`);
|
|
29
32
|
}
|
|
30
33
|
return {
|
|
31
34
|
...options,
|
|
@@ -35,7 +38,7 @@ function wdioConfig({ axe, ...options }) {
|
|
|
35
38
|
'goog:chromeOptions': {
|
|
36
39
|
// Note: wdio v7 passes `--disable-extensions` as one of the default args.
|
|
37
40
|
// we need to make sure we still append our args to the list.
|
|
38
|
-
args: (0,
|
|
41
|
+
args: (0, mergeChromeArgs_1.default)(args, { disableOtherExtensions: true })
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
};
|
|
@@ -52,7 +55,7 @@ function wdioTestRunner(...params) {
|
|
|
52
55
|
;
|
|
53
56
|
[axe, config] = params;
|
|
54
57
|
}
|
|
55
|
-
(0,
|
|
58
|
+
(0, writeVariables_1.default)(axe);
|
|
56
59
|
const capabilities = config.capabilities || [
|
|
57
60
|
{ [CHROME_OPTIONS]: { args: [] } }
|
|
58
61
|
];
|
|
@@ -63,23 +66,23 @@ function wdioTestRunner(...params) {
|
|
|
63
66
|
chromeOpts.args = chromeOpts.args || [];
|
|
64
67
|
const args = chromeOpts.args;
|
|
65
68
|
if (['headless', '--headless'].some(flag => args.includes(flag))) {
|
|
66
|
-
throw new
|
|
69
|
+
throw new headlessNotSupportedError_1.HeadlessNotSupportedError(`In WebdriverIO, use "headless=new" instead of "headless" in the "args" property of your "${CHROME_OPTIONS}" browser capability configuration.`);
|
|
67
70
|
}
|
|
68
|
-
chromeOpts.args = (0,
|
|
71
|
+
chromeOpts.args = (0, mergeChromeArgs_1.default)(args, { disableOtherExtensions: false });
|
|
69
72
|
const { onPrepare = noop, onComplete = noop } = config;
|
|
70
73
|
return {
|
|
71
74
|
...config,
|
|
72
75
|
capabilities,
|
|
73
76
|
onPrepare(...prepareParams) {
|
|
74
77
|
const sessionId = axe.sessionId;
|
|
75
|
-
fs_1.default.writeFileSync(
|
|
78
|
+
fs_1.default.writeFileSync(constants_1.PATH_TO_SESSION_FILE, JSON.stringify({ id: sessionId }));
|
|
76
79
|
// @ts-expect-error TS is angry about calling this ¯\_(ツ)_/¯
|
|
77
80
|
return onPrepare(...prepareParams);
|
|
78
81
|
},
|
|
79
82
|
// Remove the file, preventing other sessions from reusing its ID.
|
|
80
83
|
onComplete(...completeParams) {
|
|
81
84
|
try {
|
|
82
|
-
fs_1.default.unlinkSync(
|
|
85
|
+
fs_1.default.unlinkSync(constants_1.PATH_TO_SESSION_FILE);
|
|
83
86
|
}
|
|
84
87
|
catch (_a) {
|
|
85
88
|
// Oh well.
|