Skip to content

Commit 708ed31

Browse files
authored
Merge pull request #11 from filiphric/9-error-reading-setattribute-in-cypress-v1300
9 error reading setattribute in cypress v1300
2 parents 5ce69d6 + 0968870 commit 708ed31

10 files changed

+2376
-176
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules/
2-
dist/
2+
dist/
3+
cypress/videos
4+
cypress/screenshots

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## 1.2.0 (2024-02-18)
6+
7+
8+
### Features
9+
10+
* initial commit ([e16eba0](https://github.com/filiphric/cypress-plugin-xhr-toggle/commits/e16eba04542322227a6ce29bab8e217a016e7f95))
11+
512
## 1.1.0 (2023-02-16)
613

714

cypress.config.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
/* eslint-disable @typescript-eslint/no-unused-vars */
12
import { defineConfig } from "cypress";
3+
import { plugin as replayPlugin } from "@replayio/cypress";
24

35
export default defineConfig({
46
fixturesFolder: false,
57
e2e: {
8+
// eslint-disable-next-line @typescript-eslint/no-empty-function
69
setupNodeEvents(on, config) {
7-
// implement node event listeners here
8-
},
9-
env: {
10-
hideXhr: true
11-
}
10+
replayPlugin(on, config, {
11+
upload: true,
12+
apiKey: process.env.REPLAY_API_KEY,
13+
});
14+
return config;
15+
},
1216
},
1317
});

cypress/e2e/spec.cy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
it('test', () => {
22

3-
expect(true).to.be.true
3+
cy.visit('/server/index.html')
44

55
});

cypress/support/e2e.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
import '../../dist/index'
2+
import '@replayio/cypress/support';

dist/addStyles.js

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const addStyles = () => {
2-
const { $ } = Cypress;
32
const hasStyles = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrStyle');
43
const hasToggleButton = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle');
54
const defaultStyles = `
@@ -45,6 +44,9 @@ export const addStyles = () => {
4544
border-style: solid;
4645
border-color: transparent transparent #f3f4fa transparent;
4746
}
47+
.reporter:has(#xhrToggle:checked) .command.command-name-request:has(.command-is-event) {
48+
display:none
49+
}
4850
`;
4951
const turnOffXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 6.5c2.76 0 5 2.24 5 5c0 .51-.1 1-.24 1.46l3.06 3.06c1.39-1.23 2.49-2.77 3.18-4.53C21.27 7.11 17 4 12 4c-1.27 0-2.49.2-3.64.57l2.17 2.17c.47-.14.96-.24 1.47-.24zM2.71 3.16a.996.996 0 0 0 0 1.41l1.97 1.97A11.892 11.892 0 0 0 1 11.5C2.73 15.89 7 19 12 19c1.52 0 2.97-.3 4.31-.82l2.72 2.72a.996.996 0 1 0 1.41-1.41L4.13 3.16c-.39-.39-1.03-.39-1.42 0zM12 16.5c-2.76 0-5-2.24-5-5c0-.77.18-1.5.49-2.14l1.57 1.57c-.03.18-.06.37-.06.57c0 1.66 1.34 3 3 3c.2 0 .38-.03.57-.07L14.14 16c-.65.32-1.37.5-2.14.5zm2.97-5.33a2.97 2.97 0 0 0-2.64-2.64l2.64 2.64z"/></svg>`;
5052
const turnOnXhrIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="17" height="17" viewBox="0 0 24 24"><path fill="#afb3c7" d="M12 4C7 4 2.73 7.11 1 11.5C2.73 15.89 7 19 12 19s9.27-3.11 11-7.5C21.27 7.11 17 4 12 4zm0 12.5c-2.76 0-5-2.24-5-5s2.24-5 5-5s5 2.24 5 5s-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3s3-1.34 3-3s-1.34-3-3-3z"/></svg>`;
@@ -82,37 +84,32 @@ export const addStyles = () => {
8284
headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleInput);
8385
headerToggleButton === null || headerToggleButton === void 0 ? void 0 : headerToggleButton.appendChild(headerToggleLabel);
8486
}
85-
const xhrToggleElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrToggle');
86-
const xhrToggleLabelElement = top === null || top === void 0 ? void 0 : top.document.querySelector('[for=xhrToggle]');
87-
const xhrTooltipElement = top === null || top === void 0 ? void 0 : top.document.querySelector('#xhrTooltip');
88-
const hideXhr = () => {
89-
$("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "none");
90-
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
91-
xhrTooltipElement.innerHTML = turnOnXhrDescription;
92-
};
93-
const showXhr = () => {
94-
$("#unified-reporter", top === null || top === void 0 ? void 0 : top.document).find(".command.command-name-request").has(".command-is-event").css("display", "block");
95-
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
96-
xhrTooltipElement.innerHTML = turnOffXhrDescription;
97-
};
98-
if (Cypress.env('hideXhr')) {
99-
xhrToggleElement.setAttribute('checked', 'true');
100-
Cypress.on('log:added', () => {
101-
hideXhr();
102-
});
103-
}
104-
else {
105-
// just to be on the safe side when changing hideXhr variable
106-
xhrToggleElement.setAttribute('checked', 'false');
107-
showXhr();
87+
const xhrToggleElement = top.document.querySelector('#xhrToggle');
88+
const xhrToggleLabelElement = top.document.querySelector('[for=xhrToggle]');
89+
const xhrTooltipElement = top.document.querySelector('#xhrTooltip');
90+
if (xhrToggleElement && xhrToggleLabelElement && xhrTooltipElement) {
91+
if (Cypress.env('hideXhr') === true || Cypress.env('hideXhr') === undefined) {
92+
xhrToggleElement.checked = true;
93+
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
94+
xhrTooltipElement.innerHTML = turnOnXhrDescription;
95+
}
96+
else {
97+
xhrToggleElement.checked = false;
98+
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
99+
xhrTooltipElement.innerHTML = turnOffXhrDescription;
100+
}
108101
}
109-
xhrToggleElement.addEventListener('change', (e) => {
102+
xhrToggleElement === null || xhrToggleElement === void 0 ? void 0 : xhrToggleElement.addEventListener('change', (e) => {
110103
// @ts-ignore errors about HTMLElement
111104
if (e.target.checked) {
112-
hideXhr();
105+
// when checked, xhr elements are hidden
106+
xhrToggleLabelElement.innerHTML = turnOnXhrIcon;
107+
xhrTooltipElement.innerHTML = turnOnXhrDescription;
113108
}
114109
else {
115-
showXhr();
110+
// when unchecked, xhr elements are visible
111+
xhrToggleLabelElement.innerHTML = turnOffXhrIcon;
112+
xhrTooltipElement.innerHTML = turnOffXhrDescription;
116113
}
117114
});
118115
};

0 commit comments

Comments
 (0)