-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Changes from all commits
72c5619
d77d243
6ef7221
d362468
cbe71d0
cbc69f5
5ea7fa7
da1f552
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ export class CodegenActions { | |
let result = parseReactComponent(src, { | ||
resolver: findAllWithLink(exportResolver, reactDocgenResolvers), | ||
babelOptions: { | ||
configFile: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to add a test for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AtofStryker I added a test in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @astone123 any luck with the cy-in-cy test? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AtofStryker I finally added a test for this - let me know what you think |
||
parserOpts: { | ||
plugins: ['typescript', 'jsx'], | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// This config is taken from the cypress-services project. | ||
// It is used to test that the Create from Component functionality works correctly | ||
// even when a project has a conflicting babel configuration file. | ||
// The babel config in this test project includes TypeScript preset and transform plugins | ||
// that interfere with react-docgen parsing without passing `configFile: false` to the babel parser. | ||
const merge = require('babel-merge') | ||
const rootConfig = { | ||
plugins: [ | ||
'@babel/plugin-transform-logical-assignment-operators', | ||
'@babel/plugin-transform-export-namespace-from', | ||
['@babel/proposal-class-properties', { loose: true }], | ||
'@babel/plugin-proposal-object-rest-spread', | ||
'@babel/plugin-transform-runtime', | ||
'@babel/plugin-syntax-dynamic-import', | ||
'@babel/plugin-proposal-optional-chaining', | ||
'babel-plugin-add-react-displayname', | ||
], | ||
presets: [ | ||
[ | ||
'@babel/env', | ||
{ | ||
corejs: { | ||
version: 3, | ||
}, | ||
useBuiltIns: 'usage', | ||
modules: false, | ||
loose: true, | ||
}, | ||
], | ||
'@babel/react', | ||
'@babel/typescript', | ||
], | ||
} | ||
|
||
const makeNycConfig = require('../../../makeNycConfig') | ||
|
||
const plugins = [ | ||
'optimize-clsx', | ||
'@babel/plugin-transform-export-namespace-from', | ||
['@babel/proposal-decorators', { legacy: true }], | ||
'@babel/plugin-proposal-private-methods', | ||
[ | ||
'prismjs', | ||
{ | ||
languages: ['javascript', 'yml', 'diff'], | ||
plugins: [ | ||
'line-numbers', | ||
'normalize-whitespace', | ||
'diff-highlight', | ||
'line-highlight', | ||
], | ||
theme: 'default', | ||
css: true, | ||
}, | ||
], | ||
] | ||
|
||
// TODO apply it with babel's env | ||
// only instrument the frontend code during tests | ||
// should we insert instrumentation only for the dashboard project? | ||
if ( | ||
process.env.SERVER_ENV === 'test' || | ||
(process.env.SERVER_ENV === 'development' && process.env.CI) || | ||
process.env.CYPRESS_CT_COVERAGE || | ||
process.env.FORCE_COVERAGE | ||
) { | ||
plugins.push(['babel-plugin-istanbul', makeNycConfig('dashboard')]) | ||
} | ||
|
||
if (process.env.CYPRESS) { | ||
plugins.push('@babel/plugin-transform-modules-commonjs') | ||
} | ||
|
||
// ! inject proposal-decorators *before* | ||
module.exports = merge( | ||
{ | ||
plugins, | ||
}, | ||
rootConfig, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default ({ | ||
component: { | ||
experimentalSingleTabRunMode: true, | ||
devServer: { | ||
framework: 'react', | ||
bundler: 'webpack', | ||
}, | ||
}, | ||
e2e: { | ||
supportFile: false, | ||
}, | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"> | ||
<title>Components App</title> | ||
</head> | ||
<body> | ||
<div data-cy-root></div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// *********************************************************** | ||
// This example support/component.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
import { mount } from 'cypress/react' | ||
|
||
Cypress.Commands.add('mount', mount) | ||
|
||
// Example use: | ||
// cy.mount(MyComponent) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "no-specs-babel-conflict", | ||
"version": "0.0.0-test", | ||
"dependencies": { | ||
"babel-merge": "3.0.0", | ||
"core-js": "^3.0.0", | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.0", | ||
"babel-plugin-add-react-displayname": "^0.0.5", | ||
"@babel/plugin-proposal-class-properties": "^7.12.0", | ||
"@babel/plugin-proposal-decorators": "^7.12.0", | ||
"@babel/plugin-transform-react-jsx": "^7.12.0", | ||
"@babel/plugin-transform-runtime": "^7.12.0", | ||
"@babel/preset-env": "^7.12.0", | ||
"@babel/preset-react": "^7.12.0", | ||
"@babel/preset-typescript": "^7.12.0", | ||
"@babel/runtime-corejs3": "^7.12.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
|
||
// Using modern JS features that babel would transform | ||
const defaultProps = { | ||
title: 'Hello World', | ||
className: 'spec-gen-component-app', | ||
} | ||
|
||
function App (props = {}) { | ||
// Object destructuring and spread - babel would transform this | ||
const { title, className, ...restProps } = { ...defaultProps, ...props } | ||
|
||
// Template literals and arrow functions | ||
const getMessage = () => `${title} from React` | ||
|
||
return ( | ||
<div data-cy={className} {...restProps}> | ||
{getMessage()} | ||
</div> | ||
) | ||
} | ||
|
||
// Modern export syntax | ||
export default App | ||
|
||
// Named export that also uses modern syntax | ||
export const AppWithDefaults = (props) => <App {...defaultProps} {...props} /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react' | ||
|
||
/*eslint-disable */ | ||
export function MyComponent (({ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
monospace; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import './index.css' | ||
import App from './App' | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root'), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js|jsx)$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
}, | ||
resolve: { extensions: ['.js', '.jsx'] }, | ||
}, | ||
], | ||
}, | ||
} |
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.
this isn't new anymore