@axe-core/watcher 0.0.0 → 0.0.1-next.2daa1159

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/util.js ADDED
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.Controller = exports.writeVariables = exports.extensionArgs = exports.PATH_TO_EXTENSION_VARIABLES = exports.PATH_TO_SESSION_FILE = exports.DEFAULT_SERVER_URL = exports.PATH_TO_EXTENSION = void 0;
43
+ var fs_1 = __importDefault(require("fs"));
44
+ var path_1 = __importDefault(require("path"));
45
+ var os_1 = __importDefault(require("os"));
46
+ exports.PATH_TO_EXTENSION = path_1.default.join(__dirname, '..', 'extension');
47
+ exports.DEFAULT_SERVER_URL = 'https://axe.deque.com/';
48
+ exports.PATH_TO_SESSION_FILE = path_1.default.join(os_1.default.tmpdir(), 'axe-watcher-session.json');
49
+ exports.PATH_TO_EXTENSION_VARIABLES = path_1.default.join(exports.PATH_TO_EXTENSION, 'variables.json');
50
+ exports.extensionArgs = [
51
+ "--disable-extensions-except=".concat(exports.PATH_TO_EXTENSION),
52
+ "--load-extension=".concat(exports.PATH_TO_EXTENSION)
53
+ ];
54
+ /** Write the user's settings to the disk, so the extension can load them. */
55
+ function writeVariables(_a) {
56
+ var apiKey = _a.apiKey, serverURL = _a.serverURL, sessionId = _a.sessionId, autoAnalyze = _a.autoAnalyze;
57
+ if (!serverURL) {
58
+ serverURL = exports.DEFAULT_SERVER_URL;
59
+ }
60
+ var urlString;
61
+ try {
62
+ urlString = new URL(serverURL).toString();
63
+ }
64
+ catch (err) {
65
+ throw new Error("Error when converting serverURL to URL. Ensure it is formatted properly: ".concat(err));
66
+ }
67
+ if (typeof autoAnalyze === 'undefined') {
68
+ autoAnalyze = true;
69
+ }
70
+ // When a custom session ID is not provided, attempt to read it from the filesystem.
71
+ // This enables multi-process/multi-browser test suites to all use the same session ID.
72
+ if (!sessionId && fs_1.default.existsSync(exports.PATH_TO_SESSION_FILE)) {
73
+ try {
74
+ var data = JSON.parse(fs_1.default.readFileSync(exports.PATH_TO_SESSION_FILE, 'utf8'));
75
+ sessionId = data.id;
76
+ }
77
+ catch (error) {
78
+ throw new Error("Unable to read session configuration: ".concat(error));
79
+ }
80
+ }
81
+ fs_1.default.writeFileSync(exports.PATH_TO_EXTENSION_VARIABLES, JSON.stringify({
82
+ api_key: apiKey,
83
+ server_url: urlString,
84
+ session_id: sessionId,
85
+ auto_analyze: !!autoAnalyze
86
+ }));
87
+ }
88
+ exports.writeVariables = writeVariables;
89
+ function updateAutoAnalyze(newVal) {
90
+ var fileContents = fs_1.default.readFileSync(exports.PATH_TO_EXTENSION_VARIABLES, 'utf-8');
91
+ var jsonValue = JSON.parse(fileContents);
92
+ jsonValue['auto_analyze'] = newVal;
93
+ fs_1.default.writeFileSync(exports.PATH_TO_EXTENSION_VARIABLES, JSON.stringify(jsonValue));
94
+ }
95
+ var Controller = /** @class */ (function () {
96
+ function Controller() {
97
+ }
98
+ Controller.prototype.start = function () {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0:
103
+ updateAutoAnalyze(true);
104
+ return [4 /*yield*/, this.executeScript(function () {
105
+ var event = new CustomEvent('axe:start-auto-mode');
106
+ window.dispatchEvent(event);
107
+ return Promise.resolve();
108
+ })];
109
+ case 1:
110
+ _a.sent();
111
+ return [2 /*return*/];
112
+ }
113
+ });
114
+ });
115
+ };
116
+ Controller.prototype.stop = function () {
117
+ return __awaiter(this, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0:
121
+ updateAutoAnalyze(false);
122
+ return [4 /*yield*/, this.executeScript(function () {
123
+ var event = new CustomEvent('axe:stop-auto-mode');
124
+ window.dispatchEvent(event);
125
+ return Promise.resolve();
126
+ })];
127
+ case 1:
128
+ _a.sent();
129
+ return [2 /*return*/];
130
+ }
131
+ });
132
+ });
133
+ };
134
+ Controller.prototype.analyze = function () {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ return __generator(this, function (_a) {
137
+ switch (_a.label) {
138
+ case 0: return [4 /*yield*/, this.executeScript(function () {
139
+ return new Promise(function (resolve) {
140
+ var event = new CustomEvent('axe:manual-mode-analyze');
141
+ var fn = function () {
142
+ window.removeEventListener('axe:manual-mode-analyze-done', fn);
143
+ resolve();
144
+ };
145
+ window.addEventListener('axe:manual-mode-analyze-done', fn);
146
+ window.dispatchEvent(event);
147
+ });
148
+ })];
149
+ case 1:
150
+ _a.sent();
151
+ return [2 /*return*/];
152
+ }
153
+ });
154
+ });
155
+ };
156
+ /** Flush all axe-core results by sending them to the server. */
157
+ Controller.prototype.flush = function () {
158
+ return __awaiter(this, void 0, void 0, function () {
159
+ return __generator(this, function (_a) {
160
+ switch (_a.label) {
161
+ case 0: return [4 /*yield*/, this.executeScript(function () {
162
+ return new Promise(function (resolve) {
163
+ var fn = function () {
164
+ window.removeEventListener('axe:flush-end', fn);
165
+ resolve();
166
+ };
167
+ window.addEventListener('axe:flush-end', fn);
168
+ var event = new CustomEvent('axe:flush-start');
169
+ window.dispatchEvent(event);
170
+ });
171
+ })];
172
+ case 1:
173
+ _a.sent();
174
+ return [2 /*return*/];
175
+ }
176
+ });
177
+ });
178
+ };
179
+ return Controller;
180
+ }());
181
+ exports.Controller = Controller;
182
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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1B,CAAC,CAAC,EAAA;;wBAJF,SAIE,CAAA;;;;;KACH;IAEY,4BAAO,GAApB;;;;4BACE,qBAAM,IAAI,CAAC,aAAa,CAAC;4BACvB,OAAO,IAAI,OAAO,CAAC,UAAA,OAAO;gCACxB,IAAM,KAAK,GAAG,IAAI,WAAW,CAAC,yBAAyB,CAAC,CAAA;gCACxD,IAAM,EAAE,GAAG;oCACT,MAAM,CAAC,mBAAmB,CAAC,8BAA8B,EAAE,EAAE,CAAC,CAAA;oCAC9D,OAAO,EAAE,CAAA;gCACX,CAAC,CAAA;gCACD,MAAM,CAAC,gBAAgB,CAAC,8BAA8B,EAAE,EAAE,CAAC,CAAA;gCAC3D,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;4BAC7B,CAAC,CAAC,CAAA;wBACJ,CAAC,CAAC,EAAA;;wBAVF,SAUE,CAAA;;;;;KACH;IAED,gEAAgE;IACnD,0BAAK,GAAlB;;;;4BACE,qBAAM,IAAI,CAAC,aAAa,CAAC;4BACvB,OAAO,IAAI,OAAO,CAAC,UAAA,OAAO;gCACxB,IAAM,EAAE,GAAG;oCACT,MAAM,CAAC,mBAAmB,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;oCAC/C,OAAO,EAAE,CAAA;gCACX,CAAC,CAAA;gCACD,MAAM,CAAC,gBAAgB,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;gCAC5C,IAAM,KAAK,GAAG,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAA;gCAChD,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;4BAC7B,CAAC,CAAC,CAAA;wBACJ,CAAC,CAAC,EAAA;;wBAVF,SAUE,CAAA;;;;;KACH;IACH,iBAAC;AAAD,CAAC,AAnDD,IAmDC;AAnDqB,gCAAU"}
package/dist/wdio.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Configuration, Controller } from './util';
2
+ import type { Options } from '@wdio/types';
3
+ interface Browser {
4
+ executeAsyncScript(script: string, args: object[]): void;
5
+ }
6
+ interface WdioArg extends Configuration {
7
+ options?: Options.WebDriver;
8
+ }
9
+ /**
10
+ * Creates a WebDriverIO config that uses axe extension
11
+ *
12
+ * @param arg Config to extend
13
+ */
14
+ export declare function wdioConfig(arg: WdioArg): Options.WebDriver;
15
+ export declare function wdioTestRunner(axe: Configuration['axe'], config: Options.Testrunner): Options.Testrunner;
16
+ export declare class WdioController extends Controller {
17
+ private driver;
18
+ constructor(driver: Browser);
19
+ protected executeScript(fn: string | (() => Promise<void>)): Promise<void>;
20
+ }
21
+ export {};
package/dist/wdio.js ADDED
@@ -0,0 +1,136 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.WdioController = exports.wdioTestRunner = exports.wdioConfig = void 0;
66
+ var util_1 = require("./util");
67
+ /**
68
+ * Creates a WebDriverIO config that uses axe extension
69
+ *
70
+ * @param arg Config to extend
71
+ */
72
+ function wdioConfig(arg) {
73
+ var _a, _b, _c;
74
+ (0, util_1.writeVariables)(arg.axe);
75
+ // Disable eslint. Wdio doesn't export this property even though they support it.
76
+ /* eslint-disable @typescript-eslint/no-explicit-any */
77
+ var chromeOpts = ((_b = (_a = arg.options) === null || _a === void 0 ? void 0 : _a.capabilities) === null || _b === void 0 ? void 0 : _b['goog:chromeOptions']) || {};
78
+ var args = chromeOpts.args || [];
79
+ if (args.includes('--headless')) {
80
+ throw new Error('Cannot use extension while headless.');
81
+ }
82
+ return __assign(__assign({}, arg.options), { capabilities: __assign(__assign({}, (_c = arg.options) === null || _c === void 0 ? void 0 : _c.capabilities), { browserName: 'chrome', 'goog:chromeOptions': {
83
+ args: util_1.extensionArgs.concat(args)
84
+ } }) });
85
+ }
86
+ exports.wdioConfig = wdioConfig;
87
+ // Configuration.axe is not a namespace, therefore have to use ['axe'] instead of .axe
88
+ function wdioTestRunner(axe, config) {
89
+ (0, util_1.writeVariables)(axe);
90
+ var capabilities = config.capabilities || [
91
+ {
92
+ 'goog:chromeOptions': {
93
+ args: []
94
+ }
95
+ }
96
+ ];
97
+ // has to be any because type is not exported
98
+ var firstCapability = capabilities[0];
99
+ firstCapability['goog:chromeOptions'] =
100
+ firstCapability['goog:chromeOptions'] || {};
101
+ var chromeOpts = firstCapability['goog:chromeOptions'];
102
+ chromeOpts.args = chromeOpts.args || [];
103
+ var args = chromeOpts.args;
104
+ if (args.includes('--headless')) {
105
+ throw new Error('Cannot use extension while headless.');
106
+ }
107
+ chromeOpts.args = util_1.extensionArgs.concat(args);
108
+ return __assign(__assign({}, config), { capabilities: capabilities });
109
+ }
110
+ exports.wdioTestRunner = wdioTestRunner;
111
+ var WdioController = /** @class */ (function (_super) {
112
+ __extends(WdioController, _super);
113
+ function WdioController(driver) {
114
+ var _this = _super.call(this) || this;
115
+ _this.driver = driver;
116
+ return _this;
117
+ }
118
+ WdioController.prototype.executeScript = function (fn) {
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ var script;
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0:
124
+ script = "\n const callback = arguments[arguments.length - 1];\n Promise.resolve()\n .then(".concat(fn, ")\n .then(callback);\n ");
125
+ return [4 /*yield*/, this.driver.executeAsyncScript(script, [])];
126
+ case 1:
127
+ _a.sent();
128
+ return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ };
133
+ return WdioController;
134
+ }(util_1.Controller));
135
+ exports.WdioController = WdioController;
136
+ //# sourceMappingURL=wdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wdio.js","sourceRoot":"","sources":["../src/wdio.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAKe;AAWf;;;;GAIG;AAEH,SAAgB,UAAU,CAAC,GAAY;;IACrC,IAAA,qBAAc,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAEvB,iFAAiF;IACjF,uDAAuD;IACvD,IAAM,UAAU,GACd,CAAA,MAAC,MAAA,GAAG,CAAC,OAAO,0CAAE,YAAoB,0CAAG,oBAAoB,CAAC,KAAI,EAAE,CAAA;IAClE,IAAM,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,EAAE,CAAA;IAElC,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;QAC/B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;KACxD;IAED,6BACK,GAAG,CAAC,OAAO,KACd,YAAY,wBACP,MAAA,GAAG,CAAC,OAAO,0CAAE,YAAY,KAC5B,WAAW,EAAE,QAAQ,EACrB,oBAAoB,EAAE;gBACpB,IAAI,EAAE,oBAAa,CAAC,MAAM,CAAC,IAAI,CAAC;aACjC,OAEJ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1,18 @@
1
+ import { Configuration, Controller } from './util';
2
+ import type { WebDriver } from 'selenium-webdriver';
3
+ import type { Options } from 'selenium-webdriver/chrome';
4
+ interface WebDriverArgs extends Configuration {
5
+ options?: Options;
6
+ }
7
+ /**
8
+ * Creates a Selenium config that uses axe extension
9
+ *
10
+ * @param arg Config to extend
11
+ */
12
+ export declare function webdriverConfig(arg: WebDriverArgs): Options;
13
+ export declare class WebdriverController extends Controller {
14
+ private driver;
15
+ constructor(driver: WebDriver);
16
+ protected executeScript(fn: string | (() => Promise<void>)): Promise<void>;
17
+ }
18
+ export {};
@@ -0,0 +1,103 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.WebdriverController = exports.webdriverConfig = void 0;
55
+ var util_1 = require("./util");
56
+ /**
57
+ * Creates a Selenium config that uses axe extension
58
+ *
59
+ * @param arg Config to extend
60
+ */
61
+ function webdriverConfig(arg) {
62
+ var _a, _b;
63
+ // Lazily require `chrome` to avoid Puppeteer/Playwright/WDIO users from needing `selenium-webdriver` installed.
64
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
65
+ var chrome = require('selenium-webdriver/chrome');
66
+ var axe = arg.axe, options = arg.options;
67
+ (0, util_1.writeVariables)(axe);
68
+ var opts = options ? options : new chrome.Options();
69
+ opts.addArguments.apply(opts, util_1.extensionArgs);
70
+ // Note: fragile, but selenium does not give us a real way to check this
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ 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')) {
73
+ throw new Error('Cannot use extension while headless.');
74
+ }
75
+ return opts;
76
+ }
77
+ exports.webdriverConfig = webdriverConfig;
78
+ var WebdriverController = /** @class */ (function (_super) {
79
+ __extends(WebdriverController, _super);
80
+ function WebdriverController(driver) {
81
+ var _this = _super.call(this) || this;
82
+ _this.driver = driver;
83
+ return _this;
84
+ }
85
+ WebdriverController.prototype.executeScript = function (fn) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ var script;
88
+ return __generator(this, function (_a) {
89
+ switch (_a.label) {
90
+ case 0:
91
+ script = "\n const callback = arguments[arguments.length - 1];\n Promise.resolve()\n .then(".concat(fn, ")\n .then(callback);\n ");
92
+ return [4 /*yield*/, this.driver.executeAsyncScript(script)];
93
+ case 1:
94
+ _a.sent();
95
+ return [2 /*return*/];
96
+ }
97
+ });
98
+ });
99
+ };
100
+ return WebdriverController;
101
+ }(util_1.Controller));
102
+ exports.WebdriverController = WebdriverController;
103
+ //# sourceMappingURL=webdriver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webdriver.js","sourceRoot":"","sources":["../src/webdriver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAKe;AAQf;;;;GAIG;AAEH,SAAgB,eAAe,CAAC,GAAkB;;IAChD,gHAAgH;IAChH,8DAA8D;IAC9D,IAAM,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAA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