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

chore: Move component-index generation to scaffold-config package #21090

Merged
merged 4 commits into from Apr 20, 2022

Conversation

BlueWinds
Copy link
Contributor

User facing changelog

None. Internal change only.

Additional details

We wanted to move the template for component-index.html to live with the rest of the framework-specific code. This is general code cleanup related to the ct-archecture changes.

How has the user experience changed?

Only effect is a small fix to remove a couple of blank lines from the generated component-index.hmtl.

PR Tasks

  • Have tests been added/updated?
  • [N/A] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [N/A] Has a PR for user-facing changes been opened in cypress-documentation?
  • [N/A] Have API changes been updated in the type definitions?
  • [N/A] Have new configuration options been added to the cypress.schema.json?

@BlueWinds BlueWinds requested a review from ZachJW34 April 14, 2022 19:50
@BlueWinds BlueWinds requested review from a team and tgriesser as code owners April 14, 2022 19:50
@BlueWinds BlueWinds requested review from jennifer-shehane and removed request for a team April 14, 2022 19:50
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 14, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Apr 14, 2022



Test summary

4343 0 48 0Flakiness 0


Run details

Project cypress
Status Passed
Commit 01f8928
Started Apr 20, 2022 1:12 AM
Ended Apr 20, 2022 1:26 AM
Duration 14:06 💡
OS Linux Debian - 10.10
Browser Electron 94

View run in Cypress Dashboard ➡️


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 removed the request for review from jennifer-shehane April 15, 2022 06:13
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Minor comment, mainly around keeping the tests cross platform - I think we'd need to use os.EOL to make the test you've added run on windows, although many of our tests fail on windows, it mightn't be a big deal.

@@ -122,6 +123,7 @@ export const WIZARD_FRAMEWORKS = [
codeGenFramework: 'react',
glob: '*.{js,jsx,tsx}',
mountModule: 'cypress/react',
componentIndexHtml: componentIndexHtmlGenerator(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach. It seems like there's duplication (there is) but I think it's actually somewhat ideal. That said, if you forgot to add componentIndexHtml, the only way we'd know is via a type error.

One thing we could do is add a test that loops each of these, asserting the output, like

for (const framework of WIZARD_FRAMEWORKS) {
  const actual = framework.componentIndexHtmlGenerator()
  if (framework === 'nextjs') {
    // specific assertion
  } else {
    expect(actual).to.eq(<generic_template>)
  }
}

Do you think this would be useful to have, or the types are enough to keep us safe and confident? I could go either way.

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 think that relying on types is fine - if they're not here to catch issues like this, then why do we even have them? It's also implicitly covered by the system tests (though I wouldn't want to rely on them to cover this feature, they are a backstop against the types as well).


// If the framework returns an empty string for either of the modifiers,
// strip out the empty lines
return template.replace(/\n {4}\n/g, '\n')
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should be using https://nodejs.org/api/os.html#oseol

os.EOL // =>
    \n on POSIX
    \r\n on Windows

I think this would fail on windows?

Copy link
Contributor Author

@BlueWinds BlueWinds Apr 19, 2022

Choose a reason for hiding this comment

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

Hm. I don't think this is the right place for that - if we scaffold files using OS EOL separators, then that would be done in the scaffoldFile method in data-context/src/actions/WizardActions.ts. Then it would be in one place, applying to all files we scaffold to disk.

I don't think we should do that, though. Several other methods in that same file (scaffoldFixtures and scaffoldConfig for example) use \n as well. It'd be a bit of a change and would probably want its own ticket.

packages/scaffold-config/src/component-index-template.ts Outdated Show resolved Hide resolved
@@ -181,6 +185,7 @@ export const WIZARD_FRAMEWORKS = [
codeGenFramework: 'react',
glob: '*.{js,jsx,tsx}',
mountModule: 'cypress/react',
componentIndexHtml: componentIndexHtmlGenerator(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
componentIndexHtml: componentIndexHtmlGenerator(),
componentIndexHtml: componentIndexHtmlGenerator('<div id="__next_css__DO_NOT_USE__"></div>')

We have the react and next templates swapped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops. Fixed in upcoming commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was added to nuxt instead next!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix for realzies this time! ^^;;

packages/scaffold-config/src/frameworks.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Looks good, let's ship!

@lmiller1990 lmiller1990 merged commit 10dfccc into 10.0-release Apr 20, 2022
@lmiller1990 lmiller1990 deleted the UNIFY-1433-refactor-component-index.html branch April 20, 2022 01:45
tgriesser added a commit that referenced this pull request Apr 20, 2022
…e-config

* 10.0-release:
  chore: Move component-index generation to scaffold-config package (#21090)
  fix: label text should be clickable to toggle snapshot highlight (#21122)
  feat: add next preset to webpack-dev-server-fresh (#21069)
  chore: add dev-servers as deps to server to be included in the binary (#21142)
  fix: do not highlight preExtension if selected option is renameFolder (#21121)
  fix(unify): Remove 'Reconfigure' dropdown from Testing Type chooser (#21063)
  feat(unify): launchpad header breadcrumbs and reusable tooltip component (#20648)
  test: add windows-test-kitchensink job (#20847)
  fix: aut centering and height calculation (#21019)
  chore: fix tests that fail on windows (#21055)
  fix: running a new test after already having run tests (#21087)
  fix: ct project setup framework keys for next and nuxt (#21116)
  fix: remove MountReturn from scaffolded ct support file (#21119)
  fix: do not scaffold fixtures if folder exist (#21078)
  fix: revert "fix: types for Cypress.Commands.add (#20376)" (#21104)
  chore: Update Chrome (stable) to 100.0.4896.127 and Chrome (beta) to 101.0.4951.34 (#21083)
  fix: types for Cypress.Commands.add (#20376) (#20377)
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.

None yet

3 participants