@axe-core/watcher 3.11.0-rc.e230efa3 → 3.11.1-next.06e682d4

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.
Files changed (103) hide show
  1. package/dist/Controller.d.ts +9 -1
  2. package/dist/Controller.js +24 -10
  3. package/dist/Controller.js.map +1 -1
  4. package/dist/EventForwarder.js +4 -6
  5. package/dist/EventForwarder.js.map +1 -1
  6. package/dist/createDebugger.d.ts +9 -0
  7. package/dist/createDebugger.js +27 -0
  8. package/dist/createDebugger.js.map +1 -0
  9. package/dist/cypress.d.ts +1 -1
  10. package/dist/cypress.js +45 -45
  11. package/dist/cypress.js.map +1 -1
  12. package/dist/cypressCommands.d.ts +3 -1
  13. package/dist/cypressCommands.js +88 -86
  14. package/dist/cypressCommands.js.map +1 -1
  15. package/dist/git.d.ts +2 -1
  16. package/dist/git.js +5 -4
  17. package/dist/git.js.map +1 -1
  18. package/dist/playwright.d.ts +1 -1
  19. package/dist/playwright.js +10 -7
  20. package/dist/playwright.js.map +1 -1
  21. package/dist/playwrightTest.js +10 -3
  22. package/dist/playwrightTest.js.map +1 -1
  23. package/dist/playwrightWrapping.d.ts +1 -1
  24. package/dist/playwrightWrapping.js +41 -41
  25. package/dist/playwrightWrapping.js.map +1 -1
  26. package/dist/puppeteer.d.ts +1 -1
  27. package/dist/puppeteer.js +11 -8
  28. package/dist/puppeteer.js.map +1 -1
  29. package/dist/puppeteerWrapping.d.ts +3 -2
  30. package/dist/puppeteerWrapping.js +100 -42
  31. package/dist/puppeteerWrapping.js.map +1 -1
  32. package/dist/sendResultsToServer.d.ts +9 -2
  33. package/dist/sendResultsToServer.js +26 -44
  34. package/dist/sendResultsToServer.js.map +1 -1
  35. package/dist/utils/constants.d.ts +4 -0
  36. package/dist/utils/constants.js +16 -0
  37. package/dist/utils/constants.js.map +1 -0
  38. package/dist/utils/headlessNotSupportedError.d.ts +5 -0
  39. package/dist/utils/headlessNotSupportedError.js +17 -0
  40. package/dist/utils/headlessNotSupportedError.js.map +1 -0
  41. package/dist/utils/headlessNotSupportedError.test.d.ts +1 -0
  42. package/dist/utils/headlessNotSupportedError.test.js +21 -0
  43. package/dist/utils/headlessNotSupportedError.test.js.map +1 -0
  44. package/dist/utils/mergeChromeArgs.d.ts +12 -0
  45. package/dist/utils/mergeChromeArgs.js +73 -0
  46. package/dist/utils/mergeChromeArgs.js.map +1 -0
  47. package/dist/utils/mergeChromeArgs.test.d.ts +1 -0
  48. package/dist/utils/mergeChromeArgs.test.js +260 -0
  49. package/dist/utils/mergeChromeArgs.test.js.map +1 -0
  50. package/dist/utils/proxyHandlers.d.ts +12 -0
  51. package/dist/utils/proxyHandlers.js +62 -0
  52. package/dist/utils/proxyHandlers.js.map +1 -0
  53. package/dist/utils/proxyHandlers.test.d.ts +1 -0
  54. package/dist/utils/proxyHandlers.test.js +28 -0
  55. package/dist/utils/proxyHandlers.test.js.map +1 -0
  56. package/dist/utils/readVariables.d.ts +7 -0
  57. package/dist/utils/readVariables.js +17 -0
  58. package/dist/utils/readVariables.js.map +1 -0
  59. package/dist/utils/updateAutoAnalyze.d.ts +7 -0
  60. package/dist/utils/updateAutoAnalyze.js +20 -0
  61. package/dist/utils/updateAutoAnalyze.js.map +1 -0
  62. package/dist/utils/validateApiKey.d.ts +7 -0
  63. package/dist/utils/validateApiKey.js +34 -0
  64. package/dist/utils/validateApiKey.js.map +1 -0
  65. package/dist/utils/validateApiKey.test.d.ts +1 -0
  66. package/dist/utils/validateApiKey.test.js +66 -0
  67. package/dist/utils/validateApiKey.test.js.map +1 -0
  68. package/dist/utils/validateAxeRunContext.d.ts +2 -0
  69. package/dist/utils/validateAxeRunContext.js +59 -0
  70. package/dist/utils/validateAxeRunContext.js.map +1 -0
  71. package/dist/utils/validateAxeRunContext.test.d.ts +1 -0
  72. package/dist/utils/validateAxeRunContext.test.js +100 -0
  73. package/dist/utils/validateAxeRunContext.test.js.map +1 -0
  74. package/dist/utils/validateAxeRunOptions.d.ts +13 -0
  75. package/dist/utils/validateAxeRunOptions.js +161 -0
  76. package/dist/utils/validateAxeRunOptions.js.map +1 -0
  77. package/dist/utils/validateAxeRunOptions.test.d.ts +1 -0
  78. package/dist/utils/validateAxeRunOptions.test.js +230 -0
  79. package/dist/utils/validateAxeRunOptions.test.js.map +1 -0
  80. package/dist/utils/writeExtensionManifest.d.ts +7 -0
  81. package/dist/utils/writeExtensionManifest.js +18 -0
  82. package/dist/utils/writeExtensionManifest.js.map +1 -0
  83. package/dist/utils/writeVariables.d.ts +64 -0
  84. package/dist/utils/writeVariables.js +119 -0
  85. package/dist/utils/writeVariables.js.map +1 -0
  86. package/dist/utils/writeVariables.test.d.ts +1 -0
  87. package/dist/utils/writeVariables.test.js +184 -0
  88. package/dist/utils/writeVariables.test.js.map +1 -0
  89. package/dist/wdio.d.ts +1 -1
  90. package/dist/wdio.js +18 -13
  91. package/dist/wdio.js.map +1 -1
  92. package/dist/webdriver.d.ts +1 -1
  93. package/dist/webdriver.js +15 -8
  94. package/dist/webdriver.js.map +1 -1
  95. package/dist/webdriverWrapping.d.ts +1 -1
  96. package/dist/webdriverWrapping.js +16 -16
  97. package/dist/webdriverWrapping.js.map +1 -1
  98. package/extension/background.js +1 -1
  99. package/extension/content.js +1 -1
  100. package/package.json +11 -8
  101. package/dist/util.d.ts +0 -66
  102. package/dist/util.js +0 -167
  103. package/dist/util.js.map +0 -1
@@ -1,9 +1,17 @@
1
+ import type { Debugger } from 'debug';
2
+ interface ControllerParams {
3
+ /** The namespace for the debug logger. */
4
+ debugLoggerName: string;
5
+ }
1
6
  declare abstract class Controller {
2
7
  protected abstract executeScript<A = unknown, T = void>(fn: string | ((...args: A[]) => Promise<T>), ...args: unknown[]): Promise<T>;
3
8
  protected isStopped: boolean;
9
+ protected debugLogger: Debugger;
10
+ constructor({ debugLoggerName }: ControllerParams);
4
11
  start(): Promise<void>;
5
12
  stop(): Promise<void>;
6
- analyze({ __UserRequestedAnalyze }?: {
13
+ analyze({ __Method, __UserRequestedAnalyze }?: {
14
+ __Method?: string;
7
15
  __UserRequestedAnalyze?: boolean;
8
16
  }): Promise<void>;
9
17
  flush(): Promise<void>;
@@ -3,14 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const util_1 = require("./util");
6
+ const updateAutoAnalyze_1 = __importDefault(require("./utils/updateAutoAnalyze"));
7
7
  const sendResultsToServer_1 = __importDefault(require("./sendResultsToServer"));
8
+ const createDebugger_1 = __importDefault(require("./createDebugger"));
8
9
  class Controller {
9
- constructor() {
10
+ constructor({ debugLoggerName }) {
10
11
  this.isStopped = false;
12
+ this.debugLogger = (0, createDebugger_1.default)(debugLoggerName);
11
13
  }
12
14
  async start() {
13
- (0, util_1.updateAutoAnalyze)(true);
15
+ (0, updateAutoAnalyze_1.default)(true);
14
16
  this.isStopped = false;
15
17
  await this.executeScript(() => {
16
18
  if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) {
@@ -28,7 +30,7 @@ class Controller {
28
30
  });
29
31
  }
30
32
  async stop() {
31
- (0, util_1.updateAutoAnalyze)(false);
33
+ (0, updateAutoAnalyze_1.default)(false);
32
34
  this.isStopped = true;
33
35
  await this.executeScript(() => {
34
36
  if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) {
@@ -45,19 +47,24 @@ class Controller {
45
47
  });
46
48
  });
47
49
  }
48
- async analyze({ __UserRequestedAnalyze = true } = {}) {
50
+ async analyze({ __Method, __UserRequestedAnalyze = true } = {}) {
51
+ this.debugLogger(`Analyze: Invoked${__Method ? ` - ${__Method}` : ''}`);
49
52
  // If the user didn't request an analyze, and we're in manual mode, don't do anything.
50
53
  if (this.isStopped && !__UserRequestedAnalyze) {
54
+ this.debugLogger('Analyze: Skipped', {
55
+ isStopped: this.isStopped,
56
+ __UserRequestedAnalyze
57
+ });
51
58
  return;
52
59
  }
53
- await this.executeScript((userRequestedAnalyze) => {
60
+ const result = await this.executeScript((userRequestedAnalyze) => {
54
61
  if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) {
55
- return Promise.resolve();
62
+ return Promise.resolve({ message: 'Skipped - Invalid protocol' });
56
63
  }
57
64
  return new Promise(resolve => {
58
- const fn = () => {
65
+ const fn = (event) => {
59
66
  window.removeEventListener('axe:manual-mode-analyze-done', fn);
60
- resolve();
67
+ resolve(event.detail);
61
68
  };
62
69
  window.addEventListener('axe:manual-mode-analyze-done', fn);
63
70
  const event = new CustomEvent('axe:manual-mode-analyze', {
@@ -66,8 +73,10 @@ class Controller {
66
73
  window.dispatchEvent(event);
67
74
  });
68
75
  }, __UserRequestedAnalyze);
76
+ this.debugLogger(`Analyze: ${result.message}`);
69
77
  }
70
78
  async flush() {
79
+ this.debugLogger('Flush: Invoked (may analyze implicitly)');
71
80
  const results = await this.executeScript(() => {
72
81
  if (!['http:', 'https:', 'file:'].includes(window.location.protocol)) {
73
82
  return Promise.resolve([]);
@@ -88,7 +97,12 @@ class Controller {
88
97
  window.dispatchEvent(event);
89
98
  });
90
99
  });
91
- await (0, sendResultsToServer_1.default)(results);
100
+ this.debugLogger(`Flush: Received ${results.length} results`);
101
+ await (0, sendResultsToServer_1.default)({
102
+ results,
103
+ debugLogger: this.debugLogger
104
+ });
105
+ this.debugLogger('Flush: Complete');
92
106
  }
93
107
  }
94
108
  exports.default = Controller;
@@ -1 +1 @@
1
- {"version":3,"file":"Controller.js","sourceRoot":"","sources":["../src/Controller.ts"],"names":[],"mappings":";;;;;AAAA,iCAA0C;AAC1C,gFAAwE;AAExE,MAAe,UAAU;IAAzB;QAMY,cAAS,GAAG,KAAK,CAAA;IAkG7B,CAAC;IAhGQ,KAAK,CAAC,KAAK;QAChB,IAAA,wBAAiB,EAAC,IAAI,CAAC,CAAA;QACvB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QAEtB,MAAM,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE;YAC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AAA;gBACnC,CAAC,CAAA;gBAED,MAAM,CAAC,gBAAgB,CAAC,YAAY,EAAE,WAAyB,CAAC,CAAA;gBAChE,MAAM,CAAC,gBAAgB,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;gBACpD,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,iBAAiB,CAAC,CAAA;gBAChD,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;YAC7B,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,WAAW,CAAC,mBAAmB,OAAO,CAAC,MAAM,UAAU,CAAC,CAAA;QAC7D,MAAM,IAAA,6BAAmB,EAAC;YACxB,OAAO;YACP,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC,CAAA;QACF,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAA;IACrC,CAAC;CACF;AAED,kBAAe,UAAU,CAAA"}
@@ -34,12 +34,10 @@ class EventForwarder {
34
34
  .reduce((prevLaunchOptions, listener) => listener(browser, prevLaunchOptions), launchOptions));
35
35
  }
36
36
  else {
37
- /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
38
- on(event, async (...args) => {
39
- for (const listener of this.emitter.listeners(event)) {
40
- await listener(...args);
41
- }
42
- });
37
+ for (const listener of this.emitter.listeners(event)) {
38
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
39
+ on(event, listener);
40
+ }
43
41
  }
44
42
  }
45
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EventForwarder.js","sourceRoot":"","sources":["../src/EventForwarder.ts"],"names":[],"mappings":";;;;;AAYA,kEAAwC;AAExC,MAAM,cAAc;IAKlB;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,uBAAY,EAAE,CAAA;QACjC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAA;QACf,IAAI,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,EAAQ,EAAE;YAC7B,IAAI,MAAM,KAA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,KAAK,CAAC,EAAE,CAAC;oBACrD,iEAAiE;oBACjE,EAAE,CAAC,KAAY,EAAE,QAAQ,CAAC,CAAA;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,kBAAe,cAAc,CAAA"}
@@ -0,0 +1,9 @@
1
+ import debug from 'debug';
2
+ /**
3
+ * Creates a debug logger with the given namespace
4
+ *
5
+ * @param namespace The namespace for the debug logger for example: `PlaywrightController` or `PlaywrightWrapping`.
6
+ * @returns debug instance
7
+ */
8
+ declare function createDebugger(namespace: string): debug.Debugger;
9
+ export default createDebugger;
@@ -0,0 +1,27 @@
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 debug_1 = __importDefault(require("debug"));
7
+ /**
8
+ * The prefix for the debug logger allows users to filter logs by the prefix
9
+ * using the debug package.
10
+ *
11
+ * @example
12
+ * ```bash
13
+ * DEBUG=axe-watcher:* yarn test
14
+ * ```
15
+ */
16
+ const NAMESPACE_PREFIX = 'axe-watcher';
17
+ /**
18
+ * Creates a debug logger with the given namespace
19
+ *
20
+ * @param namespace The namespace for the debug logger for example: `PlaywrightController` or `PlaywrightWrapping`.
21
+ * @returns debug instance
22
+ */
23
+ function createDebugger(namespace) {
24
+ return (0, debug_1.default)(`${NAMESPACE_PREFIX}:${namespace}`);
25
+ }
26
+ exports.default = createDebugger;
27
+ //# sourceMappingURL=createDebugger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createDebugger.js","sourceRoot":"","sources":["../src/createDebugger.ts"],"names":[],"mappings":";;;;;AAAA,kDAAyB;AAEzB;;;;;;;;GAQG;AACH,MAAM,gBAAgB,GAAG,aAAa,CAAA;AAEtC;;;;;GAKG;AAEH,SAAS,cAAc,CAAC,SAAiB;IACvC,OAAO,IAAA,eAAK,EAAC,GAAG,gBAAgB,IAAI,SAAS,EAAE,CAAC,CAAA;AAClD,CAAC;AAED,kBAAe,cAAc,CAAA"}
package/dist/cypress.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Configuration } from './util';
1
+ import { type Configuration } from './utils/writeVariables';
2
2
  /**
3
3
  * Create a Cypress config that uses the axe Watcher extension.
4
4
  *
package/dist/cypress.js CHANGED
@@ -4,10 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.cypressConfig = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const util_1 = require("./util");
9
7
  const sendResultsToServer_1 = __importDefault(require("./sendResultsToServer"));
10
8
  const EventForwarder_1 = __importDefault(require("./EventForwarder"));
9
+ const writeVariables_1 = __importDefault(require("./utils/writeVariables"));
10
+ const writeExtensionManifest_1 = __importDefault(require("./utils/writeExtensionManifest"));
11
+ const headlessNotSupportedError_1 = require("./utils/headlessNotSupportedError");
12
+ const mergeChromeArgs_1 = __importDefault(require("./utils/mergeChromeArgs"));
13
+ const createDebugger_1 = __importDefault(require("./createDebugger"));
14
+ const debugLogger = (0, createDebugger_1.default)('CypressController');
11
15
  /**
12
16
  * Create a Cypress config that uses the axe Watcher extension.
13
17
  *
@@ -15,12 +19,14 @@ const EventForwarder_1 = __importDefault(require("./EventForwarder"));
15
19
  */
16
20
  const cypressConfig = (config) => {
17
21
  const { axe, ...userConfig } = config;
18
- (0, util_1.writeVariables)({
22
+ const { DEBUG } = process.env;
23
+ const hasWatcherDebug = DEBUG && DEBUG.includes('axe-watcher');
24
+ (0, writeVariables_1.default)({
19
25
  ...axe,
20
26
  // Let the extension know to check for Cypress frames.
21
27
  cypress: true
22
28
  });
23
- (0, util_1.writeManifest)({
29
+ (0, writeExtensionManifest_1.default)({
24
30
  all_frames: true,
25
31
  exclude_globs: [
26
32
  // Top-level Cypress page.
@@ -30,6 +36,12 @@ const cypressConfig = (config) => {
30
36
  ]
31
37
  });
32
38
  return {
39
+ ...(hasWatcherDebug && {
40
+ env: {
41
+ ...config.env,
42
+ __AXE_WATCHER_DEBUG: hasWatcherDebug
43
+ }
44
+ }),
33
45
  ...userConfig,
34
46
  e2e: {
35
47
  ...userConfig.e2e,
@@ -61,53 +73,41 @@ const cypressConfig = (config) => {
61
73
  * ensure we wait for the user's `setupNodeEvents` to resolve.
62
74
  */
63
75
  const userNodeEventConfig = await ((_b = (_a = userConfig.e2e) === null || _a === void 0 ? void 0 : _a.setupNodeEvents) === null || _b === void 0 ? void 0 : _b.call(_a, on, ...args));
76
+ on('task', {
77
+ __uploadAxeWatcherResults: async (results) => {
78
+ if (!results.length) {
79
+ // Indicates to Cypress that the event has been handled.
80
+ // @see https://docs.cypress.io/api/commands/task#Usage
81
+ return null;
82
+ }
83
+ await (0, sendResultsToServer_1.default)({
84
+ results,
85
+ debugLogger
86
+ });
87
+ return null;
88
+ },
89
+ __debugAxeWatcher: (message) => {
90
+ debugLogger(message);
91
+ return null;
92
+ }
93
+ });
64
94
  on('before:browser:launch', (browser, launchOptions) => {
65
- if (browser.name !== 'chrome') {
66
- throw new Error('The @axe-core/watcher package only supports running in Chrome. Please refer to our System Requirements for more information: https://docs.deque.com/developer-hub/2/en/dh-system-requirements');
95
+ // We only officially support Chrome, but for backcompat we are permissive and accept other
96
+ // Chromium-based browsers (eg, "chromium", "chrome:beta", "edge").
97
+ if (browser.name.startsWith('firefox') ||
98
+ browser.name.startsWith('electron')) {
99
+ throw new Error(`The @axe-core/watcher package only supports running in Chrome, but Cypress is configured with browser "${browser.name}". Please refer to our System Requirements for more information: https://docs.deque.com/developer-hub/2/en/dh-system-requirements`);
67
100
  }
68
101
  if (browser.isHeadless && launchOptions.args.includes('--headless')) {
69
- throw new util_1.HeadlessNotSupportedError('In Cypress, "--headless=new" became the default headless mode in Cypress version 12.15.0. Ensure your Cypress version is up to date and that you are not using a "before:browser:launch" configuration that adds "--headless" to launchOptions.args.');
102
+ throw new headlessNotSupportedError_1.HeadlessNotSupportedError('In Cypress, "--headless=new" became the default headless mode in Cypress version 12.15.0. Ensure your Cypress version is up to date and that you are not using a "before:browser:launch" configuration that adds "--headless" to launchOptions.args.');
70
103
  }
71
- // Load the extension. Merge extention args if provided by the user
72
- const launchOptionsArgs = [
73
- ...launchOptions.args,
74
- ...util_1.extensionArgs
75
- ].reduce((prev, arg) => {
76
- const [key, value] = arg.split('=');
77
- if (!prev[key]) {
78
- prev[key] = [];
79
- }
80
- if (value) {
81
- prev[key].push(value);
82
- }
83
- return prev;
84
- }, {});
85
- launchOptions.args = Object.entries(launchOptionsArgs).map(([key, value]) => value.length > 0 ? [key, value.join(',')].join('=') : key);
104
+ // Load the extension. Merge extension args if provided by the user
105
+ const existingArgs = launchOptions.args;
106
+ launchOptions.args = (0, mergeChromeArgs_1.default)(existingArgs, {
107
+ disableOtherExtensions: false
108
+ });
86
109
  return launchOptions;
87
110
  });
88
- // Read the results sent from the extension, then forward to the server.
89
- on('after:run', async () => {
90
- let results;
91
- try {
92
- results = fs_1.default
93
- .readdirSync('cypress/axe-watcher')
94
- .filter(f => f.endsWith('.json'));
95
- }
96
- catch (error) {
97
- // this is a non-error; the test suite likely just failed early
98
- // without running any scans
99
- if (error.code === 'ENOENT') {
100
- return;
101
- }
102
- throw error;
103
- }
104
- for (const result of results) {
105
- const data = fs_1.default.readFileSync(`cypress/axe-watcher/${result}`, 'utf8');
106
- const parsed = JSON.parse(data);
107
- await (0, sendResultsToServer_1.default)(parsed);
108
- fs_1.default.unlinkSync(`cypress/axe-watcher/${result}`);
109
- }
110
- });
111
111
  /**
112
112
  * Forward the accumulated events to cypress.
113
113
  * For more information, see comment on #44
@@ -1 +1 @@
1
- {"version":3,"file":"cypress.js","sourceRoot":"","sources":["../src/cypress.ts"],"names":[],"mappings":";;;;;;AACA,4CAAmB;AACnB,iCAMe;AACf,gFAAuD;AACvD,sEAA6C;AAE7C;;;;GAIG;AAEI,MAAM,aAAa,GAAG,CAC3B,MAA6C,EACtB,EAAE;IACzB,M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,CAAC;wBACD,MAAM,IAAI,KAAK,CACb,0GAA0G,OAAO,CAAC,IAAI,mIAAmI,CAC1P,CAAA;oBACH,CAAC;oBAED,IAAI,OAAO,CAAC,UAAU,IAAI,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;wBACpE,MAAM,IAAI,qDAAyB,CACjC,sPAAsP,CACvP,CAAA;oBACH,CAAC;oBAED,mEAAmE;oBACnE,MAAM,YAAY,GAAG,aAAa,CAAC,IAAI,CAAA;oBACvC,aAAa,CAAC,IAAI,GAAG,IAAA,yBAAe,EAAC,YAAY,EAAE;wBACjD,sBAAsB,EAAE,KAAK;qBAC9B,CAAC,CAAA;oBAEF,OAAO,aAAa,CAAA;gBACtB,CAAC,CAAC,CAAA;gBAEF;;;mBAGG;gBACH,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;gBAEjC,OAAO,mBAAmB,CAAA;YAC5B,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA;AA3HY,QAAA,aAAa,iBA2HzB"}
@@ -1,4 +1,3 @@
1
- export {};
2
1
  declare global {
3
2
  namespace Cypress {
4
3
  interface Chainable {
@@ -12,6 +11,7 @@ declare global {
12
11
  axeFlush(): Chainable<void>;
13
12
  /** Perform an axe-core analysis. */
14
13
  axeWatcherAnalyze(params?: {
14
+ __Method?: string;
15
15
  __UserRequestedAnalyze?: boolean;
16
16
  }): Chainable<void>;
17
17
  /**
@@ -20,6 +20,7 @@ declare global {
20
20
  * @Deprecated Use cy.axeWatcherAnalyze() instead
21
21
  */
22
22
  axeAnalyze(params?: {
23
+ __Method?: string;
23
24
  __UserRequestedAnalyze?: boolean;
24
25
  }): Chainable<void>;
25
26
  /**
@@ -48,3 +49,4 @@ declare global {
48
49
  type CypressMethod = keyof Cypress.Chainable;
49
50
  /** Commands we wrap to help us identify new page states. */
50
51
  export declare const WRAPPED_COMMANDS: ReadonlyArray<CypressMethod>;
52
+ export {};
@@ -27,8 +27,17 @@ exports.WRAPPED_COMMANDS = [
27
27
  'trigger',
28
28
  'type',
29
29
  'uncheck',
30
+ 'visit',
30
31
  'wait'
31
32
  ];
33
+ /** Helper function to log debug messages */
34
+ const logDebugAxeWatcher = ({ message }) => {
35
+ // perf: we only want to log debug messages if the env has been set
36
+ // so it doesn't enqueue a Cypress command
37
+ if (Cypress.env('__AXE_WATCHER_DEBUG')) {
38
+ cy.task('__debugAxeWatcher', message, { log: false });
39
+ }
40
+ };
32
41
  const shouldAnalyzeLocation = (location) => ['http:', 'https:', 'file:'].includes(location.protocol);
33
42
  /**
34
43
  * Wrapped commands queue an axe run before calling the original method. This can seem
@@ -39,99 +48,91 @@ const shouldAnalyzeLocation = (location) => ['http:', 'https:', 'file:'].include
39
48
  * The last command that runs relies on the flush to catch the last page state.
40
49
  */
41
50
  exports.WRAPPED_COMMANDS.forEach(method => Cypress.Commands.overwrite(method, (originalFn, ...args) => {
42
- var _a, _b, _c, _d, _e, _f;
43
- const currentCommand = (_b = (_a = cy.state('current')) === null || _a === void 0 ? void 0 : _a.attributes) === null || _b === void 0 ? void 0 : _b.name;
51
+ var _a, _b, _c, _d, _e;
52
+ const currentCommand = cy.state('current');
53
+ const currentCommandName = currentCommand === null || currentCommand === void 0 ? void 0 : currentCommand.get('name');
54
+ const currentCommandType = currentCommand === null || currentCommand === void 0 ? void 0 : currentCommand.get('type');
55
+ // TODO: Remove the feature flag once #1109 is fully resolved.
56
+ const tryRequerySubject = !!Cypress.env('__AXE_WATCHER_CYPRESS_REQUERY_SUBJECT_AFTER_ANALYZE') &&
57
+ 'getSubjectFromChain' in cy;
44
58
  // Some commands, like "type" call other commands internally, like "click".
45
59
  // We don't want to enqueue a run in these scenarios because it can cause
46
60
  // promises to be returned from commands, which Cypress does not allow.
47
61
  // See: https://github.com/cypress-io/cypress/issues/19086
48
- if (currentCommand && currentCommand !== method) {
62
+ if (currentCommandName && currentCommandName !== method) {
49
63
  return originalFn(...args);
50
64
  }
51
- // The "Subject" is a handle to the current DOM element(s) that the command is acting on.
52
- const originalSubject = (_d = (_c = cy).subject) === null || _d === void 0 ? void 0 : _d.call(_c);
65
+ // axeWatcherAnalyze is slow; it's possible for the Cypress subject to become invalidated
66
+ // while it's running (eg, if the subject is in some sort of remount-loop). To account for
67
+ // this, we ask Cypress to requery the subject object from the subjectChain before returning
68
+ // control to the original function.
69
+ // Note that we don't always have access to an original subjectChain to restore; the API is
70
+ // only available in Cypress 12+, and even then we might be wrapping a command that doesn't
71
+ // necessarily operate on a subject.
53
72
  // The "Subject Chain" represents the chain of Cypress selection operations that lead up
54
73
  // to finding the "Subject". cy.getSubjectFromChain() requeries those operations to retrieve
55
74
  // a fresh "Subject" handle.
56
- const originalSubjectChain = (_f = (_e = cy).subjectChain) === null || _f === void 0 ? void 0 : _f.call(_e);
57
- cy.window()
58
- .then(win => {
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- if (win && !win.__AXE_WATCHER_HAS_VISITED) {
61
- /**
62
- * Set a flag on the Window to indicate that a wrapped method has been called.
63
- * This is used to determine whether we should call `axeFlush` after the test.
64
- */
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- ;
67
- win.__AXE_WATCHER_HAS_VISITED = true;
68
- }
69
- })
70
- .axeWatcherAnalyze({ __UserRequestedAnalyze: false })
71
- // axeWatcherAnalyze is slow; it's possible for the Cypress subject to become invalidated
72
- // while it's running (eg, if the subject is in some sort of remount-loop). To account for
73
- // this, we ask Cypress to requery the subject object from the subjectChain before returning
74
- // control to the original function.
75
- //
76
- // Note that we don't always have access to an original subjectChain to restore; the API is
77
- // only available in Cypress 12+, and even then we might be wrapping a command that doesn't
78
- // necessarily operate on a subject.
79
- .then(() => {
80
- var _a, _b;
81
- // Some Cypress commands pick up the subject from cy.subject(), and some pick it up from a
82
- // subject parameter that's passed to the command. Returning the updated subject from this
83
- // .then() sets cy.subject() to handle the former...
84
- return originalSubjectChain &&
85
- ((_b = (_a = cy).getSubjectFromChain) === null || _b === void 0 ? void 0 : _b.call(_a, originalSubjectChain));
86
- })
87
- .then(updatedSubject => {
88
- // ...and this map handles the latter.
89
- const argsWithRefreshedSubject = args.map(arg => originalSubject && arg === originalSubject ? updatedSubject : arg);
90
- // originalFn might return a Promise that Cypress needs to be able to track, so it's important
91
- // to propagate its return value even though we're not chaining any further cypress commands
92
- // ourselves.
93
- return originalFn(...argsWithRefreshedSubject);
75
+ const originalSubject = (_b = (_a = cy).subject) === null || _b === void 0 ? void 0 : _b.call(_a);
76
+ const originalSubjectChain = (_d = (_c = cy).subjectChain) === null || _d === void 0 ? void 0 : _d.call(_c);
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ let commandChain = cy.window().axeWatcherAnalyze({
79
+ __Method: method,
80
+ __UserRequestedAnalyze: false
94
81
  });
82
+ // This version has issues if the subject is remounting continuously because Cypress
83
+ // considers the ".then" to be an action (not a query) and so isn't willing to re-run
84
+ // it if necessary for actionability checks
85
+ //
86
+ // commandChain = commandChain.then(() => (cy as CyInternal).getSubjectFromChain!(originalSubjectChain))
87
+ //
88
+ if (tryRequerySubject) {
89
+ const timeout = (_e = args.find(arg => arg.timeout)) === null || _e === void 0 ? void 0 : _e.timeout;
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ commandChain = commandChain.__axeRestoreSubject(originalSubjectChain, timeout);
92
+ // In all hooked cases, originalFn can have its own timeout.
93
+ // Setting our own very long timeout here both maintains the original timeout
94
+ // and correctly attributes an error thrown because of it to the originalFn timing out,
95
+ // rather than to our wrapper.
96
+ commandChain.then({ timeout: 999999 }, refreshedSubject => originalFn(
97
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98
+ ...updateSubject(args, currentCommandType, refreshedSubject)));
99
+ }
100
+ else {
101
+ commandChain
102
+ // Set the subject back to the previous subject
103
+ .then(() => originalSubject)
104
+ .then(() => originalFn(...args));
105
+ }
95
106
  }));
96
- /**
97
- * The `visit` command is wrapped differently than the other commands. This is because
98
- * we need to actually visit and load the page before we can run axe.
99
- *
100
- * We queue an axe run, run the original visit command, and then mark
101
- * the page visited before returning visit result.
102
- */
103
- Cypress.Commands.overwrite('visit', (originalFn, ...args) => {
104
- // We use `cy.wrap(null)` here just to get into the Cypress command queue.
105
- cy.wrap(null)
106
- .axeWatcherAnalyze({ __UserRequestedAnalyze: false })
107
- .then(() => originalFn(...args))
108
- .then(visitResult => {
109
- cy.window()
110
- .then(win => {
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- if (win && !win.__AXE_WATCHER_HAS_VISITED) {
113
- /**
114
- * Set a flag on the Window to indicate that a wrapped method has been called.
115
- * This is used to determine whether we should call `axeFlush` after the test.
116
- */
117
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
- ;
119
- win.__AXE_WATCHER_HAS_VISITED = true;
120
- }
121
- })
122
- .then(() => visitResult);
107
+ function updateSubject(args, commandType, refreshedSubject) {
108
+ if (commandType === 'parent') {
109
+ return args;
110
+ }
111
+ else {
112
+ return [refreshedSubject, ...args.slice(1)];
113
+ }
114
+ }
115
+ Cypress.Commands.addQuery(
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ '__axeRestoreSubject',
118
+ // This must be a regular function because timeouts rely on `this`
119
+ // https://docs.cypress.io/api/cypress-api/custom-queries#Arguments
120
+ function (subjectChain, timeout) {
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ this.set('timeout', timeout);
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ this.set('onFail', (err) => {
125
+ const runner = cy.state('runnable');
126
+ err.codeFrame = runner.invocationDetails;
123
127
  });
128
+ return () => cy.getSubjectFromChain(subjectChain);
124
129
  });
125
130
  function axeWatcherFlushCommand() {
131
+ logDebugAxeWatcher({ message: 'Flush: Invoked (may analyze implicitly)' });
126
132
  cy.window().then(win => {
127
133
  if (!shouldAnalyzeLocation(win.location)) {
128
134
  return Promise.resolve();
129
135
  }
130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
- const hasVisited = win.__AXE_WATCHER_HAS_VISITED;
132
- if (!hasVisited) {
133
- return Promise.resolve();
134
- }
135
136
  return new Promise(resolve => {
136
137
  const results = [];
137
138
  const onAxeResult = (event) => {
@@ -140,7 +141,6 @@ function axeWatcherFlushCommand() {
140
141
  const onFlushEnd = () => {
141
142
  win.removeEventListener('axe:flush-end', onFlushEnd);
142
143
  win.removeEventListener('axe:result', onAxeResult);
143
- win.__AXE_WATCHER_HAS_VISITED = false;
144
144
  resolve(results);
145
145
  };
146
146
  win.addEventListener('axe:flush-end', onFlushEnd);
@@ -148,11 +148,8 @@ function axeWatcherFlushCommand() {
148
148
  const event = new CustomEvent('axe:flush-start');
149
149
  win.dispatchEvent(event);
150
150
  }).then(results => {
151
- // Generate a random-enough filename to avoid collisions.
152
- const time = new Date().getTime();
153
- const rnd = Math.random().toString(36).slice(2);
154
- const filename = `cypress/axe-watcher/${time}-${rnd}.json`;
155
- cy.writeFile(filename, JSON.stringify(results, null, 2));
151
+ cy.task('__uploadAxeWatcherResults', results, { log: false });
152
+ logDebugAxeWatcher({ message: 'Flush: complete' });
156
153
  });
157
154
  });
158
155
  }
@@ -160,26 +157,31 @@ const doesCypressCommandExist = (commandName) => {
160
157
  //@ts-expect-error - Property 'cy' does not exist on type 'Cypress & CyEventEmitter'.ts(2339)
161
158
  return !!Cypress.cy[commandName];
162
159
  };
163
- function axeWatcherAnalyzeCommand({ __UserRequestedAnalyze = true } = {}) {
160
+ function axeWatcherAnalyzeCommand({ __Method, __UserRequestedAnalyze = true } = {}) {
161
+ logDebugAxeWatcher({
162
+ message: `Analyze: Invoked${__Method ? ` - ${__Method}` : ''}`
163
+ });
164
164
  const userRequestedAnalyze = __UserRequestedAnalyze;
165
165
  cy.window().then(win => {
166
166
  if (!shouldAnalyzeLocation(win.location)) {
167
- return Promise.resolve();
167
+ return Promise.resolve({ message: `Skipped - Invalid protocol` });
168
168
  }
169
169
  // If the user didn't request an analyze, and we're in manual mode, don't do anything.
170
170
  if (isStopped && !userRequestedAnalyze) {
171
- return Promise.resolve();
171
+ return Promise.resolve({ message: `Skipped (Manual mode)` });
172
172
  }
173
173
  return new Promise(resolve => {
174
- const fn = () => {
174
+ const fn = (event) => {
175
175
  win.removeEventListener('axe:manual-mode-analyze-done', fn);
176
- resolve();
176
+ resolve(event.detail);
177
177
  };
178
178
  win.addEventListener('axe:manual-mode-analyze-done', fn);
179
179
  const event = new CustomEvent('axe:manual-mode-analyze', {
180
180
  detail: { userRequestedAnalyze }
181
181
  });
182
182
  win.dispatchEvent(event);
183
+ }).then(result => {
184
+ logDebugAxeWatcher({ message: `Analyze: ${result === null || result === void 0 ? void 0 : result.message}` });
183
185
  });
184
186
  });
185
187
  }