1 | //
|
2 | // Cypress NPM api type declarations
|
3 | // https://on.cypress.io/module-api
|
4 | // https://github.com/cypress-io/cypress/issues/2141
|
5 | //
|
6 | // in the future the NPM module itself will be in TypeScript
|
7 | // but for now describe it as an ambient module
|
8 |
|
9 | declare namespace CypressCommandLine {
|
10 | /**
|
11 | * All options that one can pass to "cypress.run"
|
12 | * @see https://on.cypress.io/module-api#cypress-run
|
13 | * @example
|
14 | ```
|
15 | const cypress = require('cypress')
|
16 | cypress.run({
|
17 | reporter: 'junit',
|
18 | browser: 'chrome',
|
19 | config: {
|
20 | baseUrl: 'http://localhost:8080',
|
21 | chromeWebSecurity: false,
|
22 | },
|
23 | env: {
|
24 | foo: 'bar',
|
25 | baz: 'quux',
|
26 | }
|
27 | })
|
28 | ```
|
29 | */
|
30 | interface CypressRunOptions extends CypressCommonOptions {
|
31 | /**
|
32 | * Specify browser to run tests in, either by name or by filesystem path
|
33 | */
|
34 | browser: string
|
35 | /**
|
36 | * Specify a unique identifier for a run to enable grouping or parallelization
|
37 | */
|
38 | ciBuildId: string
|
39 | /**
|
40 | * Group recorded tests together under a single run name
|
41 | */
|
42 | group: string
|
43 | /**
|
44 | * Tag string for the recorded run, like "production,nightly"
|
45 | */
|
46 | tag: string
|
47 | /**
|
48 | * Display the browser instead of running headlessly
|
49 | */
|
50 | headed: boolean
|
51 | /**
|
52 | * Hide the browser instead of running headed
|
53 | */
|
54 | headless: boolean
|
55 | /**
|
56 | * Specify your secret Record Key
|
57 | */
|
58 | key: string
|
59 | /**
|
60 | * Keep Cypress open after all tests run
|
61 | */
|
62 | noExit: boolean
|
63 | /**
|
64 | * Run recorded specs in parallel across multiple machines
|
65 | */
|
66 | parallel: boolean
|
67 | /**
|
68 | * Override default port
|
69 | */
|
70 | port: number
|
71 | /**
|
72 | * Run quietly, using only the configured reporter
|
73 | */
|
74 | quiet: boolean
|
75 | /**
|
76 | * Whether to record the test run
|
77 | */
|
78 | record: boolean
|
79 | /**
|
80 | * Specify a mocha reporter
|
81 | */
|
82 | reporter: string
|
83 | /**
|
84 | * Specify mocha reporter options
|
85 | */
|
86 | reporterOptions: any
|
87 | /**
|
88 | * Specify the specs to run
|
89 | */
|
90 | spec: string
|
91 | /**
|
92 | * Specify the number of failures to cancel a run being recorded to the Cloud or false to disable auto-cancellation.
|
93 | */
|
94 | autoCancelAfterFailures: number | false
|
95 | /**
|
96 | * Whether to display the Cypress Runner UI
|
97 | */
|
98 | runnerUi: boolean
|
99 | }
|
100 |
|
101 | /**
|
102 | * All options that one can pass to "cypress.open"
|
103 | * @see https://on.cypress.io/module-api#cypress-open
|
104 | * @example
|
105 | ```
|
106 | const cypress = require('cypress')
|
107 | cypress.open({
|
108 | env: {
|
109 | username: 'Joe Doe',
|
110 | email: 'joe@acme.co'
|
111 | },
|
112 | project: '~/demos/my-project'
|
113 | })
|
114 | ```
|
115 | */
|
116 | interface CypressOpenOptions extends CypressCommonOptions {
|
117 | /**
|
118 | * Specify browser to run tests in, either by name or by filesystem path
|
119 | */
|
120 | browser: string
|
121 | /**
|
122 | * Open Cypress in detached mode
|
123 | */
|
124 | detached: boolean
|
125 | /**
|
126 | * Run in global mode
|
127 | */
|
128 | global: boolean
|
129 | /**
|
130 | * Override default port
|
131 | */
|
132 | port: number
|
133 | }
|
134 |
|
135 | /**
|
136 | * Options available for `cypress.open` and `cypress.run`
|
137 | */
|
138 | interface CypressCommonOptions {
|
139 | /**
|
140 | * Specify configuration
|
141 | */
|
142 | config: Cypress.ConfigOptions
|
143 | /**
|
144 | * Path to the config file to be used.
|
145 | *
|
146 | * @default "cypress.config.{js,ts,mjs,cjs}"
|
147 | */
|
148 | configFile: string
|
149 | /**
|
150 | * Specify environment variables.
|
151 | * TODO: isn't this duplicate of config.env?!
|
152 | */
|
153 | env: object
|
154 | /**
|
155 | * Path to a specific project
|
156 | */
|
157 | project: string
|
158 | /**
|
159 | * Specify the type of tests to execute.
|
160 | * @default "e2e"
|
161 | */
|
162 | testingType: Cypress.TestingType
|
163 | }
|
164 |
|
165 | // small utility types to better express meaning of other types
|
166 | type dateTimeISO = string
|
167 | type ms = number
|
168 | type pixels = number
|
169 |
|
170 | /**
|
171 | * Cypress single test result
|
172 | */
|
173 | interface TestResult {
|
174 | duration: number
|
175 | title: string[]
|
176 | state: string
|
177 | /**
|
178 | * Error string as it's presented in console if the test fails
|
179 | */
|
180 | displayError: string | null
|
181 | attempts: AttemptResult[]
|
182 | }
|
183 |
|
184 | interface AttemptResult {
|
185 | state: string
|
186 | }
|
187 |
|
188 | /**
|
189 | * Information about a single screenshot.
|
190 | */
|
191 | interface ScreenshotInformation {
|
192 | name: string
|
193 | takenAt: dateTimeISO
|
194 | /**
|
195 | * Absolute path to the saved image
|
196 | */
|
197 | path: string
|
198 | height: pixels
|
199 | width: pixels
|
200 | }
|
201 |
|
202 | interface SpecResult {
|
203 | /**
|
204 | * resolved filename of the spec
|
205 | */
|
206 | absolute: string
|
207 | /**
|
208 | * file extension like ".js"
|
209 | */
|
210 | fileExtension: string
|
211 | /**
|
212 | * file name without extension like "spec"
|
213 | */
|
214 | fileName: string
|
215 | /**
|
216 | * filename like "spec.js"
|
217 | */
|
218 | name: string
|
219 | /**
|
220 | * name relative to the project root, like "cypress/integration/spec.js"
|
221 | */
|
222 | relative: string
|
223 | }
|
224 |
|
225 | /**
|
226 | * Cypress test run result for a single spec.
|
227 | */
|
228 | interface RunResult {
|
229 | error: string | null
|
230 | /**
|
231 | * Reporter name like "spec"
|
232 | */
|
233 | reporter: string
|
234 | /**
|
235 | * This is controlled by the reporter, and Cypress cannot guarantee
|
236 | * the properties. Usually this object has suites, tests, passes, etc
|
237 | */
|
238 | reporterStats: object
|
239 | screenshots: ScreenshotInformation[]
|
240 | /**
|
241 | * Accurate test results collected by Cypress.
|
242 | */
|
243 | stats: {
|
244 | duration?: ms
|
245 | endedAt: dateTimeISO
|
246 | failures: number
|
247 | passes: number
|
248 | pending: number
|
249 | skipped: number
|
250 | startedAt: dateTimeISO
|
251 | suites: number
|
252 | tests: number
|
253 | }
|
254 | /**
|
255 | * information about the spec test file.
|
256 | */
|
257 | spec: SpecResult
|
258 | tests: TestResult[]
|
259 | video: string | null
|
260 | }
|
261 |
|
262 | type PublicConfig = Omit<Cypress.ResolvedConfigOptions, 'additionalIgnorePattern' | 'autoOpen' | 'browser' | 'browsers' | 'browserUrl' | 'clientRoute' | 'cypressEnv' | 'devServerPublicPathRoute' | 'morgan' | 'namespace' | 'proxyServer' | 'proxyUrl' | 'rawJson' | 'remote' | 'repoRoot' | 'report' | 'reporterRoute' | 'reporterUrl' | 'resolved' | 'setupNodeEvents' | 'socketId' | 'socketIoCookie' | 'socketIoRoute' | 'specs' | 'state' | 'supportFolder'> & {
|
263 | browsers: Cypress.PublicBrowser[]
|
264 | cypressInternalEnv: string
|
265 | }
|
266 |
|
267 | /**
|
268 | * Results returned by the test run.
|
269 | * @see https://on.cypress.io/module-api
|
270 | */
|
271 | interface CypressRunResult {
|
272 | browserName: string
|
273 | browserPath: string
|
274 | browserVersion: string
|
275 | config: PublicConfig
|
276 | cypressVersion: string
|
277 | endedTestsAt: dateTimeISO
|
278 | osName: string
|
279 | osVersion: string
|
280 | runs: RunResult[]
|
281 | /**
|
282 | * If Cypress test run was recorded, full url will be provided.
|
283 | * @see https://on.cypress.io/cloud-introduction
|
284 | */
|
285 | runUrl?: string
|
286 | startedTestsAt: dateTimeISO
|
287 | totalDuration: number
|
288 | totalFailed: number
|
289 | totalPassed: number
|
290 | totalPending: number
|
291 | totalSkipped: number
|
292 | totalSuites: number
|
293 | totalTests: number
|
294 | }
|
295 |
|
296 | /**
|
297 | * If Cypress fails to run at all (for example, if there are no spec files to run),
|
298 | * then it will return a CypressFailedRunResult. Check the failures attribute.
|
299 | * @example
|
300 | ```
|
301 | const result = await cypress.run()
|
302 | if (result.status === 'failed') {
|
303 | console.error('failures %d', result.failures)
|
304 | console.error(result.message)
|
305 | process.exit(result.failures)
|
306 | }
|
307 | ```
|
308 | *
|
309 | **/
|
310 | interface CypressFailedRunResult {
|
311 | status: 'failed'
|
312 | failures: number
|
313 | message: string
|
314 | }
|
315 |
|
316 | /**
|
317 | * Methods allow parsing given CLI arguments the same way Cypress CLI does it.
|
318 | */
|
319 | interface CypressCliParser {
|
320 | /**
|
321 | * Parses the given array of string arguments to "cypress run"
|
322 | * just like Cypress CLI does it.
|
323 | * @see https://on.cypress.io/module-api
|
324 | * @example
|
325 | * const cypress = require('cypress')
|
326 | * const args = ['cypress', 'run', '--browser', 'chrome']
|
327 | * const options = await cypress.cli.parseRunArguments(args)
|
328 | * // options is {browser: 'chrome'}
|
329 | * // pass the options to cypress.run()
|
330 | * const results = await cypress.run(options)
|
331 | */
|
332 | parseRunArguments(args: string[]): Promise<Partial<CypressRunOptions>>
|
333 | }
|
334 | }
|
335 |
|
336 | declare module 'cypress' {
|
337 | /**
|
338 | * Cypress NPM module interface.
|
339 | * @see https://on.cypress.io/module-api
|
340 | * @example
|
341 | ```
|
342 | const cypress = require('cypress')
|
343 | cypress.run().then(results => ...)
|
344 | ```
|
345 | */
|
346 | interface CypressNpmApi {
|
347 | /**
|
348 | * Execute a headless Cypress test run.
|
349 | * @see https://on.cypress.io/module-api#cypress-run
|
350 | * @example
|
351 | ```
|
352 | const cypress = require('cypress')
|
353 | // runs all spec files matching a wildcard
|
354 | cypress.run({
|
355 | spec: 'cypress/integration/admin*-spec.js'
|
356 | }).then(results => {
|
357 | if (results.status === 'failed') {
|
358 | // Cypress could not run
|
359 | } else {
|
360 | // inspect results object
|
361 | }
|
362 | })
|
363 | ```
|
364 | */
|
365 | run(options?: Partial<CypressCommandLine.CypressRunOptions>): Promise<CypressCommandLine.CypressRunResult | CypressCommandLine.CypressFailedRunResult>
|
366 | /**
|
367 | * Opens Cypress GUI. Resolves with void when the
|
368 | * GUI is closed.
|
369 | * @see https://on.cypress.io/module-api#cypress-open
|
370 | */
|
371 | open(options?: Partial<CypressCommandLine.CypressOpenOptions>): Promise<void>
|
372 |
|
373 | /**
|
374 | * Utility functions for parsing CLI arguments the same way
|
375 | * Cypress does
|
376 | */
|
377 | cli: CypressCommandLine.CypressCliParser
|
378 |
|
379 | /**
|
380 | * Provides automatic code completion for configuration in many popular code editors.
|
381 | * While it's not strictly necessary for Cypress to parse your configuration, we
|
382 | * recommend wrapping your config object with `defineConfig()`
|
383 | * @example
|
384 | * module.exports = defineConfig({
|
385 | * viewportWidth: 400
|
386 | * })
|
387 | *
|
388 | * @see ../types/cypress-npm-api.d.ts
|
389 | * @param {Cypress.ConfigOptions} config
|
390 | * @returns {Cypress.ConfigOptions} the configuration passed in parameter
|
391 | */
|
392 | defineConfig<ComponentDevServerOpts = any>(config: Cypress.ConfigOptions<ComponentDevServerOpts>): Cypress.ConfigOptions
|
393 |
|
394 | /**
|
395 | * Provides automatic code completion for Component Frameworks Definitions.
|
396 | * While it's not strictly necessary for Cypress to parse your configuration, we
|
397 | * recommend wrapping your Component Framework Definition object with `defineComponentFramework()`
|
398 | * @example
|
399 | * module.exports = defineComponentFramework({
|
400 | * type: 'cypress-ct-solid-js'
|
401 | * })
|
402 | *
|
403 | * @see ../types/cypress-npm-api.d.ts
|
404 | * @param {Cypress.ThirdPartyComponentFrameworkDefinition} config
|
405 | * @returns {Cypress.ThirdPartyComponentFrameworkDefinition} the configuration passed in parameter
|
406 | */
|
407 | defineComponentFramework(config: Cypress.ThirdPartyComponentFrameworkDefinition): Cypress.ThirdPartyComponentFrameworkDefinition
|
408 | }
|
409 |
|
410 | // export Cypress NPM module interface
|
411 | const cypress: CypressNpmApi
|
412 | export = cypress
|
413 | }
|