@rvoh/psychic-spec-helpers 0.3.1-fgbeta-2 → 0.3.1-fgbeta-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,4 @@
1
- import launchPage from './launchPage.js';
2
- export default async function visit(path, { page, baseUrl = 'http://localhost:3000' } = {}) {
3
- page ||= await launchPage();
1
+ export default async function visit(path, { baseUrl = 'http://localhost:3000' } = {}) {
4
2
  await page.goto(`${baseUrl}/${path.replace(/^\//, '')}`);
5
3
  return page;
6
4
  }
@@ -1,14 +1,3 @@
1
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
2
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
3
1
  export default async function toHaveSelector(page, expectedSelector) {
4
- return await evaluateWithRetryAndTimeout(page, async () => {
5
- requirePuppeteerPage(page);
6
- return {
7
- pass: !!(await page.$(expectedSelector)),
8
- actual: expectedSelector,
9
- };
10
- }, {
11
- successText: r => `Expected ${r} to have selector: ${expectedSelector}`,
12
- failureText: r => `Expected ${r} not to have selector: ${expectedSelector}`,
13
- });
2
+ await page.waitForSelector(expectedSelector);
14
3
  }
@@ -1,16 +1,3 @@
1
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
2
- import getAllTextContentFromPage from '../internal/getAllTextContentFromPage.js';
3
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
4
- export default async function toMatchTextContent(argumentPassedToExpect, expected) {
5
- return await evaluateWithRetryAndTimeout(argumentPassedToExpect, async () => {
6
- requirePuppeteerPage(argumentPassedToExpect);
7
- const actual = await getAllTextContentFromPage(argumentPassedToExpect);
8
- return {
9
- pass: actual.includes(expected),
10
- actual,
11
- };
12
- }, {
13
- successText: r => `Expected ${r} to match text ${expected}`,
14
- failureText: r => `Expected ${r} not to match text ${expected}`,
15
- });
1
+ export default async function toMatchTextContent(page, text, { selector = 'body' } = {}) {
2
+ await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`);
16
3
  }
@@ -1,5 +1,3 @@
1
- import { Page } from 'puppeteer';
2
- export default function visit(path: string, { page, baseUrl }?: {
3
- page?: Page;
1
+ export default function visit(path: string, { baseUrl }?: {
4
2
  baseUrl?: string;
5
- }): Promise<Page>;
3
+ }): Promise<import("puppeteer").Page>;
@@ -1,5 +1,2 @@
1
1
  import { Page } from 'puppeteer';
2
- export default function toHaveSelector(page: Page, expectedSelector: string): Promise<{
3
- message: () => string;
4
- pass: boolean;
5
- }>;
2
+ export default function toHaveSelector(page: Page, expectedSelector: string): Promise<void>;
@@ -1,5 +1,4 @@
1
1
  import { Page } from 'puppeteer';
2
- export default function toMatchTextContent(argumentPassedToExpect: Page, expected: string): Promise<{
3
- message: () => string;
4
- pass: boolean;
5
- }>;
2
+ export default function toMatchTextContent(page: Page, text: string, { selector }?: {
3
+ selector?: string;
4
+ }): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic-spec-helpers",
4
- "version": "0.3.1-fgbeta-2",
4
+ "version": "0.3.1-fgbeta-3",
5
5
  "description": "psychic framework spec helpers",
6
6
  "main": "./dist/cjs/src/index.js",
7
7
  "module": "./dist/esm/src/index.js",
@@ -1,11 +1,7 @@
1
- import { Page } from 'puppeteer'
2
- import launchPage from './launchPage.js'
3
-
4
1
  export default async function visit(
5
2
  path: string,
6
- { page, baseUrl = 'http://localhost:3000' }: { page?: Page; baseUrl?: string } = {}
3
+ { baseUrl = 'http://localhost:3000' }: { baseUrl?: string } = {}
7
4
  ) {
8
- page ||= await launchPage()
9
5
  await page.goto(`${baseUrl}/${path.replace(/^\//, '')}`)
10
6
  return page
11
7
  }
@@ -1,21 +1,5 @@
1
1
  import { Page } from 'puppeteer'
2
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js'
3
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js'
4
2
 
5
3
  export default async function toHaveSelector(page: Page, expectedSelector: string) {
6
- return await evaluateWithRetryAndTimeout(
7
- page,
8
- async () => {
9
- requirePuppeteerPage(page)
10
-
11
- return {
12
- pass: !!(await page.$(expectedSelector)),
13
- actual: expectedSelector,
14
- }
15
- },
16
- {
17
- successText: r => `Expected ${r} to have selector: ${expectedSelector}`,
18
- failureText: r => `Expected ${r} not to have selector: ${expectedSelector}`,
19
- }
20
- )
4
+ await page.waitForSelector(expectedSelector)
21
5
  }
@@ -1,23 +1,9 @@
1
1
  import { Page } from 'puppeteer'
2
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js'
3
- import getAllTextContentFromPage from '../internal/getAllTextContentFromPage.js'
4
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js'
5
2
 
6
- export default async function toMatchTextContent(argumentPassedToExpect: Page, expected: string) {
7
- return await evaluateWithRetryAndTimeout(
8
- argumentPassedToExpect,
9
- async () => {
10
- requirePuppeteerPage(argumentPassedToExpect)
11
-
12
- const actual = await getAllTextContentFromPage(argumentPassedToExpect)
13
- return {
14
- pass: actual.includes(expected),
15
- actual,
16
- }
17
- },
18
- {
19
- successText: r => `Expected ${r} to match text ${expected}`,
20
- failureText: r => `Expected ${r} not to match text ${expected}`,
21
- }
22
- )
3
+ export default async function toMatchTextContent(
4
+ page: Page,
5
+ text: string,
6
+ { selector = 'body' }: { selector?: string } = {}
7
+ ) {
8
+ await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`)
23
9
  }