@rvoh/psychic-spec-helpers 0.2.0

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.
Files changed (109) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +68 -0
  3. package/dist/esm/src/feature/helpers/launchBrowser.js +9 -0
  4. package/dist/esm/src/feature/helpers/launchPage.js +5 -0
  5. package/dist/esm/src/feature/helpers/launchViteServer.js +89 -0
  6. package/dist/esm/src/feature/helpers/providePuppeteerViteMatchers.js +73 -0
  7. package/dist/esm/src/feature/helpers/visit.js +6 -0
  8. package/dist/esm/src/feature/internal/evaluateWithRetryAndTimeout.js +29 -0
  9. package/dist/esm/src/feature/internal/evaluationFailure.js +6 -0
  10. package/dist/esm/src/feature/internal/evaluationSuccess.js +6 -0
  11. package/dist/esm/src/feature/internal/getAllTextContentFromPage.js +19 -0
  12. package/dist/esm/src/feature/internal/isPuppeteerPage.js +3 -0
  13. package/dist/esm/src/feature/internal/matchFailure.js +6 -0
  14. package/dist/esm/src/feature/internal/matchSuccess.js +6 -0
  15. package/dist/esm/src/feature/internal/requirePuppeteerPage.js +6 -0
  16. package/dist/esm/src/feature/matchers/toCheck.js +23 -0
  17. package/dist/esm/src/feature/matchers/toClick.js +25 -0
  18. package/dist/esm/src/feature/matchers/toClickButton.js +25 -0
  19. package/dist/esm/src/feature/matchers/toClickLink.js +25 -0
  20. package/dist/esm/src/feature/matchers/toClickSelector.js +25 -0
  21. package/dist/esm/src/feature/matchers/toFill.js +21 -0
  22. package/dist/esm/src/feature/matchers/toHaveChecked.js +19 -0
  23. package/dist/esm/src/feature/matchers/toHaveLink.js +25 -0
  24. package/dist/esm/src/feature/matchers/toHavePath.js +15 -0
  25. package/dist/esm/src/feature/matchers/toHaveSelector.js +14 -0
  26. package/dist/esm/src/feature/matchers/toHaveUnchecked.js +19 -0
  27. package/dist/esm/src/feature/matchers/toHaveUrl.js +14 -0
  28. package/dist/esm/src/feature/matchers/toMatchTextContent.js +16 -0
  29. package/dist/esm/src/feature/matchers/toNotHaveSelector.js +14 -0
  30. package/dist/esm/src/feature/matchers/toNotMatchTextContent.js +16 -0
  31. package/dist/esm/src/feature/matchers/toUncheck.js +23 -0
  32. package/dist/esm/src/index.js +12 -0
  33. package/dist/esm/src/shared/sleep.js +7 -0
  34. package/dist/esm/src/unit/SpecRequest.js +89 -0
  35. package/dist/esm/src/unit/SpecSession.js +48 -0
  36. package/dist/esm/src/unit/createPsychicServer.js +8 -0
  37. package/dist/esm/src/unit/supersession.js +72 -0
  38. package/dist/types/src/feature/helpers/launchBrowser.d.ts +2 -0
  39. package/dist/types/src/feature/helpers/launchPage.d.ts +2 -0
  40. package/dist/types/src/feature/helpers/launchViteServer.d.ts +6 -0
  41. package/dist/types/src/feature/helpers/providePuppeteerViteMatchers.d.ts +5 -0
  42. package/dist/types/src/feature/helpers/visit.d.ts +5 -0
  43. package/dist/types/src/feature/internal/evaluateWithRetryAndTimeout.d.ts +14 -0
  44. package/dist/types/src/feature/internal/evaluationFailure.d.ts +4 -0
  45. package/dist/types/src/feature/internal/evaluationSuccess.d.ts +4 -0
  46. package/dist/types/src/feature/internal/getAllTextContentFromPage.d.ts +2 -0
  47. package/dist/types/src/feature/internal/isPuppeteerPage.d.ts +1 -0
  48. package/dist/types/src/feature/internal/matchFailure.d.ts +4 -0
  49. package/dist/types/src/feature/internal/matchSuccess.d.ts +4 -0
  50. package/dist/types/src/feature/internal/requirePuppeteerPage.d.ts +1 -0
  51. package/dist/types/src/feature/matchers/toCheck.d.ts +5 -0
  52. package/dist/types/src/feature/matchers/toClick.d.ts +5 -0
  53. package/dist/types/src/feature/matchers/toClickButton.d.ts +5 -0
  54. package/dist/types/src/feature/matchers/toClickLink.d.ts +5 -0
  55. package/dist/types/src/feature/matchers/toClickSelector.d.ts +5 -0
  56. package/dist/types/src/feature/matchers/toFill.d.ts +5 -0
  57. package/dist/types/src/feature/matchers/toHaveChecked.d.ts +5 -0
  58. package/dist/types/src/feature/matchers/toHaveLink.d.ts +5 -0
  59. package/dist/types/src/feature/matchers/toHavePath.d.ts +5 -0
  60. package/dist/types/src/feature/matchers/toHaveSelector.d.ts +5 -0
  61. package/dist/types/src/feature/matchers/toHaveUnchecked.d.ts +5 -0
  62. package/dist/types/src/feature/matchers/toHaveUrl.d.ts +5 -0
  63. package/dist/types/src/feature/matchers/toMatchTextContent.d.ts +5 -0
  64. package/dist/types/src/feature/matchers/toNotHaveSelector.d.ts +5 -0
  65. package/dist/types/src/feature/matchers/toNotMatchTextContent.d.ts +5 -0
  66. package/dist/types/src/feature/matchers/toUncheck.d.ts +5 -0
  67. package/dist/types/src/index.d.ts +45 -0
  68. package/dist/types/src/shared/sleep.d.ts +1 -0
  69. package/dist/types/src/unit/SpecRequest.d.ts +34 -0
  70. package/dist/types/src/unit/SpecSession.d.ts +29 -0
  71. package/dist/types/src/unit/createPsychicServer.d.ts +1 -0
  72. package/dist/types/src/unit/supersession.d.ts +6 -0
  73. package/package.json +47 -0
  74. package/src/feature/helpers/launchBrowser.ts +10 -0
  75. package/src/feature/helpers/launchPage.ts +7 -0
  76. package/src/feature/helpers/launchViteServer.ts +104 -0
  77. package/src/feature/helpers/providePuppeteerViteMatchers.ts +102 -0
  78. package/src/feature/helpers/visit.ts +11 -0
  79. package/src/feature/internal/evaluateWithRetryAndTimeout.ts +49 -0
  80. package/src/feature/internal/evaluationFailure.ts +6 -0
  81. package/src/feature/internal/evaluationSuccess.ts +6 -0
  82. package/src/feature/internal/getAllTextContentFromPage.ts +26 -0
  83. package/src/feature/internal/isPuppeteerPage.ts +3 -0
  84. package/src/feature/internal/matchFailure.ts +6 -0
  85. package/src/feature/internal/matchSuccess.ts +6 -0
  86. package/src/feature/internal/requirePuppeteerPage.ts +7 -0
  87. package/src/feature/matchers/toCheck.ts +34 -0
  88. package/src/feature/matchers/toClick.ts +30 -0
  89. package/src/feature/matchers/toClickButton.ts +30 -0
  90. package/src/feature/matchers/toClickLink.ts +30 -0
  91. package/src/feature/matchers/toClickSelector.ts +30 -0
  92. package/src/feature/matchers/toFill.ts +28 -0
  93. package/src/feature/matchers/toHaveChecked.ts +26 -0
  94. package/src/feature/matchers/toHaveLink.ts +30 -0
  95. package/src/feature/matchers/toHavePath.ts +23 -0
  96. package/src/feature/matchers/toHaveSelector.ts +21 -0
  97. package/src/feature/matchers/toHaveUnchecked.ts +26 -0
  98. package/src/feature/matchers/toHaveUrl.ts +21 -0
  99. package/src/feature/matchers/toMatchTextContent.ts +23 -0
  100. package/src/feature/matchers/toNotHaveSelector.ts +21 -0
  101. package/src/feature/matchers/toNotMatchTextContent.ts +26 -0
  102. package/src/feature/matchers/toUncheck.ts +35 -0
  103. package/src/index.ts +56 -0
  104. package/src/shared/sleep.ts +7 -0
  105. package/src/unit/SpecRequest.ts +160 -0
  106. package/src/unit/SpecSession.ts +103 -0
  107. package/src/unit/createPsychicServer.ts +8 -0
  108. package/src/unit/supersession.ts +100 -0
  109. package/tsconfig.json +7 -0
@@ -0,0 +1,14 @@
1
+ import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
2
+ import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
3
+ export default async function toNotHaveSelector(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} not to have selector: ${expectedSelector}`,
12
+ failureText: r => `Expected ${r} to have selector: ${expectedSelector}`,
13
+ });
14
+ }
@@ -0,0 +1,16 @@
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 toNotMatchTextContent(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} not to match text ${expected}`,
14
+ failureText: r => `Expected ${r} to match text ${expected}`,
15
+ });
16
+ }
@@ -0,0 +1,23 @@
1
+ import evaluateWithRetryAndTimeout from '../internal/evaluateWithRetryAndTimeout.js';
2
+ import evaluationFailure from '../internal/evaluationFailure.js';
3
+ import requirePuppeteerPage from '../internal/requirePuppeteerPage.js';
4
+ export default async function toUncheck(page, expectedText) {
5
+ return await evaluateWithRetryAndTimeout(page, async () => {
6
+ requirePuppeteerPage(page);
7
+ const checkbox = await page.$(`input[type="checkbox"][value="${expectedText}"]`);
8
+ if (!checkbox)
9
+ return evaluationFailure(`A checkbox was not found with "${expectedText}"`);
10
+ const isChecked = await page.evaluate(checkbox => checkbox.checked, checkbox);
11
+ if (!isChecked)
12
+ return evaluationFailure(`A checkbox was found with "${expectedText}", but it is already unchecked`);
13
+ await checkbox.click();
14
+ const isCheckedNow = await page.evaluate(checkbox => checkbox.checked, checkbox);
15
+ return {
16
+ pass: !isCheckedNow,
17
+ actual: expectedText,
18
+ };
19
+ }, {
20
+ successText: r => `Expected page to have uncheckable checkbox with text: "${expectedText}"`,
21
+ failureText: r => `Expected page not to have uncheckable checkbox with text: "${expectedText}"`,
22
+ });
23
+ }
@@ -0,0 +1,12 @@
1
+ // unit spec helpers
2
+ export { default as specRequest } from './unit/SpecRequest.js';
3
+ export { default as createPsychicServer } from './unit/createPsychicServer.js';
4
+ export { SpecRequest } from './unit/SpecRequest.js';
5
+ export { SpecSession } from './unit/SpecSession.js';
6
+ // feature spec helpers
7
+ export { default as providePuppeteerViteMatchers } from './feature/helpers/providePuppeteerViteMatchers.js';
8
+ export { default as launchBrowser } from './feature/helpers/launchBrowser.js';
9
+ export { default as launchPage } from './feature/helpers/launchPage.js';
10
+ export { default as launchViteServer, stopViteServer } from './feature/helpers/launchViteServer.js';
11
+ export { default as visit } from './feature/helpers/visit.js';
12
+ export default {};
@@ -0,0 +1,7 @@
1
+ export default async function sleep(ms) {
2
+ return await new Promise(accept => {
3
+ setTimeout(() => {
4
+ accept(undefined);
5
+ }, ms);
6
+ });
7
+ }
@@ -0,0 +1,89 @@
1
+ import supertest from 'supertest';
2
+ import { createPsychicServer } from '../index.js';
3
+ import supersession from './supersession.js';
4
+ import { SpecSession } from './SpecSession.js';
5
+ export class SpecRequest {
6
+ PsychicServer;
7
+ server;
8
+ async get(uri, expectedStatus, opts = {}) {
9
+ return await this.makeRequest('get', uri, expectedStatus, opts);
10
+ }
11
+ async post(uri, expectedStatus, opts = {}) {
12
+ return await this.makeRequest('post', uri, expectedStatus, opts);
13
+ }
14
+ async put(uri, expectedStatus, opts = {}) {
15
+ return await this.makeRequest('put', uri, expectedStatus, opts);
16
+ }
17
+ async patch(uri, expectedStatus, opts = {}) {
18
+ return await this.makeRequest('patch', uri, expectedStatus, opts);
19
+ }
20
+ async delete(uri, expectedStatus, opts = {}) {
21
+ return await this.makeRequest('delete', uri, expectedStatus, opts);
22
+ }
23
+ async init(PsychicServer) {
24
+ this.PsychicServer = PsychicServer;
25
+ this.server ||= await createPsychicServer(PsychicServer);
26
+ }
27
+ async session(uri, credentials, expectedStatus, opts = {}) {
28
+ return await new Promise((accept, reject) => {
29
+ createPsychicServer(this.PsychicServer)
30
+ .then(server => {
31
+ const session = supersession(server);
32
+ session[(opts.httpMethod || 'post')](uri)
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
34
+ .send(credentials)
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
36
+ .expect(expectedStatus)
37
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
38
+ .query(opts.query || {})
39
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
40
+ .set(opts.headers || {})
41
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
42
+ .end((err) => {
43
+ if (err)
44
+ return reject(err);
45
+ return accept(new SpecSession(session));
46
+ });
47
+ })
48
+ .catch(err => {
49
+ throw err;
50
+ });
51
+ });
52
+ }
53
+ async makeRequest(method, uri, expectedStatus, opts = {}) {
54
+ // TODO: find out why this is necessary. Currently, without initializing the server
55
+ // at the beginning of the specs, supertest is unable to use our server to handle requests.
56
+ // it gives the appearance of being an issue with a runaway promise (i.e. missing await)
57
+ // but I can't find it anywhere, so I am putting this init method in as a temporary fix.
58
+ if (!this.server)
59
+ throw new Error(`
60
+ ERROR:
61
+ When making use of the send spec helper, you must first call "await specRequest.init(PsychicServer)"
62
+ from a beforEach hook at the root of your specs.
63
+ `);
64
+ if (expectedStatus === 500) {
65
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = '1';
66
+ }
67
+ const req = supertest.agent(this.server.expressApp);
68
+ let request = req[method](uri);
69
+ if (opts.headers)
70
+ request = request.set(opts.headers);
71
+ if (opts.query)
72
+ request = request.query(opts.query);
73
+ if (method !== 'get')
74
+ request = request.send(opts.data);
75
+ try {
76
+ const res = await request.expect(expectedStatus);
77
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = undefined;
78
+ return res;
79
+ }
80
+ catch (err) {
81
+ // without manually console logging, you get no stack trace here
82
+ console.error(err);
83
+ console.trace();
84
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = undefined;
85
+ throw err;
86
+ }
87
+ }
88
+ }
89
+ export default new SpecRequest();
@@ -0,0 +1,48 @@
1
+ // like SpecRequest, but meant to be bound to an instance
2
+ // of supersession, enabling chained requests to collect cookies
3
+ export class SpecSession {
4
+ _session;
5
+ constructor(_session) {
6
+ this._session = _session;
7
+ }
8
+ async get(uri, expectedStatus, opts = {}) {
9
+ return await this.makeRequest('get', uri, expectedStatus, opts);
10
+ }
11
+ async post(uri, expectedStatus, opts = {}) {
12
+ return await this.makeRequest('post', uri, expectedStatus, opts);
13
+ }
14
+ async put(uri, expectedStatus, opts = {}) {
15
+ return await this.makeRequest('put', uri, expectedStatus, opts);
16
+ }
17
+ async patch(uri, expectedStatus, opts = {}) {
18
+ return await this.makeRequest('patch', uri, expectedStatus, opts);
19
+ }
20
+ async delete(uri, expectedStatus, opts = {}) {
21
+ return await this.makeRequest('delete', uri, expectedStatus, opts);
22
+ }
23
+ async makeRequest(method, uri, expectedStatus, opts = {}) {
24
+ if (expectedStatus === 500) {
25
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = '1';
26
+ }
27
+ const req = this._session;
28
+ let request = req[method](uri);
29
+ if (opts.headers)
30
+ request = request.set(opts.headers);
31
+ if (opts.query)
32
+ request = request.query(opts.query);
33
+ if (method !== 'get')
34
+ request = request.send(opts.data);
35
+ try {
36
+ const res = await request.expect(expectedStatus);
37
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = undefined;
38
+ return res;
39
+ }
40
+ catch (err) {
41
+ // without manually console logging, you get no stack trace here
42
+ console.error(err);
43
+ console.trace();
44
+ process.env.PSYCHIC_EXPECTING_INTERNAL_SERVER_ERROR = undefined;
45
+ throw err;
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,8 @@
1
+ const _server = undefined;
2
+ export default async function createPsychicServer(PsychicServer) {
3
+ if (_server)
4
+ return _server;
5
+ const server = new PsychicServer();
6
+ await server.boot();
7
+ return server;
8
+ }
@@ -0,0 +1,72 @@
1
+ import { CookieAccessInfo as CookieAccess } from 'cookiejar';
2
+ import http from 'http';
3
+ import request from 'supertest';
4
+ import URL from 'url';
5
+ class Supersession {
6
+ options;
7
+ app;
8
+ agent;
9
+ url;
10
+ cookieAccess;
11
+ constructor(server, options = {}) {
12
+ this.options = options;
13
+ if (!server.expressApp) {
14
+ throw new Error('Supersession requires an `app`');
15
+ }
16
+ this.agent = request.agent(server.expressApp, options);
17
+ const app = http.createServer(server.expressApp);
18
+ const url = request.Test.prototype.serverAddress(app, '/');
19
+ this.app = app;
20
+ this.url = URL.parse(url);
21
+ this.reset();
22
+ // typescript is telling me I don't need to worry about options.helpers,
23
+ // but leaving this commented out in case we need to revisit
24
+ // if (this.options.helpers instanceof Object) {
25
+ // assign(this, this.options.helpers)
26
+ // }
27
+ }
28
+ get cookies() {
29
+ return this.agent.jar.getCookies(this.cookieAccess);
30
+ }
31
+ reset() {
32
+ // Unset supertest-session options before forwarding options to superagent.
33
+ var agentOptions = {
34
+ ...this.options,
35
+ before: undefined,
36
+ cookieAccess: undefined,
37
+ destroy: undefined,
38
+ helpers: undefined,
39
+ };
40
+ this.agent = request.agent(this.app, agentOptions);
41
+ const domain = this.url.hostname;
42
+ const path = this.url.path;
43
+ const secure = 'https:' == this.url.protocol;
44
+ const script = false;
45
+ this.cookieAccess = CookieAccess(domain, path, secure, script);
46
+ }
47
+ destroy() {
48
+ if (this.options.destroy)
49
+ this.options.destroy.call(this);
50
+ this.reset();
51
+ }
52
+ request(method, route) {
53
+ var test = this.agent[method](route);
54
+ // typescript is telling me I don't need to worry about options.before,
55
+ // but leaving this commented out in case we need to revisit
56
+ // if (this.options.before) {
57
+ // this.options.before.call(this, test)
58
+ // }
59
+ return test;
60
+ }
61
+ }
62
+ export const HttpMethods = ['get', 'post', 'put', 'patch', 'delete', 'options'];
63
+ HttpMethods.forEach(function (m) {
64
+ ;
65
+ Supersession.prototype[m] = function () {
66
+ var args = [].slice.call(arguments);
67
+ return this.request.apply(this, [m].concat(args));
68
+ };
69
+ });
70
+ export default function supersession(server, config = {}) {
71
+ return new Supersession(server, config);
72
+ }
@@ -0,0 +1,2 @@
1
+ import puppeteer, { LaunchOptions } from 'puppeteer';
2
+ export default function launchBrowser(opts?: LaunchOptions): Promise<puppeteer.Browser>;
@@ -0,0 +1,2 @@
1
+ import { LaunchOptions } from 'puppeteer';
2
+ export default function launchPage(opts?: LaunchOptions): Promise<import("puppeteer").Page>;
@@ -0,0 +1,6 @@
1
+ export default function launchViteServer({ port, cmd, timeout, }?: {
2
+ port?: number;
3
+ cmd?: string;
4
+ timeout?: number;
5
+ }): Promise<void>;
6
+ export declare function stopViteServer(): void;
@@ -0,0 +1,5 @@
1
+ export default function providePuppeteerViteMatchers(): void;
2
+ export interface CustomMatcherResult {
3
+ pass: boolean;
4
+ message: (actual?: unknown) => string;
5
+ }
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function visit(path: string, { page, baseUrl }?: {
3
+ page?: Page;
4
+ baseUrl?: string;
5
+ }): Promise<Page>;
@@ -0,0 +1,14 @@
1
+ export default function evaluateWithRetryAndTimeout(argumentPassedToExpect: any, evaluationFn: (a: any) => ExpectToEvaluateReturnType | Promise<ExpectToEvaluateReturnType>, opts: ExpectToEvaluateOpts): Promise<{
2
+ message: () => string;
3
+ pass: boolean;
4
+ }>;
5
+ export type ExpectToEvaluateReturnType = {
6
+ pass: boolean;
7
+ actual: any;
8
+ };
9
+ export interface ExpectToEvaluateOpts {
10
+ timeout?: number;
11
+ interval?: number;
12
+ successText?: (received: any) => string;
13
+ failureText: (received: any) => string;
14
+ }
@@ -0,0 +1,4 @@
1
+ export default function evaluationFailure(actual: any): {
2
+ pass: boolean;
3
+ actual: any;
4
+ };
@@ -0,0 +1,4 @@
1
+ export default function evaluationSuccess(actual: any): {
2
+ pass: boolean;
3
+ actual: any;
4
+ };
@@ -0,0 +1,2 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function getAllTextContentFromPage(page: Page): Promise<string>;
@@ -0,0 +1 @@
1
+ export default function isPuppeteerPage(page: any): boolean;
@@ -0,0 +1,4 @@
1
+ export default function matchFailure(message: string | ((expected: any) => string)): {
2
+ pass: boolean;
3
+ message: (expected: any) => string;
4
+ };
@@ -0,0 +1,4 @@
1
+ export default function matchSuccess(message: string | ((expected: any) => string)): {
2
+ pass: boolean;
3
+ message: (expected: any) => string;
4
+ };
@@ -0,0 +1 @@
1
+ export default function requirePuppeteerPage(argumentPassedToExpect: any): void;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toCheck(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toClick(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toClickButton(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toClickLink(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toClickSelector(page: Page, cssSelector: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toFill(page: Page, cssSelector: string, text: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHaveChecked(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHaveLink(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHavePath(page: Page, expectedPath: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHaveSelector(page: Page, expectedSelector: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHaveUnchecked(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toHaveUrl(page: Page, expectedUrl: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toMatchTextContent(argumentPassedToExpect: Page, expected: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toNotHaveSelector(page: Page, expectedSelector: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toNotMatchTextContent(argumentPassedToExpect: Page, expected: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,5 @@
1
+ import { Page } from 'puppeteer';
2
+ export default function toUncheck(page: Page, expectedText: string): Promise<{
3
+ message: () => string;
4
+ pass: boolean;
5
+ }>;
@@ -0,0 +1,45 @@
1
+ import { ExpectToEvaluateOpts } from './feature/internal/evaluateWithRetryAndTimeout.js';
2
+ import { CustomMatcherResult } from './feature/helpers/providePuppeteerViteMatchers.js';
3
+ export { default as specRequest } from './unit/SpecRequest.js';
4
+ export { default as createPsychicServer } from './unit/createPsychicServer.js';
5
+ export { SpecRequest } from './unit/SpecRequest.js';
6
+ export { SpecSession } from './unit/SpecSession.js';
7
+ export { default as providePuppeteerViteMatchers } from './feature/helpers/providePuppeteerViteMatchers.js';
8
+ export { default as launchBrowser } from './feature/helpers/launchBrowser.js';
9
+ export { default as launchPage } from './feature/helpers/launchPage.js';
10
+ export { default as launchViteServer, stopViteServer } from './feature/helpers/launchViteServer.js';
11
+ export { default as visit } from './feature/helpers/visit.js';
12
+ declare global {
13
+ function context(description: string, callback: () => void): void;
14
+ }
15
+ declare module 'vitest' {
16
+ interface ExpectStatic extends PuppeteerAssertions {
17
+ }
18
+ interface Assertion extends PuppeteerAssertions {
19
+ }
20
+ }
21
+ interface PuppeteerAssertions {
22
+ toMatchDreamModel(expected: any): CustomMatcherResult;
23
+ toMatchDreamModels(expected: any): CustomMatcherResult;
24
+ toBeWithin(precision: number, expected: number): CustomMatcherResult;
25
+ toEqualCalendarDate(expected: any): CustomMatcherResult;
26
+ toMatchTextContent(expected: any): Promise<CustomMatcherResult>;
27
+ toNotMatchTextContent(expected: any): Promise<CustomMatcherResult>;
28
+ toHaveSelector(expected: any): Promise<CustomMatcherResult>;
29
+ toNotHaveSelector(expected: any): Promise<CustomMatcherResult>;
30
+ toCheck(expected: any): Promise<CustomMatcherResult>;
31
+ toClick(expected: any): Promise<CustomMatcherResult>;
32
+ toClickLink(expected: any): Promise<CustomMatcherResult>;
33
+ toClickLink(expected: any): Promise<CustomMatcherResult>;
34
+ toClickSelector(expected: any): Promise<CustomMatcherResult>;
35
+ toHavePath(expected: any): Promise<CustomMatcherResult>;
36
+ toHaveUrl(expected: any): Promise<CustomMatcherResult>;
37
+ toHaveChecked(expected: any): Promise<CustomMatcherResult>;
38
+ toHaveUnchecked(expected: any): Promise<CustomMatcherResult>;
39
+ toHaveLink(expected: any): Promise<CustomMatcherResult>;
40
+ toFill(cssSelector: string, text: string): Promise<CustomMatcherResult>;
41
+ toUncheck(expected: any): Promise<CustomMatcherResult>;
42
+ toEvaluate(expected: (a: any) => boolean | Promise<boolean>, opts: ExpectToEvaluateOpts): Promise<CustomMatcherResult>;
43
+ }
44
+ declare const _default: {};
45
+ export default _default;
@@ -0,0 +1 @@
1
+ export default function sleep(ms: number): Promise<unknown>;
@@ -0,0 +1,34 @@
1
+ import { Response } from 'supertest';
2
+ import { HttpMethod } from './supersession.js';
3
+ import { SpecSession } from './SpecSession.js';
4
+ export declare class SpecRequest {
5
+ private PsychicServer;
6
+ private server;
7
+ get(uri: string, expectedStatus: number, opts?: SpecRequestOptsGet): Promise<Response>;
8
+ post(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
9
+ put(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
10
+ patch(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
11
+ delete(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
12
+ init(PsychicServer: any): Promise<void>;
13
+ session(uri: string, credentials: object, expectedStatus: number, opts?: SpecRequestSessionOpts): Promise<SpecSession>;
14
+ private makeRequest;
15
+ }
16
+ export interface SpecRequestOptsAll extends SpecRequestOpts {
17
+ query?: Record<string, unknown>;
18
+ data?: Record<string, unknown>;
19
+ }
20
+ export interface SpecRequestOptsGet extends SpecRequestOpts {
21
+ query?: any;
22
+ }
23
+ export interface SpecRequestOptsPost extends SpecRequestOpts {
24
+ data?: any;
25
+ }
26
+ export interface SpecRequestOpts {
27
+ headers?: Record<string, string>;
28
+ allowMocks?: boolean;
29
+ }
30
+ export interface SpecRequestSessionOpts extends SpecRequestOptsAll {
31
+ httpMethod?: HttpMethod;
32
+ }
33
+ declare const _default: SpecRequest;
34
+ export default _default;
@@ -0,0 +1,29 @@
1
+ import { Response } from 'supertest';
2
+ import supersession, { HttpMethod } from './supersession.js';
3
+ export declare class SpecSession {
4
+ private _session;
5
+ constructor(_session: ReturnType<typeof supersession>);
6
+ get(uri: string, expectedStatus: number, opts?: SpecRequestOptsGet): Promise<Response>;
7
+ post(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
8
+ put(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
9
+ patch(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
10
+ delete(uri: string, expectedStatus: number, opts?: SpecRequestOptsPost): Promise<Response>;
11
+ private makeRequest;
12
+ }
13
+ export interface SpecRequestOptsAll extends SpecRequestOpts {
14
+ query?: Record<string, unknown>;
15
+ data?: Record<string, unknown>;
16
+ }
17
+ export interface SpecRequestOptsGet extends SpecRequestOpts {
18
+ query?: any;
19
+ }
20
+ export interface SpecRequestOptsPost extends SpecRequestOpts {
21
+ data?: any;
22
+ }
23
+ export interface SpecRequestOpts {
24
+ headers?: Record<string, string>;
25
+ allowMocks?: boolean;
26
+ }
27
+ export interface SpecRequestSessionOpts extends SpecRequestOptsAll {
28
+ httpMethod?: HttpMethod;
29
+ }
@@ -0,0 +1 @@
1
+ export default function createPsychicServer(PsychicServer: any): Promise<any>;
@@ -0,0 +1,6 @@
1
+ import request from 'supertest';
2
+ type AgentOptions = Parameters<typeof request.agent>[1];
3
+ export declare const HttpMethods: readonly ["get", "post", "put", "patch", "delete", "options"];
4
+ export type HttpMethod = (typeof HttpMethods)[number];
5
+ export default function supersession(server: any, config?: AgentOptions): ReturnType<typeof request>;
6
+ export {};