Skip to content
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

fix(launchpad): support default export #20383

Merged
merged 25 commits into from
Mar 1, 2022
Merged

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Feb 28, 2022

Closes: https://cypress-io.atlassian.net/browse/UNIFY-1073

Adds support for migrating cypress/plugins/index.ts to cypress.config.ts where the pluginsFile has export default.

Demo (Cypress internal team only).

@cypress
Copy link

cypress bot commented Feb 28, 2022



Test summary

17787 0 217 0Flakiness 3


Run details

Project cypress
Status Passed
Commit 96f6eda
Started Mar 1, 2022 10:36 PM
Ended Mar 1, 2022 10:48 PM
Duration 11:45 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

net_stubbing.cy.ts Flakiness
1 network stubbing > waiting and aliasing > can timeout waiting on a single request using "alias.request"
2 network stubbing > waiting and aliasing > can timeout waiting on a single request using "alias.request"
xhr.cy.js Flakiness
1 ... > no status when request isnt forced 404

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@lmiller1990 lmiller1990 changed the base branch from unify-1073-config-migration to 10.0-release February 28, 2022 06:05
@@ -7,7 +7,7 @@ module.exports = defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./')(on, config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were all wrong, how the heck did this get merged? This is why I don't generally like snapshots; they don't test behavior.

@lmiller1990 lmiller1990 changed the title chore: support default export fix(launchpad): support default export Feb 28, 2022
@lmiller1990 lmiller1990 marked this pull request as ready for review February 28, 2022 08:09
davidmunechika
davidmunechika previously approved these changes Feb 28, 2022
}

const pluginFile = fs.readFileSync(path.join(createConfigOptions.projectRoot, pluginPath), 'utf8')
const hasExportDefault = pluginFile.includes('export default')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more foolproof I believe

Suggested change
const hasExportDefault = pluginFile.includes('export default')
const hasExportDefault = /\nexport default /.test(pluginsFile)

We could also create a harmonizing function inside of cypress to use instead of require.

import { compatibleRequire } from 'cypress'

TBH, even the use of the require function at all seems like a bad idea.
An import at the top of the file would probably work better.

Copy link
Contributor Author

@lmiller1990 lmiller1990 Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the nice things with require is if there are any side effects, it won't execute until setupNodeEvents is called - that's closer to the original behavior. I think someone suggested a top-level import in the Jira ticket but this makes for a more minimal code change, which is nice. Why is require a bad idea? Any edge case I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also couldn't you have

      export default (on, config) {}

And your regexp would not work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the regexp, I am afraid of people using "task" to scaffold files before they start testing.

This could really throw you off.

My all-time fav is the babel way:

export default defineConfig({
  e2e: setupNodeEvent(on, config){
    const pluginsFunction = require('./cypress/plugins')
    return pluginsFunction.default ? pluginsFunction.default(on, config) : pluginsFunction(on, config)
  }
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to add a conditional to the generated config; it seems weird that we can't just give them the correct code out of the box.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also don't want to actually import their file to see if it has a .default property since that would trigger any side effects during config generation, not really ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I ended up implementing this with babel.

elevatebart
elevatebart previously approved these changes Mar 1, 2022
davidmunechika
davidmunechika previously approved these changes Mar 1, 2022
elevatebart
elevatebart previously approved these changes Mar 1, 2022
davidmunechika
davidmunechika previously approved these changes Mar 1, 2022
@lmiller1990 lmiller1990 dismissed stale reviews from davidmunechika and elevatebart via 96f6eda March 1, 2022 22:30
@lmiller1990
Copy link
Contributor Author

Fixed merge conflict, gonna merge this up since it had two ✅

@elevatebart elevatebart merged commit 7a02925 into 10.0-release Mar 1, 2022
@elevatebart elevatebart deleted the lmiller1990/UNIFY-1073 branch March 1, 2022 23:33
tgriesser added a commit that referenced this pull request Mar 2, 2022
* 10.0-release:
  fix: comment link to accurate docs (#20437)
  fix: scaffold commands file (#20398)
  fix(launchpad): support default export (#20383)
  feat(launchpad): support for Vue CLI 5 (#20413)
  fix: UNIFY-676 browsers should be configurable in setupNodeEvents (#20367)
  fix: make launchpad link open default browser (#20399)
  fix(icons): publish the files in the package
  fix: build icons in build-prod (#20411)
  test: migrate module-api to 10.0
  chore: build this branch
  test: migrate module_api to system tests (#20265)
  chore: remove pkg/driver //@ts-nocheck final (#20169)
  chore: fix "cannot find module" in clone-repo-and-checkout-release-branch (#20293)
  chore: Update Chrome (beta) to 99.0.4844.45 (#20234)
  chore: fix CI cache state for darwin (#20339)
  Add TODO comments
  feedback
  chore: move tests to its own file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants