Skip to content

Commit

Permalink
feat: migrate cypress hooks (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
seren5240 authored Apr 11, 2024
1 parent bb6f67d commit da228c1
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion .grit/patterns/js/cypress_to_playwright.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pattern convert_cypress_queries() {
`cy.contains($text, $options)` => `await expect(page.getByText($text)).toBeVisible($options)`,
`cy.contains($text)` => `await expect(page.getByText($text)).toBeVisible()`,
`cy.log($log)` => `console.log($log)`,
`cy.wait($timeout)` => `await page.waitForTimeout($timeout)`,
`Cypress.env('$var')` => `process.env.$var`,
`cy.onlyOn($var === $cond)` => `if ($var !== $cond) {
test.skip();
Expand Down Expand Up @@ -64,7 +65,14 @@ pattern convert_cypress_queries() {
pattern convert_cypress_test() {
or {
`describe($description, $suite)` => `test.describe($description, $suite)`,
`describe($description, $suite)` => `test.describe($description, $suite)` where {
$suite <: maybe contains bubble or {
`before($hook)` => `test.beforeAll(async $hook)`,
`beforeEach($hook)` => `test.beforeEach(async $hook)`,
`after($hook)` => `test.afterAll(async $hook)`,
`afterEach($hook)` => `test.afterEach(async $hook)`,
},
},
or {
`it($description, () => { $body })`,
`test($description, () => { $body })`
Expand Down Expand Up @@ -139,3 +147,33 @@ await request.post('/submit', {
});
await expect(page.getByText('Submitted')).toBeVisible({ timeout: 10000 });
```

## Converts hooks

```js
describe('Grouping', function () {
before(function () {
setup();
});

afterEach(function () {
cy.wait(1000);
teardown();
});
});
```

```ts
import { expect, test } from '@playwright/test';

test.describe('Grouping', function () {
test.beforeAll(async function () {
setup();
});

test.afterEach(async function () {
await page.waitForTimeout(1000);
teardown();
});
});
```

0 comments on commit da228c1

Please sign in to comment.