@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.
- package/dist/esm/src/feature/helpers/visit.js +1 -3
- package/dist/esm/src/feature/matchers/toHaveSelector.js +18 -11
- package/dist/esm/src/feature/matchers/toMatchTextContent.js +22 -13
- package/dist/types/src/feature/helpers/visit.d.ts +2 -4
- package/dist/types/src/feature/matchers/toHaveSelector.d.ts +2 -2
- package/dist/types/src/feature/matchers/toMatchTextContent.d.ts +4 -2
- package/package.json +1 -1
- package/src/feature/helpers/visit.ts +1 -5
- package/src/feature/matchers/toHaveSelector.ts +18 -17
- package/src/feature/matchers/toMatchTextContent.ts +25 -18
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
8
|
-
|
|
5
|
+
pass: true,
|
|
6
|
+
message: () => `
|
|
7
|
+
expected no selector: ${selector}
|
|
8
|
+
but the selector was found
|
|
9
|
+
`,
|
|
9
10
|
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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:
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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,5 @@
|
|
|
1
1
|
import { Page } from 'puppeteer';
|
|
2
|
-
export default function toHaveSelector(page: Page,
|
|
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(
|
|
3
|
-
|
|
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,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
|
-
{
|
|
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,
|
|
6
|
-
|
|
7
|
-
page
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
|
|
18
|
-
|
|
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(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
13
|
-
|
|
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
|
}
|