From Cypress
Replace Cypress command chains with async tests and keep your data-cy attributes.
e2e replaces Cypress command chains with async TypeScript tests that run in Node. Both suites can stay in the project while you move one spec at a time.
agent prompt
For a migration that spans several sessions, the migrate-to-e2e skill records what moved in a progress file and keeps the old suite running until you retire each test.
Port the config
Install e2e and configure a model with the quickstart. The example below uses an agent call.
Keep your data-cy attributes. The config below reads them as test ids.
e2e.config.ts
import type { E2EConfig } from 'e2e';
import { web } from '@e2e-dev/web';
export default {
targets: [{
engine: web({ testIdAttribute: 'data-cy' }),
app: { url: 'http://localhost:3000' },
}],
} satisfies E2EConfig;Rewrite one spec
Start with a spec that often breaks.
Cypress
describe('todos', () => {
it('completes one', () => {
cy.visit('/todos');
cy.get('[data-cy=new-todo]').type('Buy milk{enter}');
cy.get('[data-cy=new-todo]').type('Walk the dog{enter}');
cy.contains('li', 'Buy milk').find('[data-cy=toggle]').click();
cy.get('[data-cy=todo]').should('have.length', 2);
cy.contains('1 item left').should('be.visible');
});
});e2e
import { describe, test } from '@e2e-dev/web';
import { expect } from 'e2e';
describe('todos', () => {
test('completes one', async ({ app, agent, screen }) => {
await app.open('/todos');
await agent.act('add todos "Buy milk" and "Walk the dog"');
await expect(screen.getByTestId('todo')).toHaveCount(2);
await agent.act('complete "Buy milk"');
await expect(screen.getByText('1 item left')).toBeVisible();
});
});Map each command
Two things differ from Cypress:
- There is no chain. Await each call on its own line. It returns a value:
const text = await locator.textContent(). - Actions and single-node reads and assertions need one match. Several fail
with
LOCATOR_AMBIGUOUS. Narrow with.filter(),.first(), or.nth(). See screen.
