Skip to content

Commit da228c1

Browse files
authored
feat: migrate cypress hooks (#186)
1 parent bb6f67d commit da228c1

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

.grit/patterns/js/cypress_to_playwright.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pattern convert_cypress_queries() {
3737
`cy.contains($text, $options)` => `await expect(page.getByText($text)).toBeVisible($options)`,
3838
`cy.contains($text)` => `await expect(page.getByText($text)).toBeVisible()`,
3939
`cy.log($log)` => `console.log($log)`,
40+
`cy.wait($timeout)` => `await page.waitForTimeout($timeout)`,
4041
`Cypress.env('$var')` => `process.env.$var`,
4142
`cy.onlyOn($var === $cond)` => `if ($var !== $cond) {
4243
test.skip();
@@ -64,7 +65,14 @@ pattern convert_cypress_queries() {
6465
6566
pattern convert_cypress_test() {
6667
or {
67-
`describe($description, $suite)` => `test.describe($description, $suite)`,
68+
`describe($description, $suite)` => `test.describe($description, $suite)` where {
69+
$suite <: maybe contains bubble or {
70+
`before($hook)` => `test.beforeAll(async $hook)`,
71+
`beforeEach($hook)` => `test.beforeEach(async $hook)`,
72+
`after($hook)` => `test.afterAll(async $hook)`,
73+
`afterEach($hook)` => `test.afterEach(async $hook)`,
74+
},
75+
},
6876
or {
6977
`it($description, () => { $body })`,
7078
`test($description, () => { $body })`
@@ -139,3 +147,33 @@ await request.post('/submit', {
139147
});
140148
await expect(page.getByText('Submitted')).toBeVisible({ timeout: 10000 });
141149
```
150+
151+
## Converts hooks
152+
153+
```js
154+
describe('Grouping', function () {
155+
before(function () {
156+
setup();
157+
});
158+
159+
afterEach(function () {
160+
cy.wait(1000);
161+
teardown();
162+
});
163+
});
164+
```
165+
166+
```ts
167+
import { expect, test } from '@playwright/test';
168+
169+
test.describe('Grouping', function () {
170+
test.beforeAll(async function () {
171+
setup();
172+
});
173+
174+
test.afterEach(async function () {
175+
await page.waitForTimeout(1000);
176+
teardown();
177+
});
178+
});
179+
```

0 commit comments

Comments
 (0)