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