Skip to content

Commit 08a444a

Browse files
Dennis BergevinDennis Bergevin
Dennis Bergevin
authored and
Dennis Bergevin
committed
feat: consolidate import
1 parent b5a9ec6 commit 08a444a

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ npm install --save-dev cypress-plugin-last-failed
4343
2. In `cypress/support/e2e.js` (For E2E tests) and/or `cypress/support/component.js` (For Component tests),
4444

4545
```js
46-
import { failedTestToggle } from 'cypress-plugin-last-failed/src/toggle';
46+
import { failedTestToggle } from 'cypress-plugin-last-failed';
4747

4848
const registerCypressGrep = require('@bahmutov/cy-grep');
4949
registerCypressGrep();

cypress/support/e2e.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// ***********************************************************
1515

1616
// Import commands.js using ES2015 syntax:
17-
import { failedTestToggle } from '../../src/toggle';
17+
import { failedTestToggle } from '../../src';
1818
import './commands';
1919

2020
failedTestToggle();

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs');
22
const path = require('path');
3-
3+
const failedTestToggle = require('./toggle');
44
/**
55
* Collects failed tests from the most recent Cypress test run
66
*
@@ -52,4 +52,4 @@ const collectFailingTests = (on, config) => {
5252
return collectFailingTests;
5353
};
5454

55-
module.exports = { collectFailingTests };
55+
module.exports = { collectFailingTests, failedTestToggle };

src/toggle.js

+26-25
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const grepFailed = () => {
3232
* Toggle for use within a spec file during `cypress open`
3333
*/
3434

35-
export const failedTestToggle = () => {
35+
const failedTestToggle = () => {
3636
const hasStyles = top?.document.querySelector('#runFailedStyle');
3737
const hasToggleButton = top?.document.querySelector('#runFailedToggle');
3838
const defaultStyles = `
@@ -166,29 +166,30 @@ export const failedTestToggle = () => {
166166
runFailedTooltipElement.innerHTML = turnOffRunFailedDescription;
167167
}
168168
});
169-
};
169+
// Wrapping logic within isInteractive check
170+
// This targets cypress open mode where user can switch specs
171+
if (Cypress.config('isInteractive')) {
172+
Cypress.on('window:unload', () => {
173+
// Store the current Cypress test runner url
174+
// This is to check against any spec change in test runner while the grep filter is activated
175+
// If a user does switch spec while filter is active, the filter will be reset
176+
const sidebarRunsLinkPage = window.top?.document.querySelector(
177+
'[data-cy="sidebar-link-runs-page"]'
178+
);
179+
const runFailedToggleElement =
180+
window.top?.document.querySelector('#runFailedToggle');
181+
182+
if (
183+
window.top?.document.URL !=
184+
sidebarRunsLinkPage.getAttribute('data-url') &&
185+
runFailedToggleElement.checked
186+
) {
187+
runFailedToggleElement.click();
188+
}
170189

171-
// Wrapping logic within isInteractive check
172-
// This targets cypress open mode where user can switch specs
173-
if (Cypress.config('isInteractive')) {
174-
Cypress.on('window:unload', () => {
175-
// Store the current Cypress test runner url
176-
// This is to check against any spec change in test runner while the grep filter is activated
177-
// If a user does switch spec while filter is active, the filter will be reset
178-
const sidebarRunsLinkPage = window.top?.document.querySelector(
179-
'[data-cy="sidebar-link-runs-page"]'
180-
);
181-
const runFailedToggleElement =
182-
window.top?.document.querySelector('#runFailedToggle');
183-
184-
if (
185-
window.top?.document.URL !=
186-
sidebarRunsLinkPage.getAttribute('data-url') &&
187-
runFailedToggleElement.checked
188-
) {
189-
runFailedToggleElement.click();
190-
}
190+
sidebarRunsLinkPage.setAttribute('data-url', window.top?.document.URL);
191+
});
192+
}
193+
};
191194

192-
sidebarRunsLinkPage.setAttribute('data-url', window.top?.document.URL);
193-
});
194-
}
195+
module.exports = failedTestToggle;

0 commit comments

Comments
 (0)