Skip to content

fix: remove 'new' badge from Create from Component, fix parsing #31457

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<!-- See the ../guides/writing-the-cypress-changelog.md for details on writing the changelog. -->
## 14.3.2

_Released 5/1/2025 (PENDING)_

**Bugfixes:**

- Fixed an issue where Create from Component feature might not be able to parse React components from project files. Fixed in [#31457](https://github.com/cypress-io/cypress/pull/31457).

## 14.3.1

_Released 4/17/2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:header="t('createSpec.component.importFromComponent.header')"
:description="t('createSpec.component.importFromComponent.description')"
:icon="DocumentCodeIcon"
:badge-text="t('versions.new')"
/>
</template>

Expand Down
1 change: 1 addition & 0 deletions packages/data-context/src/actions/CodegenActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class CodegenActions {
let result = parseReactComponent(src, {
resolver: findAllWithLink(exportResolver, reactDocgenResolvers),
babelOptions: {
configFile: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This option disables the use of a config file for Babel. this is what we want since we're calling it directly, we don't want to pick up any config file that might be in the project

https://babeljs.io/docs/options#configfile

Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AtofStryker I added a test in CodegenActions.spec.ts just to make sure that we pass this option to Babel. I went down the road of trying to do a system test for this instead, but couldn't get it to work

Copy link
Contributor

Choose a reason for hiding this comment

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

its probably hard to do a system test since its code generation for a component? Have you tried a cy-in-cy test? That would give us the most coverage here

Copy link
Contributor

Choose a reason for hiding this comment

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

@astone123 any luck with the cy-in-cy test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no I haven't looked at it yet, will try it out this week

parserOpts: {
plugins: ['typescript', 'jsx'],
},
Expand Down
24 changes: 24 additions & 0 deletions packages/data-context/test/unit/actions/CodegenActions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,29 @@ describe('CodegenActions', () => {

expect(components).to.have.length(0)
})

it('ensure that Babel is instructed to not use a config file', async () => {
let capturedOptions = null
const mockReactDocgen = {
parse: (src, options) => {
capturedOptions = options

return [{ displayName: 'TestComponent' }]
},
builtinResolvers: {
FindExportedDefinitionsResolver: class {
resolve () {
return []
}
},
},
}

const filePath = path.join(process.cwd(), 'test/unit/actions/project/counter-class.jsx')

await actions.getReactComponentsFromFile(filePath, mockReactDocgen)

expect(capturedOptions.babelOptions.configFile).to.equal(false)
})
})
})
Loading