-
Notifications
You must be signed in to change notification settings - Fork 3.3k
chore: refactor cypress/cli
to TypeScript
#32063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
cypress
|
Project |
cypress
|
Branch Review |
chore/refactor_cli_to_ts
|
Run status |
|
Run duration | 11m 07s |
Commit |
|
Committer | Bill Glesias |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
0
|
|
0
|
|
1
|
|
0
|
|
681
|
View all changes introduced in this branch ↗︎ |
UI Coverage
37.38%
|
|
---|---|
|
129
|
|
77
|
Accessibility
97.35%
|
|
---|---|
|
3 critical
7 serious
1 moderate
1 minor
|
|
62
|
5e4e990
to
b06e770
Compare
rebase into first
rebase into second
…piled down to CommonJS
b06e770
to
34448c3
Compare
…s 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
passing CI on 1ddfa5e empty commit |
@@ -104,18 +113,18 @@ const runSmokeTest = (binaryDir, options) => { | |||
const stdioOptions = _.extend({}, { | |||
env: { | |||
...process.env, | |||
FORCE_COLOR: 0, | |||
FORCE_COLOR: '0', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtofStryker I've confused myself on whether this is actually testing what it should be testing. https://force-color.org/ This was the original PR: #28994
When this variable is present and not an empty string (regardless of its value), it should force the addition of ANSI color.
Wasn't the original intention to have this evaluate to OFF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to turn it off because the colored ANSI output was causing out verification task to fail. This should still be testing what we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtofStryker So FORCE_COLOR
is evaluating to true here which is what we want?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
const rendererOptions = { | ||
renderer, | ||
} | ||
|
||
const tasks = new Listr([ | ||
{ | ||
options: { title: util.titleize('Verifying Cypress can run', chalk.gray(binaryDir)) }, | ||
task: (ctx, task) => { | ||
title: util.titleize('Verifying Cypress can run', chalk.gray(binaryDir)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtofStryker I think this change is fixing behavior - this wasn't logging before (it's not in the snapshots) - is this the change in the snapshots that you were seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh duh that would explain it. It's been a while since I visited this PR and couldn't remember. Yes this was the change I saw in the snapshots not being deterministic. I'm going to double confirm by fixing this on develop and seeing if I see the same determinism problems
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const isPossibleLinuxWithIncorrectDisplay = (): boolean => { | ||
return isLinux() && !!process.env.DISPLAY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of feel like there are situations before where this may have not been working also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly but unlikely? Any use cases you can think of?
const { stdout } = await execa('uname', ['-m']).catch(() => ({ stdout: '' })) | ||
|
||
debug('arm uname -m result: %o ', { stdout }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { stdout } = await execa('uname', ['-m']).catch(() => ({ stdout: '' })) | |
debug('arm uname -m result: %o ', { stdout }) | |
const stdout = await execa('uname', ['-m']).catch(() => ({ stdout: '' })) | |
debug('arm uname -m result: %o ', stdout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what is implement currently is correct based on https://www.npmjs.com/package/execa/v/5.1.0#usage. the print statement is just electing to print this as an object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just seems like double destructuring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first is valid. The other wants to key an object with stdout
in the print which I can see why but it seems unnecessary? Either way probably fine to leave as is
const getUrl = (arch, version) => { | ||
if (is.url(version)) { | ||
const getUrl = (arch: string, version: string): string => { | ||
if (is.webUrl(version)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weirdly url is an alias of webUrl 🙄 so no change of behavior here but the type is right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct I thought the same thing. One has types the other doesn't but it is the exact same thing!
sinon.stub(fs, 'removeAsync').resolves() | ||
sinon.stub(state, 'getVersionDir').returns('/cache/Cypress/1.2.3') | ||
sinon.stub(state, 'getBinaryDir').returns('/cache/Cypress/1.2.3/Cypress.app') | ||
sinon.stub(state, 'getBinaryPkgAsync').resolves() | ||
sinon.stub(fs, 'ensureDirAsync').resolves(undefined) | ||
os.platform.returns('darwin') | ||
|
||
;(os.platform as any).returns('darwin') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AtofStryker Might prefer something like below - there's a lot of these leading semicolon cases which I don't think are super intuitive. Do we want to replace them all?
const platformStub = (os.platform as any)
platformStub.returns('darwin')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it reads better, but I don't know if it worth the effort to make this look better since we eventually plan on replacing mocha
with vitest
and will likely get rid of the spec_helper
all together? I think we just live with the syntax for now and clean it up when we migrate the testing harness
@@ -345,7 +347,7 @@ describe('/lib/tasks/install', function () { | |||
beforeEach(function () { | |||
sinon.stub(util, 'isInstalledGlobally').returns(true) | |||
|
|||
state.getBinaryPkgAsync.resolves({ version: 'x.x.x' }) | |||
;(state.getBinaryPkgAsync as any).resolves({ version: 'x.x.x' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same - a few leading semicolons in this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I'm fine with it until we either improve the types or migrate the testing harness. The other sane option with spec files at least is to just us an @ts-expect-error
as we get a lot of typing errors when we writing tests. something like:
// @ts-expect-error
state.getBinaryPkgAsync.resolves({ version: 'x.x.x' })
is completely normal
Additional details
Converts the Cypress CLI from JavaScript to TypeScript. This is to help with our eventual goal of moving to an ESM based repository, which is much easier when compiling to source. The files in the package have been migrated to TypeScript and now compile down to CommonJS (for now).


We still only ship the JavaScript files with the CLI
It's important with this migration to make sure there are NOT breaking changes to the CLI. This is confirmed below:
Loaded from CommonJS (in comparison with the
15.0.0
CLI)Loaded from ESM (in comparison with the
15.0.0
CLI)With this, it is easier to visualize that there isn't a breaking change to the CLI.
What is in scope for this PR
ts-node
require()
statements and use ES6 style import statementsWhat is not in scope for this PR
any
Steps to test
How has the user experience changed?
This change should go unnoticed to the end user as it is just a refactor
PR Tasks
cypress-documentation
?type definitions
?