Skip to content

Commit

Permalink
feat: implement pause and debug commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Solant committed Oct 11, 2024
1 parent fcdc73c commit ef9f2b9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
4 changes: 2 additions & 2 deletions COMPATIBILITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
| [.clearCookies()](https://docs.cypress.io/api/commands/clearcookies) | 🕓 | 🕓 | |
| [.clearLocalStorage()](https://docs.cypress.io/api/commands/clearlocalstorage) | 🕓 | 🕓 | |
| [.clock()](https://docs.cypress.io/api/commands/clock) | 🕓 | 🕓 | |
| [.debug()](https://docs.cypress.io/api/commands/debug) | 🕓 | 🕓 | |
| [.debug()](https://docs.cypress.io/api/commands/debug) | | - | |
| [.each()](https://docs.cypress.io/api/commands/each) | 🕓 | 🕓 | |
| [.end()](https://docs.cypress.io/api/commands/end) | 🕓 | 🕓 | |
| [.exec()](https://docs.cypress.io/api/commands/exec) | 🕓 | 🕓 | |
Expand All @@ -97,7 +97,7 @@
| [.log()](https://docs.cypress.io/api/commands/log) | 🕓 | 🕓 | |
| [.mount()](https://docs.cypress.io/api/commands/mount) | 🕓 | 🕓 | |
| [.origin()](https://docs.cypress.io/api/commands/origin) | 🕓 | 🕓 | |
| [.pause()](https://docs.cypress.io/api/commands/pause) | 🕓 | 🕓 | |
| [.pause()](https://docs.cypress.io/api/commands/pause) | | - | |
| [.reload()](https://docs.cypress.io/api/commands/reload) | 🕓 | 🕓 | |
| [.request()](https://docs.cypress.io/api/commands/request) | 🕓 | 🕓 | |
| [.screenshot()](https://docs.cypress.io/api/commands/screenshot) | 🕓 | 🕓 | |
Expand Down
15 changes: 5 additions & 10 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export type Action = AssertActions | {
key: string,
} | {
type: 'title'
} | {
type: 'pause'
};

let queue: Array<Action> = [];
Expand All @@ -70,16 +72,6 @@ function resolveSelectorItem(parent: Locator | Page, selector: Selector[number])
}
}

export function getLocator(page: Page, selector: Selector): Locator {
let locator = resolveSelectorItem(page, selector[0]);

for (let i = 1; i < selector.length; i += 1) {
locator = resolveSelectorItem(locator, selector[i]);
}

return locator;
}

export type Subject = { type: 'locator', value: Locator } | { type: 'value', value: unknown };

export async function evaluateAction(
Expand Down Expand Up @@ -179,6 +171,9 @@ export async function evaluateAction(
break;
case 'title':
return { type: 'value', value: await page.title() };
case 'pause':
await page.pause();
break;
default:
throw new Error(`Action type "${(action as Record<string, unknown>).type}" is not implemented`);
}
Expand Down
10 changes: 10 additions & 0 deletions src/cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class Cy {
return this.selfOrChild();
}

debug() {
pushQueue({ type: 'pause' });
return this.selfOrChild();
}

pause() {
pushQueue({ type: 'pause' });
return this.selfOrChild();
}

first() {
pushQueue({ type: 'locator', selector: [{ modifier: 'first' }], root: this.root });
return this.selfOrChild();
Expand Down
9 changes: 9 additions & 0 deletions tests/api/other-commands/debug.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { setup } from '../../../src';

setup();

describe('.debug()', () => {
it('basic usage', () => {
cy.visit('https://example.cypress.io/todo').get('button').debug();
})
})
9 changes: 9 additions & 0 deletions tests/api/other-commands/pause.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { setup } from '../../../src';

setup();

describe('.pause()', () => {
it('basic usage', () => {
cy.visit('https://example.cypress.io/todo').get('button').pause();
})
})

0 comments on commit ef9f2b9

Please sign in to comment.