Files
cypress/cli/test/lib/exec/versions_spec.ts
Bill Glesias 3481d1acaf chore: refactor cypress/cli to TypeScript (#32063)
* migrate cli scripts to TypeScript

* convert all javascript source files in the CLI to TypeScript

rebase into first

* chore: refactor all tests to TypeScript

rebase into second

* add npmignore for cli for typescript files

* update build process

* fix publically available exports

* Fix cy-in-cy tests

* add ts-expect-error to failing files

* fix projectConfigIpc failures as there are now multiple installs of tsx

* fix after-pack hook

* fix binary script

* chore: update publish binary to account for CLI being an ESModule compiled down to CommonJS

* does this work?

* fix the verify spec by making the listr2 renderer silent as it behaves differently since the refactor and is printing non deterministic outputs into our tests that do not have a large impact on the area we are testing and mostly served to actually test the renders of the listr2 framework itself

* empty commit

* additional refactor to code to remove strange any typing and exporting

* bump cache and build binaries

* fix CLI exports to keep backwards compatibility

* fix unit-tests

* turn on mac jobs

* fix group name rename in CLI

* remove babel deps from cli and explicitly install typescript

* address feedback from code review

* dont just falsy check results and instead explicitly check for null or undefined

* add ts-expect-error

* additional pass on cleaning up dynamic require / import from global lib references

* annotate ts-expect-errors with reason for why error is expected

* add rest of ts-expect-error comments

* removing hardcoded branch to publish binary chore/migrate_cli_to_typescript
2025-09-02 17:52:45 -04:00

90 lines
2.9 KiB
TypeScript

import { expect } from 'chai'
import '../../spec_helper'
import util from '../../../lib/util'
import state from '../../../lib/tasks/state'
import versions from '../../../lib/exec/versions'
describe('lib/exec/versions', function () {
const binaryDir = '/cache/1.2.3/Cypress.app'
beforeEach(function (): void {
sinon.stub(state, 'getBinaryDir').returns(binaryDir)
sinon.stub(state, 'getBinaryPkgAsync').withArgs(binaryDir).resolves({
version: '1.2.3',
electronVersion: '10.1.2',
electronNodeVersion: '12.16.3',
})
sinon.stub(util, 'pkgVersion').returns('4.5.6')
sinon.stub(util, 'pkgBuildInfo').returns({ stable: true })
})
describe('.getVersions', function () {
it('gets the correct binary and package version', function () {
return versions.getVersions().then(({ package: pkg, binary }: any) => {
expect(pkg, 'package version').to.eql('4.5.6')
expect(binary, 'binary version').to.eql('1.2.3')
})
})
it('gets the correct Electron and bundled Node version', function () {
return versions.getVersions().then(({ electronVersion, electronNodeVersion }: any) => {
expect(electronVersion, 'electron version').to.eql('10.1.2')
expect(electronNodeVersion, 'node version').to.eql('12.16.3')
})
})
it('gets correct binary version if CYPRESS_RUN_BINARY', function () {
sinon.stub(state, 'parseRealPlatformBinaryFolderAsync').resolves('/my/cypress/path')
process.env.CYPRESS_RUN_BINARY = '/my/cypress/path'
state.getBinaryPkgAsync
// @ts-expect-error - is shorthand stub on a function
.withArgs('/my/cypress/path')
.resolves({
version: '7.8.9',
})
return versions.getVersions().then(({ package: pkg, binary }: any) => {
expect(pkg).to.eql('4.5.6')
expect(binary).to.eql('7.8.9')
})
})
it('appends pre-release if not stable', async function () {
// @ts-expect-error - is shorthand stub on a function
util.pkgBuildInfo.returns({ stable: false })
const v = await versions.getVersions()
expect(v.package).to.eql('4.5.6 (pre-release)')
})
it('appends development if missing buildInfo', async function () {
// @ts-expect-error - is shorthand stub on a function
util.pkgBuildInfo.returns(undefined)
const v = await versions.getVersions()
expect(v.package).to.eql('4.5.6 (development)')
})
it('reports default versions if not found', function () {
// imagine package.json only has version there
// @ts-expect-error - is shorthand stub on a function
state.getBinaryPkgAsync.withArgs(binaryDir).resolves({
version: '90.9.9',
})
return versions.getVersions().then((versions: any) => {
expect(versions).to.deep.equal({
'package': '4.5.6',
'binary': '90.9.9',
'electronVersion': 'not found',
'electronNodeVersion': 'not found',
})
})
})
})
})