quickpickle 1.8.0 → 1.10.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.
package/dist/world.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { TestContext } from 'vitest';
2
2
  import type { QuickPickleConfig } from '.';
3
3
  import sanitize from './shims/path-sanitizer';
4
+ import { type PixelmatchOptions } from 'pixelmatch';
5
+ import type { AriaRole } from '@a11y-tools/aria-roles';
6
+ export type AriaRoleExtended = AriaRole | 'element' | 'input';
7
+ import { Buffer } from 'buffer';
4
8
  interface Common {
5
9
  info: {
6
10
  feature: string;
@@ -34,6 +38,7 @@ export interface QuickPickleWorldInterface {
34
38
  tagsMatch(tags: string[]): string[] | null;
35
39
  sanitizePath: typeof sanitize;
36
40
  fullPath(path: string): string;
41
+ wait(ms: number): Promise<void>;
37
42
  }
38
43
  export type InfoConstructor = Omit<QuickPickleWorldInterface['info'], 'errors'> & {
39
44
  common: Common;
@@ -52,6 +57,7 @@ export declare class QuickPickleWorld implements QuickPickleWorldInterface {
52
57
  [key: string]: any;
53
58
  }>;
54
59
  get isComplete(): boolean;
60
+ get projectRoot(): string;
55
61
  /**
56
62
  * Checks the tags of the Scenario against a provided list of tags,
57
63
  * and returns the shared tags, with the "@" prefix character.
@@ -73,9 +79,178 @@ export declare class QuickPickleWorld implements QuickPickleWorldInterface {
73
79
  * @return string the sanitized path, including the project root
74
80
  */
75
81
  fullPath(path: string): string;
82
+ /**
83
+ * A helper function for when you really just need to wait.
84
+ *
85
+ * @deprecated Waiting for arbitrary amounts of time makes your tests flaky! There are
86
+ * usually better ways to wait for something to happen, and this functionality will be
87
+ * removed from the API as soon we're sure nobody will **EVER** want to use it again.
88
+ * (That may be a long time.)
89
+ *
90
+ * @param ms milliseconds to wait
91
+ */
92
+ wait(ms: number): Promise<void>;
76
93
  toString(): string;
77
94
  }
78
95
  export type WorldConstructor = new (context: TestContext, info: InfoConstructor) => QuickPickleWorldInterface;
79
96
  export declare function getWorldConstructor(): WorldConstructor;
80
97
  export declare function setWorldConstructor(constructor: WorldConstructor): void;
98
+ export type VisualDiffResult = {
99
+ diff: Buffer;
100
+ pixels: number;
101
+ pct: number;
102
+ };
103
+ export type ScreenshotComparisonOptions = any & Partial<PixelmatchOptions> & {
104
+ maxDiffPercentage?: number;
105
+ maxDiffPixels?: number;
106
+ };
107
+ export declare const defaultScreenshotComparisonOptions: ScreenshotComparisonOptions;
108
+ export interface VisualConfigSetting {
109
+ screenshotDir?: string;
110
+ screenshotOpts?: Partial<ScreenshotComparisonOptions>;
111
+ }
112
+ interface StubVisualWorldInterface extends QuickPickleWorldInterface {
113
+ /**
114
+ * The directory where screenshots are saved, relative to the project root.
115
+ */
116
+ screenshotDir: string;
117
+ /**
118
+ * The filename for a screenshot based on the current Scenario.
119
+ */
120
+ screenshotFilename: string;
121
+ /**
122
+ * The full path to a screenshot file, from the root of the file system,
123
+ * based on the current Scenario.
124
+ */
125
+ screenshotPath: string;
126
+ /**
127
+ * The options for the default screenshot comparisons.
128
+ */
129
+ screenshotOptions: Partial<ScreenshotComparisonOptions>;
130
+ /**
131
+ * The full path to a screenshot file, from the root of the file system,
132
+ * based on the custom name provided, and including information on any
133
+ * exploded tags as necessary.
134
+ *
135
+ * @param name
136
+ */
137
+ getScreenshotPath(name?: string): string;
138
+ /**
139
+ * A helper function to compare two screenshots, for visual regression testing.
140
+ * If the screenshots do not match, the difference should be returned as a Buffer.
141
+ */
142
+ screenshotDiff(actual: Buffer, expected: Buffer, options?: any): Promise<VisualDiffResult>;
143
+ }
144
+ export interface VisualWorldInterface extends StubVisualWorldInterface {
145
+ /**
146
+ * A helper method for getting an element, which should work across different testing libraries.
147
+ * The "Locator" interface used should be whatever is compatible with the testing library
148
+ * being integrated by your World Constructor. This is intended as an 80% solution for
149
+ * behavioral tests, so that a single step definition can get an element based on a variety
150
+ * of factors, e.g. (in Playwright syntax):
151
+ *
152
+ * @example getLocator(page, 'Cancel', 'button') => page.getByRole('button', { name: 'Cancel' })
153
+ * @example getLocator(page, 'Search', 'input') => page.getByLabel('Search').or(page.getByPlaceholder('Search'))
154
+ * @example getLocator(page, 'ul.fourteen-points li', 'element', 'Open covenants of peace') => page.locator('ul.fourteen-points li').filter({ hasText: 'Open covenants of peace' })
155
+ *
156
+ * @param locator Locator
157
+ * The container inside which to search for the required element.
158
+ * @param identifier string
159
+ * A string that identifies the element to be found. For ARIA roles this is the "name" attribute,
160
+ * for role="input" it is the label or placeholder, and for role="element" it is the CSS selector.
161
+ * @param role string
162
+ * An ARIA role, or "input" to get an input by label or placeholder, or "element" to get an element by css selector.
163
+ * @param text string
164
+ * A string that the element must contain.
165
+ */
166
+ getLocator(locator: any, identifier: string, role: AriaRoleExtended, text?: string | null): any;
167
+ /**
168
+ * Sets a value on a form element based on its type (select, checkbox/radio, or other input).
169
+ * The "Locator" interface used should be whatever is compatible with the testing library
170
+ * being integrated by your World Constructor. This is intended as an 80% solution for
171
+ * behavioral tests, so that a single step definition can get an element based on a variety
172
+ * of factors, e.g.:
173
+ *
174
+ * @example setValue(<SelectInput>, "Option 1, Option 2") => Selects multiple options in a select element
175
+ * @example setValue(<RadioInput>, "true") => Checks a checkbox/radio item
176
+ * @example setValue(<CheckboxInput>, "false") => Unchecks a checkbox item
177
+ * @example setValue(<TextInput>, "Some text") => Fills a text input with "Some text"
178
+ * @example setValue(<NumberInput>, 5) => Sets a number input to the number 5
179
+ *
180
+ * @param locator Locator
181
+ * The Locator for the form element
182
+ * @param value string|any
183
+ * The value to set can be string or other value type
184
+ */
185
+ setValue(locator: any, value: string | any): Promise<void>;
186
+ /**
187
+ * Scrolls an element by a number of pixels in a given direction.
188
+ *
189
+ * @param locator Locator
190
+ * The locator that should be scrolled
191
+ * @param direction "up"|"down"|"left"|"right"
192
+ * The direction to scroll, i.e. "up", "down", "left", "right"
193
+ * @param px
194
+ * A number of pixels to scroll
195
+ */
196
+ scroll(locator: any, direction: string, px: number): Promise<void>;
197
+ /**
198
+ * A helper method for parsing text on a page or in an element.
199
+ * Can be used to check for the presence OR absence of visible OR hidden text.
200
+ *
201
+ * Examples:
202
+ * @example expectText(locator, 'text', true, true) // expect that a locator with the text is visible (and there may be hidden ones)
203
+ * @example expectText(locator, 'text', false, true) // expect that NO locator with the text is visible (but there may be hidden ones)
204
+ * @example expectText(locator, 'text', true, false) // expect that a HIDDEN locator with the text IS FOUND on the page (but there may be visible ones)
205
+ * @example expectText(locator, 'text', false, false) // expect that NO hidden locator with the text is found on the page (but there may be visible ones)
206
+ *
207
+ * @param locator the locator to check
208
+ * @param text the text to be found
209
+ * @param toBePresent whether a locator with the text should be present
210
+ * @param toBeVisible whether the locator with the text should be visible
211
+ * @returns void
212
+ */
213
+ expectText(locator: any, text: string, toBePresent: boolean, toBeVisible: boolean): Promise<void>;
214
+ /**
215
+ * A helper function for parsing elements on a page or in an element.
216
+ * Can be used to check for the presence OR absence of visible OR hidden elements.
217
+ * Examples:
218
+ * @example expectElement(locator, true) // expect that an element is visible (and there may be hidden ones)
219
+ * @example expectElement(locator, false) // expect that NO element is visible (but there may be hidden ones)
220
+ * @example expectElement(locator, true, false) // expect that a HIDDEN element IS FOUND on the page (but there may be visible ones)
221
+ * @example expectElement(locator, false, false) // expect that NO hidden element is found on the page (but there may be visible ones)
222
+ *
223
+ * @param locator the locator to check
224
+ * @param toBePresent whether an element should be present
225
+ * @param toBeVisible whether the element should be visible
226
+ */
227
+ expectElement(locator: any, toBePresent: boolean, toBeVisible: boolean): Promise<void>;
228
+ /**
229
+ * A helper function to get a screenshot of the current page or an element.
230
+ * Depending on the implementation, it may also save a screenshot to disk.
231
+ */
232
+ screenshot(opts?: {
233
+ name?: string;
234
+ locator?: any;
235
+ }): Promise<Buffer>;
236
+ /**
237
+ * A helper function to test whether two screenshots match. The "Locator" interface used
238
+ * should be whatever is compatible with the testing library being integrated by your World Constructor.
239
+ *
240
+ * @param locator the locator to check
241
+ * @param screenshotName the name of the screenshot to compare against
242
+ */
243
+ expectScreenshotMatch(locator: any, screenshotName: string, options?: any): Promise<void>;
244
+ screenshotOptions: Partial<ScreenshotComparisonOptions>;
245
+ }
246
+ export declare class VisualWorld extends QuickPickleWorld implements StubVisualWorldInterface {
247
+ constructor(context: TestContext, info: InfoConstructor);
248
+ init(): Promise<void>;
249
+ get screenshotDir(): string;
250
+ get screenshotFilename(): string;
251
+ get screenshotPath(): string;
252
+ get screenshotOptions(): any;
253
+ getScreenshotPath(name?: string): string;
254
+ screenshotDiff(actual: Buffer, expected: Buffer, opts: any): Promise<VisualDiffResult>;
255
+ }
81
256
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickpickle",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Plugin for Vitest to run tests written in Gherkin Syntax.",
5
5
  "keywords": [
6
6
  "BDD",
@@ -35,12 +35,15 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
+ "@a11y-tools/aria-roles": "^1.0.0",
38
39
  "@cucumber/cucumber-expressions": "^18.0.1",
39
40
  "@cucumber/gherkin": "^32.1.0",
40
41
  "@cucumber/messages": "^27.2.0",
41
42
  "@cucumber/tag-expressions": "^6.1.2",
43
+ "buffer": "^6.0.3",
42
44
  "lodash": "^4.17.21",
43
- "lodash-es": "^4.17.21"
45
+ "lodash-es": "^4.17.21",
46
+ "pngjs": "^7.0.0"
44
47
  },
45
48
  "devDependencies": {
46
49
  "@optimize-lodash/esbuild-plugin": "^3.2.0",
@@ -51,12 +54,11 @@
51
54
  "@types/lodash": "^4.17.16",
52
55
  "@types/lodash-es": "^4.17.12",
53
56
  "@types/node": "^22.15.17",
54
- "@vitest/browser": "^3.1.3",
55
57
  "playwright": "^1.52.0",
56
58
  "rollup": "^4.40.2",
57
59
  "typescript": "^5.8.3",
58
60
  "vite": "^6.3.5",
59
- "vitest": "^3.1.3"
61
+ "vitest": "^3.1.4"
60
62
  },
61
63
  "peerDependencies": {
62
64
  "vitest": "^1.0.0 || >=2.0.0"