Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Commit 7b4de11

Browse files
committed
feat: export functions, close #5
1 parent 87daa78 commit 7b4de11

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

README.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ it('skips this test when running on Mac', () => {
1717
npm install -D @cypress/skip-test
1818
```
1919

20-
Then add this module to your support file `cypress/support/index.js`
20+
## Example
21+
22+
You can use this module as custom Cypress commands `cy.skipOn` and `cy.onlyOn` or by importing its functions. To use custom commands, add this module to your support file `cypress/support/index.js`
2123

2224
```js
2325
require('@cypress/skip-test')
2426
```
2527

26-
## Example
27-
2828
### `cy.skipOn`
2929

3030
Skip this test if running in Electron browser
@@ -65,6 +65,22 @@ it('only tests localhost', () => {
6565
})
6666
```
6767

68+
### imports
69+
70+
```js
71+
import { onlyOn, skipOn } from '../..'
72+
73+
it('runs only on Mac', () => {
74+
// using the exported function instead of
75+
// the custom command cy.onlyOn(...)
76+
onlyOn('mac')
77+
})
78+
79+
it('skips on Mac', () => {
80+
skipOn('darwin')
81+
})
82+
```
83+
6884
### Notes
6985

7086
You can chain conditions together

cypress/integration/import-spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference types="cypress" />
2+
import { onlyOn, skipOn } from '../..'
3+
4+
it('runs only on Mac', () => {
5+
// using the exported function instead of
6+
// the custom command cy.onlyOn(...)
7+
onlyOn('mac')
8+
})
9+
10+
it('skips on Mac', () => {
11+
skipOn('darwin')
12+
})

index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const matchesUrlPart = normalizedName => {
3030
return url && url.includes(normalizedName)
3131
}
3232

33-
Cypress.Commands.add('skipOn', name => {
33+
/**
34+
* Skips the current test based on the browser, platform or url.
35+
*/
36+
export const skipOn = name => {
3437
if (!_.isString(name) || '') {
3538
throw new Error(
3639
'Invalid syntax: cy.skipOn(<name>), for example cy.skipOn("linux")'
@@ -62,9 +65,12 @@ Cypress.Commands.add('skipOn', name => {
6265
if (matchesUrlPart(normalizedName)) {
6366
return skip()
6467
}
65-
})
68+
}
6669

67-
Cypress.Commands.add('onlyOn', name => {
70+
/**
71+
* Runs the current test only in the specified browser, platform or against url.
72+
*/
73+
export const onlyOn = name => {
6874
if (!_.isString(name) || '') {
6975
throw new Error(
7076
'Invalid syntax: cy.onlyOn(<name>), for example cy.onlyOn("linux")'
@@ -92,4 +98,8 @@ Cypress.Commands.add('onlyOn', name => {
9298
if (!matchesUrlPart(normalizedName)) {
9399
return skip()
94100
}
95-
})
101+
}
102+
103+
Cypress.Commands.add('skipOn', skipOn)
104+
105+
Cypress.Commands.add('onlyOn', onlyOn)

0 commit comments

Comments
 (0)