-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c052e84
Showing
7 changed files
with
4,229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"endOfLine": "lf", | ||
"quoteProps": "consistent", | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# cypress-helper-getcy | ||
|
||
A simple [Cypress](https://www.cypress.io/) [command](https://docs.cypress.io/api/cypress-api/custom-commands.html) for getting elements via `data-cy` attributes. | ||
|
||
[![npm version](https://img.shields.io/npm/v/cypress-helper-getcy.svg?style=flat-square) ![npm downloads](https://img.shields.io/npm/dm/cypress-helper-getcy?style=flat-square)](https://www.npmjs.com/package/cypress-helper-getcy) | ||
|
||
## Inspiration | ||
|
||
- [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements) | ||
|
||
### Why not just `cy.get('[data-cy=submit]')`? | ||
|
||
Well, I like clean tests, and I found both the test code and logs to be rather ugly and harder to read when doing that. So I wanted something cleaner, and made this, which cleans up both the code and the log. 👍 | ||
|
||
## Setup | ||
|
||
### 1. Install | ||
|
||
```shell | ||
npm install --save-dev cypress-helper-getcy | ||
``` | ||
|
||
### 2. Include | ||
|
||
```js | ||
// E.g. in cypress/support/index.js | ||
include 'cypress-helper-getcy'; | ||
``` | ||
|
||
## Usage | ||
|
||
```html | ||
<div data-cy="my-test-subject"></div> | ||
``` | ||
|
||
```js | ||
it('finds my test subject', () => { | ||
cy.getCy('my-test-subject').should('exist'); | ||
}); | ||
``` | ||
|
||
_**Note:** See [tests](test/tests/getCy.ts) for more examples._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const DELAY = 1500; | ||
const LOG_TAG = '[cypress-hmr-restarter]'; | ||
|
||
const clickRestart = win => { | ||
const btn = win.top.document.querySelector('.restart'); | ||
btn && btn.click(); | ||
}; | ||
|
||
Cypress.on('window:load', win => { | ||
const host = Cypress.config().baseUrl.replace(/https?/, 'wss'); | ||
const socket = new WebSocket(`${host}/sockjs-node`); | ||
|
||
socket.onopen = () => console.debug(LOG_TAG, 'Connected to HMR socket'); | ||
socket.onclose = () => console.debug(LOG_TAG, 'Disconnected from HMR socket'); | ||
socket.onmessage = e => { | ||
const { type } = JSON.parse(e.data); | ||
switch (type) { | ||
case 'invalid': | ||
console.debug(LOG_TAG, `Restarting due to HMR in ${DELAY}ms...`); | ||
// TODO: Debounce this somehow? | ||
setTimeout(() => clickRestart(win), DELAY); | ||
break; | ||
} | ||
}; | ||
}); |
Oops, something went wrong.