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

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,21 @@
1
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
2
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
3
- export default async function toHaveSelector(page, expectedSelector) {
4
- return await evaluateWithRetryAndTimeout(page, async () => {
5
- requirePuppeteerPage(page);
1
+ export default async function toHaveSelector(page, selector) {
2
+ try {
3
+ await page.waitForSelector(selector);
6
4
  return {
7
- pass: !!(await page.$(expectedSelector)),
8
- actual: expectedSelector,
5
+ pass: true,
6
+ message: () => `
7
+ expected no selector: ${selector}
8
+ but the selector was found
9
+ `,
9
10
  };
10
- }, {
11
- successText: r => `Expected ${r} to have selector: ${expectedSelector}`,
12
- failureText: r => `Expected ${r} not to have selector: ${expectedSelector}`,
13
- });
11
+ }
12
+ catch {
13
+ return {
14
+ pass: false,
15
+ message: () => `
16
+ expected selector: ${selector}
17
+ but no selector was found
18
+ `,
19
+ };
20
+ }
14
21
  }
@@ -1,16 +1,25 @@
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);
1
+ export default async function toMatchTextContent(page, text, { selector = 'body' } = {}) {
2
+ try {
3
+ await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`);
8
4
  return {
9
- pass: actual.includes(expected),
10
- actual,
5
+ pass: true,
6
+ message: () => `
7
+ expected no ${selector} with text:
8
+ ${text}
9
+
10
+ but text was found with that selector
11
+ `,
11
12
  };
12
- }, {
13
- successText: r => `Expected ${r} to match text ${expected}`,
14
- failureText: r => `Expected ${r} not to match text ${expected}`,
15
- });
13
+ }
14
+ catch {
15
+ return {
16
+ pass: false,
17
+ message: () => `
18
+ expected ${selector} with text:
19
+ ${text}
20
+
21
+ but no text was found within that selector
22
+ `,
23
+ };
24
+ }
16
25
  }
@@ -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,5 @@
1
1
  import { Page } from 'puppeteer';
2
- export default function toHaveSelector(page: Page, expectedSelector: string): Promise<{
3
- message: () => string;
2
+ export default function toHaveSelector(page: Page, selector: string): Promise<{
4
3
  pass: boolean;
4
+ message: () => string;
5
5
  }>;
@@ -1,5 +1,7 @@
1
1
  import { Page } from 'puppeteer';
2
- export default function toMatchTextContent(argumentPassedToExpect: Page, expected: string): Promise<{
3
- message: () => string;
2
+ export default function toMatchTextContent(page: Page, text: string, { selector }?: {
3
+ selector?: string;
4
+ }): Promise<{
4
5
  pass: boolean;
6
+ message: () => string;
5
7
  }>;
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-4",
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,22 @@
1
1
  import { Page } from 'puppeteer'
2
- import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js'
3
- import requirePuppeteerPage from '../internal/requirePuppeteerPage.js'
4
2
 
5
- 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}`,
3
+ export default async function toHaveSelector(page: Page, selector: string) {
4
+ try {
5
+ await page.waitForSelector(selector)
6
+ return {
7
+ pass: true,
8
+ message: () => `
9
+ expected no selector: ${selector}
10
+ but the selector was found
11
+ `,
12
+ }
13
+ } catch {
14
+ return {
15
+ pass: false,
16
+ message: () => `
17
+ expected selector: ${selector}
18
+ but no selector was found
19
+ `,
19
20
  }
20
- )
21
+ }
21
22
  }
@@ -1,23 +1,30 @@
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)
3
+ export default async function toMatchTextContent(
4
+ page: Page,
5
+ text: string,
6
+ { selector = 'body' }: { selector?: string } = {}
7
+ ) {
8
+ try {
9
+ await page.waitForSelector(`${selector}::-p-text(${text.replace(/"/g, '\\"')})`)
10
+ return {
11
+ pass: true,
12
+ message: () => `
13
+ expected no ${selector} with text:
14
+ ${text}
11
15
 
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}`,
16
+ but text was found with that selector
17
+ `,
21
18
  }
22
- )
19
+ } catch {
20
+ return {
21
+ pass: false,
22
+ message: () => `
23
+ expected ${selector} with text:
24
+ ${text}
25
+
26
+ but no text was found within that selector
27
+ `,
28
+ }
29
+ }
23
30
  }