@axe-core/watcher 0.0.0 → 0.0.1-next.057bf3d9

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.
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __importDefault = (this && this.__importDefault) || function (mod) {
76
+ return (mod && mod.__esModule) ? mod : { "default": mod };
77
+ };
78
+ Object.defineProperty(exports, "__esModule", { value: true });
79
+ exports.PuppeteerController = exports.puppeteerConfig = void 0;
80
+ var util_1 = require("./util");
81
+ var Controller_1 = __importDefault(require("./Controller"));
82
+ /**
83
+ * Creates a Puppeteer config that uses axe extension.
84
+ *
85
+ * @param opts Config to extend
86
+ */
87
+ function puppeteerConfig(opts) {
88
+ var axe = opts.axe, config = __rest(opts, ["axe"]);
89
+ var _a = config.args, args = _a === void 0 ? [] : _a;
90
+ (0, util_1.writeVariables)(axe);
91
+ if (config.headless) {
92
+ throw new util_1.HeadlessNotSupportedError();
93
+ }
94
+ args = args.concat(util_1.extensionArgs);
95
+ return __assign(__assign({}, config), { headless: false, args: args });
96
+ }
97
+ exports.puppeteerConfig = puppeteerConfig;
98
+ var PuppeteerController = /** @class */ (function (_super) {
99
+ __extends(PuppeteerController, _super);
100
+ function PuppeteerController(driver) {
101
+ var _this = _super.call(this) || this;
102
+ _this.driver = driver;
103
+ return _this;
104
+ }
105
+ PuppeteerController.prototype.executeScript = function (fn) {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0: return [4 /*yield*/, this.driver.evaluate(fn)];
110
+ case 1:
111
+ _a.sent();
112
+ return [2 /*return*/];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ return PuppeteerController;
118
+ }(Controller_1.default));
119
+ exports.PuppeteerController = PuppeteerController;
120
+ //# sourceMappingURL=puppeteer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"puppeteer.js","sourceRoot":"","sources":["../src/puppeteer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,+BAKe;AACf,4DAAqC;AAMrC;;;;GAIG;AAEH,SAAgB,eAAe,CAAC,IAA6B;IACnD,IAAA,GAAG,GAAgB,IAAI,IAApB,EAAK,MAAM,UAAK,IAAI,EAAzB,OAAkB,CAAF,CAAS;IACzB,IAAA,KAAc,MAAM,KAAX,EAAT,IAAI,mBAAG,EAAE,KAAA,CAAW;IAC1B,IAAA,qBAAc,EAAC,GAAG,CAAC,CAAA;IAEnB,IAAI,MAAM,CAAC,QAAQ,EAAE;QACnB,MAAM,IAAI,gCAAyB,EAAE,CAAA;KACtC;IAED,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAa,CAAC,CAAA;IAEjC,6BACK,MAAM,KACT,QAAQ,EAAE,KAAK,EACf,IAAI,MAAA,IACL;AACH,CAAC;AAhBD,0CAgBC;AAED;IAAyC,uCAAU;IAGjD,6BAAY,MAAY;QAAxB,YACE,iBAAO,SAER;QADC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAA;;IACtB,CAAC;IAEe,2CAAa,GAA7B,UACE,EAAkC;;;;4BAElC,qBAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAA;;wBAA9B,SAA8B,CAAA;;;;;KAC/B;IACH,0BAAC;AAAD,CAAC,AAbD,CAAyC,oBAAU,GAalD;AAbY,kDAAmB"}
package/dist/util.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ export declare const PATH_TO_EXTENSION: string;
2
+ export declare const DEFAULT_SERVER_URL = "https://axe.deque.com/";
3
+ export declare const PATH_TO_SESSION_FILE: string;
4
+ export declare const PATH_TO_EXTENSION_VARIABLES: string;
5
+ export declare const extensionArgs: readonly [`--disable-extensions-except=${string}`, `--load-extension=${string}`];
6
+ export declare class HeadlessNotSupportedError extends Error {
7
+ name: string;
8
+ constructor();
9
+ }
10
+ export interface Configuration {
11
+ axe: {
12
+ /** Your axe API key. */
13
+ apiKey: string;
14
+ /** Custom axe server URL. */
15
+ serverURL?: string;
16
+ /** Your session ID. */
17
+ sessionId?: string;
18
+ /**
19
+ * Whether or not to automatically run axe on the page when loaded and
20
+ * when changes are made.
21
+ */
22
+ autoAnalyze?: boolean;
23
+ };
24
+ }
25
+ interface WriteVariablesParams {
26
+ apiKey: string;
27
+ serverURL?: string;
28
+ sessionId?: string;
29
+ autoAnalyze?: boolean;
30
+ }
31
+ /** Write the user's settings to the disk, so the extension can load them. */
32
+ export declare function writeVariables({ apiKey, serverURL, sessionId, autoAnalyze }: WriteVariablesParams): void;
33
+ interface WriteManifestParams {
34
+ all_frames: boolean;
35
+ exclude_globs: string[];
36
+ }
37
+ /** Update the extension manifest file. */
38
+ export declare function writeManifest({ all_frames, exclude_globs }: WriteManifestParams): void;
39
+ export {};
package/dist/util.js ADDED
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.writeManifest = exports.writeVariables = exports.HeadlessNotSupportedError = exports.extensionArgs = exports.PATH_TO_EXTENSION_VARIABLES = exports.PATH_TO_SESSION_FILE = exports.DEFAULT_SERVER_URL = exports.PATH_TO_EXTENSION = void 0;
22
+ var fs_1 = __importDefault(require("fs"));
23
+ var path_1 = __importDefault(require("path"));
24
+ var os_1 = __importDefault(require("os"));
25
+ exports.PATH_TO_EXTENSION = path_1.default.join(__dirname, '..', 'extension');
26
+ exports.DEFAULT_SERVER_URL = 'https://axe.deque.com/';
27
+ exports.PATH_TO_SESSION_FILE = path_1.default.join(os_1.default.tmpdir(), 'axe-watcher-session.json');
28
+ exports.PATH_TO_EXTENSION_VARIABLES = path_1.default.join(exports.PATH_TO_EXTENSION, 'variables.json');
29
+ exports.extensionArgs = [
30
+ "--disable-extensions-except=".concat(exports.PATH_TO_EXTENSION),
31
+ "--load-extension=".concat(exports.PATH_TO_EXTENSION)
32
+ ];
33
+ var HeadlessNotSupportedError = /** @class */ (function (_super) {
34
+ __extends(HeadlessNotSupportedError, _super);
35
+ function HeadlessNotSupportedError() {
36
+ var _this = _super.call(this, 'Cannot use extension while headless.') || this;
37
+ _this.name = 'HeadlessNotSupportedError';
38
+ return _this;
39
+ }
40
+ return HeadlessNotSupportedError;
41
+ }(Error));
42
+ exports.HeadlessNotSupportedError = HeadlessNotSupportedError;
43
+ /** Write the user's settings to the disk, so the extension can load them. */
44
+ function writeVariables(_a) {
45
+ var apiKey = _a.apiKey, serverURL = _a.serverURL, sessionId = _a.sessionId, autoAnalyze = _a.autoAnalyze;
46
+ if (!serverURL) {
47
+ serverURL = exports.DEFAULT_SERVER_URL;
48
+ }
49
+ var urlString;
50
+ try {
51
+ urlString = new URL(serverURL).toString();
52
+ }
53
+ catch (err) {
54
+ throw new Error("Error when converting serverURL to URL. Ensure it is formatted properly: ".concat(err));
55
+ }
56
+ if (typeof autoAnalyze === 'undefined') {
57
+ autoAnalyze = true;
58
+ }
59
+ // When a custom session ID is not provided, attempt to read it from the filesystem.
60
+ // This enables multi-process/multi-browser test suites to all use the same session ID.
61
+ if (!sessionId && fs_1.default.existsSync(exports.PATH_TO_SESSION_FILE)) {
62
+ try {
63
+ var data = JSON.parse(fs_1.default.readFileSync(exports.PATH_TO_SESSION_FILE, 'utf8'));
64
+ sessionId = data.id;
65
+ }
66
+ catch (error) {
67
+ throw new Error("Unable to read session configuration: ".concat(error));
68
+ }
69
+ }
70
+ fs_1.default.writeFileSync(exports.PATH_TO_EXTENSION_VARIABLES, JSON.stringify({
71
+ api_key: apiKey,
72
+ server_url: urlString,
73
+ session_id: sessionId,
74
+ auto_analyze: !!autoAnalyze
75
+ }));
76
+ }
77
+ exports.writeVariables = writeVariables;
78
+ /** Update the extension manifest file. */
79
+ function writeManifest(_a) {
80
+ var all_frames = _a.all_frames, exclude_globs = _a.exclude_globs;
81
+ var manifestPath = path_1.default.join(exports.PATH_TO_EXTENSION, 'manifest.json');
82
+ var manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf-8'));
83
+ manifest.content_scripts[0].all_frames = all_frames;
84
+ manifest.content_scripts[0].exclude_globs = exclude_globs;
85
+ fs_1.default.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
86
+ }
87
+ exports.writeManifest = writeManifest;
88
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,0CAAmB;AACnB,8CAAuB;AACvB,0CAAmB;AAEN,QAAA,iBAAiB,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;AAC3D,QAAA,kBAAkB,GAAG,wBAAwB,CAAA;AAC7C,QAAA,oBAAoB,GAAG,cAAI,CAAC,IAAI,CAC3C,YAAE,CAAC,MAAM,EAAE,EACX,0BAA0B,CAC3B,CAAA;AACY,QAAA,2BAA2B,GAAG,cAAI,CAAC,IAAI,CAClD,yBAAiB,EACjB,gBAAgB,CACjB,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,sCAA+B,yBAAiB,CAAE;IAClD,2BAAoB,yBAAiB,CAAE;CAC/B,CAAA;AAEV;IAA+C,6CAAK;IAGlD;QAAA,YACE,kBAAM,sCAAsC,CAAC,SAC9C;QAJM,UAAI,GAAG,2BAA2B,CAA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,IAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,yBAAiB,EAAE,eAAe,CAAC,CAAA;IAClE,IAAM,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;AATD,sCASC"}
package/dist/wdio.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Options } from '@wdio/types';
2
+ import { Configuration } from './util';
3
+ import Controller from './Controller';
4
+ interface Browser {
5
+ executeAsyncScript(script: string, args: object[]): void;
6
+ }
7
+ interface WdioArg extends Configuration {
8
+ options?: Options.WebDriver;
9
+ }
10
+ /**
11
+ * Creates a WebDriverIO config that uses axe extension
12
+ *
13
+ * @param arg Config to extend
14
+ */
15
+ export declare function wdioConfig(arg: WdioArg): Options.WebDriver;
16
+ export declare function wdioTestRunner(axe: Configuration['axe'], config: Options.Testrunner): Options.Testrunner;
17
+ export declare class WdioController extends Controller {
18
+ private driver;
19
+ constructor(driver: Browser);
20
+ protected executeScript(fn: string | (() => Promise<void>)): Promise<void>;
21
+ }
22
+ export {};
package/dist/wdio.js ADDED
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __importDefault = (this && this.__importDefault) || function (mod) {
65
+ return (mod && mod.__esModule) ? mod : { "default": mod };
66
+ };
67
+ Object.defineProperty(exports, "__esModule", { value: true });
68
+ exports.WdioController = exports.wdioTestRunner = exports.wdioConfig = void 0;
69
+ var util_1 = require("./util");
70
+ var Controller_1 = __importDefault(require("./Controller"));
71
+ /**
72
+ * Creates a WebDriverIO config that uses axe extension
73
+ *
74
+ * @param arg Config to extend
75
+ */
76
+ function wdioConfig(arg) {
77
+ var _a, _b, _c;
78
+ (0, util_1.writeVariables)(arg.axe);
79
+ // Disable eslint. Wdio doesn't export this property even though they support it.
80
+ /* eslint-disable @typescript-eslint/no-explicit-any */
81
+ var chromeOpts = ((_b = (_a = arg.options) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b['goog:chromeOptions']) || {};
82
+ var args = chromeOpts.args || [];
83
+ if (args.includes('--headless')) {
84
+ throw new util_1.HeadlessNotSupportedError();
85
+ }
86
+ return __assign(__assign({}, arg.options), { capabilities: __assign(__assign({}, (_c = arg.options) === null || _c === void 0 ? void 0 : _c.capabilities), { browserName: 'chrome', 'goog:chromeOptions': {
87
+ args: util_1.extensionArgs.concat(args)
88
+ } }) });
89
+ }
90
+ exports.wdioConfig = wdioConfig;
91
+ // Configuration.axe is not a namespace, therefore have to use ['axe'] instead of .axe
92
+ function wdioTestRunner(axe, config) {
93
+ (0, util_1.writeVariables)(axe);
94
+ var capabilities = config.capabilities || [
95
+ {
96
+ 'goog:chromeOptions': {
97
+ args: []
98
+ }
99
+ }
100
+ ];
101
+ // has to be any because type is not exported
102
+ var firstCapability = capabilities[0];
103
+ firstCapability['goog:chromeOptions'] =
104
+ firstCapability['goog:chromeOptions'] || {};
105
+ var chromeOpts = firstCapability['goog:chromeOptions'];
106
+ chromeOpts.args = chromeOpts.args || [];
107
+ var args = chromeOpts.args;
108
+ if (args.includes('--headless')) {
109
+ throw new util_1.HeadlessNotSupportedError();
110
+ }
111
+ chromeOpts.args = util_1.extensionArgs.concat(args);
112
+ return __assign(__assign({}, config), { capabilities: capabilities });
113
+ }
114
+ exports.wdioTestRunner = wdioTestRunner;
115
+ var WdioController = /** @class */ (function (_super) {
116
+ __extends(WdioController, _super);
117
+ function WdioController(driver) {
118
+ var _this = _super.call(this) || this;
119
+ _this.driver = driver;
120
+ return _this;
121
+ }
122
+ WdioController.prototype.executeScript = function (fn) {
123
+ return __awaiter(this, void 0, void 0, function () {
124
+ var script;
125
+ return __generator(this, function (_a) {
126
+ switch (_a.label) {
127
+ case 0:
128
+ script = "\n const callback = arguments[arguments.length - 1];\n Promise.resolve()\n .then(".concat(fn, ")\n .then(callback);\n ");
129
+ return [4 /*yield*/, this.driver.executeAsyncScript(script, [])];
130
+ case 1:
131
+ _a.sent();
132
+ return [2 /*return*/];
133
+ }
134
+ });
135
+ });
136
+ };
137
+ return WdioController;
138
+ }(Controller_1.default));
139
+ exports.WdioController = WdioController;
140
+ //# sourceMappingURL=wdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wdio.js","sourceRoot":"","sources":["../src/wdio.ts"],"names":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I,IAAI,EAAE,CAAA;IACvC,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;IAE5B,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;QAC/B,MAAM,IAAI,gCAAyB,EAAE,CAAA;KACtC;IAED,UAAU,CAAC,IAAI,GAAG,oBAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAE5C,6BACK,MAAM,KACT,YAAY,cAAA,IACb;AACH,CAAC;AA9BD,wCA8BC;AAED;IAAoC,kCAAU;IAG5C,wBAAY,MAAe;QAA3B,YACE,iBAAO,SAER;QADC,KAAI,CAAC,MAAM,GAAG,MAAM,CAAA;;IACtB,CAAC;IAEe,sCAAa,GAA7B,UACE,EAAkC;;;;;;wBAE5B,MAAM,GAAG,4GAGH,EAAE,sCAEb,CAAA;wBACD,qBAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,EAAE,EAAE,CAAC,EAAA;;wBAAhD,SAAgD,CAAA;;;;;KACjD;IACH,qBAAC;AAAD,CAAC,AAnBD,CAAoC,oBAAU,GAmB7C;AAnBY,wCAAc"}
@@ -0,0 +1,19 @@
1
+ import type { WebDriver } from 'selenium-webdriver';
2
+ import type { Options } from 'selenium-webdriver/chrome';
3
+ import { Configuration } from './util';
4
+ import Controller from './Controller';
5
+ interface WebDriverArgs extends Configuration {
6
+ options?: Options;
7
+ }
8
+ /**
9
+ * Creates a Selenium config that uses axe extension
10
+ *
11
+ * @param arg Config to extend
12
+ */
13
+ export declare function webdriverConfig(arg: WebDriverArgs): Options;
14
+ export declare class WebdriverController extends Controller {
15
+ private driver;
16
+ constructor(driver: WebDriver);
17
+ protected executeScript(fn: string | (() => Promise<void>)): Promise<void>;
18
+ }
19
+ export {};
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (_) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ var __importDefault = (this && this.__importDefault) || function (mod) {
54
+ return (mod && mod.__esModule) ? mod : { "default": mod };
55
+ };
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ exports.WebdriverController = exports.webdriverConfig = void 0;
58
+ var util_1 = require("./util");
59
+ var Controller_1 = __importDefault(require("./Controller"));
60
+ /**
61
+ * Creates a Selenium config that uses axe extension
62
+ *
63
+ * @param arg Config to extend
64
+ */
65
+ function webdriverConfig(arg) {
66
+ var _a, _b;
67
+ // Lazily require `chrome` to avoid Puppeteer/Playwright/WDIO users from needing `selenium-webdriver` installed.
68
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
69
+ var chrome = require('selenium-webdriver/chrome');
70
+ var axe = arg.axe, options = arg.options;
71
+ (0, util_1.writeVariables)(axe);
72
+ var opts = options ? options : new chrome.Options();
73
+ opts.addArguments.apply(opts, util_1.extensionArgs);
74
+ // Note: fragile, but selenium does not give us a real way to check this
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ if ((_b = (_a = opts === null || opts === void 0 ? void 0 : opts.options_) === null || _a === void 0 ? void 0 : _a.args) === null || _b === void 0 ? void 0 : _b.includes('headless')) {
77
+ throw new util_1.HeadlessNotSupportedError();
78
+ }
79
+ return opts;
80
+ }
81
+ exports.webdriverConfig = webdriverConfig;
82
+ var WebdriverController = /** @class */ (function (_super) {
83
+ __extends(WebdriverController, _super);
84
+ function WebdriverController(driver) {
85
+ var _this = _super.call(this) || this;
86
+ _this.driver = driver;
87
+ return _this;
88
+ }
89
+ WebdriverController.prototype.executeScript = function (fn) {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var script;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0:
95
+ script = "\n const callback = arguments[arguments.length - 1];\n Promise.resolve()\n .then(".concat(fn, ")\n .then(callback);\n ");
96
+ return [4 /*yield*/, this.driver.executeAsyncScript(script)];
97
+ case 1:
98
+ _a.sent();
99
+ return [2 /*return*/];
100
+ }
101
+ });
102
+ });
103
+ };
104
+ return WebdriverController;
105
+ }(Controller_1.default));
106
+ exports.WebdriverController = WebdriverController;
107
+ //# sourceMappingURL=webdriver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webdriver.js","sourceRoot":"","sources":["../src/webdriver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,+BAKe;AACf,4DAAqC;AAMrC;;;;GAIG;AAEH,SAAgB,eAAe,CAAC,GAAkB;;IAChD,gHAAgH;IAChH,8DAA8D;IAC9D,IAAM,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAA;IAE3C,IAAA,GAAG,GAAc,GAAG,IAAjB,EAAE,OAAO,GAAK,GAAG,QAAR,CAAQ;IAC5B,IAAA,qBAAc,EAAC,GAAG,CAAC,CAAA;IAEnB,IAAM,IAAI,GAAY,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAA;IAC9D,IAAI,CAAC,YAAY,OAAjB,IAAI,EAAiB,oBAAa,EAAC;IAEnC,wEAAwE;IACxE,8DAA8D;IAC9D,IAAI,MAAA,MAAC,IAAY,aAAZ,IAAI,uBA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