Skip to content

Commit 44619db

Browse files
committed
chore: convert cypress spec to vitest
1 parent 8d321c8 commit 44619db

File tree

9 files changed

+199
-161
lines changed

9 files changed

+199
-161
lines changed

cli/.mocharc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module.exports = {
1616
'test/lib/tasks/verify.spec.ts',
1717
'test/lib/build.spec.ts',
1818
'test/lib/cli.spec.ts',
19-
'test/lib/cypress.spec.ts',
2019
],
2120
timeout: 10000,
2221
reporter: 'spec',

cli/__snapshots__/cypress.spec.ts.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

cli/lib/cli.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,3 @@ const cliModule = {
608608
}
609609

610610
export default cliModule
611-
612-
// @ts-ignore
613-
if (!module.parent) {
614-
logger.error('This CLI module should be required from another Node module')
615-
logger.error('and not executed directly')
616-
617-
process.exit(-1)
618-
}

cli/lib/cypress.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// https://github.com/cypress-io/cypress/issues/316
2-
3-
import Bluebird from 'bluebird'
42
import tmpModule from 'tmp'
5-
import fs from './fs'
3+
import fs from 'fs-extra'
64
import openModule from './exec/open'
75
import runModule from './exec/run'
86
import util from './util'
97
import cli from './cli'
108

11-
const tmp = Bluebird.promisifyAll(tmpModule) as any
12-
139
const cypressModuleApi = {
1410
/**
1511
* Opens Cypress GUI
@@ -25,35 +21,30 @@ const cypressModuleApi = {
2521
* Runs Cypress tests in the current project
2622
* @see https://on.cypress.io/module-api#cypress-run
2723
*/
28-
run (options: any = {}): any {
24+
async run (options: any = {}): Promise<any> {
2925
if (!runModule.isValidProject(options.project)) {
30-
return Bluebird.reject(new Error(`Invalid project path parameter: ${options.project}`))
26+
throw new Error(`Invalid project path parameter: ${options.project}`)
3127
}
3228

3329
options = util.normalizeModuleOptions(options)
30+
tmpModule.setGracefulCleanup()
3431

35-
tmp.setGracefulCleanup()
32+
const outputPath: string = tmpModule.file()
3633

37-
return tmp.fileAsync()
38-
.then((outputPath: string) => {
39-
options.outputPath = outputPath
34+
options.outputPath = outputPath
4035

41-
return runModule.start(options)
42-
.then((failedTests: any) => {
43-
return fs.readJsonAsync(outputPath, { throws: false })
44-
.then((output: any) => {
45-
if (!output) {
46-
return {
47-
status: 'failed',
48-
failures: failedTests,
49-
message: 'Could not find Cypress test run results',
50-
}
51-
}
36+
const failedTests = await runModule.start(options)
37+
const output = fs.readJson(outputPath, { throws: false })
38+
39+
if (!output) {
40+
return {
41+
status: 'failed',
42+
failures: failedTests,
43+
message: 'Could not find Cypress test run results',
44+
}
45+
}
5246

53-
return output
54-
})
55-
})
56-
})
47+
return output
5748
},
5849

5950
cli: {

cli/lib/tasks/download.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import la from 'lazy-ass'
2-
import is from 'check-more-types'
32
import os from 'os'
43
import url from 'url'
54
import path from 'path'
@@ -13,6 +12,9 @@ import { throwFormErrorText, errors } from '../errors'
1312
import fs from '../fs'
1413
import util from '../util'
1514

15+
// TODO: this package needs to be replaced as we can't import it in vitest
16+
const is = require('check-more-types')
17+
1618
const debug = Debug('cypress:cli')
1719

1820
const defaultBaseUrl = 'https://download.cypress.io/'

cli/lib/tasks/unzip.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import _ from 'lodash'
22
import la from 'lazy-ass'
3-
import is from 'check-more-types'
43
import cp from 'child_process'
54
import os from 'os'
65
import yauzl from 'yauzl'
@@ -12,6 +11,9 @@ import { throwFormErrorText, errors } from '../errors'
1211
import fs from '../fs'
1312
import util from '../util'
1413

14+
// TODO: this package needs to be replaced as we can't import it in vitest
15+
const is = require('check-more-types')
16+
1517
const debug = Debug('cypress:cli:unzip')
1618

1719
const unzipTools = {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`cypress > .run > resolves with contents of tmp file 1`] = `
4+
{
5+
"code": 0,
6+
"failingTests": [],
7+
}
8+
`;

0 commit comments

Comments
 (0)