Skip to content

Commit 3c37879

Browse files
authored
Merge pull request #183 from arminbro/dev
Dev
2 parents a470dd1 + 3191ebd commit 3c37879

14 files changed

Lines changed: 105 additions & 170 deletions

bin/generate-react.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ function isNotValidNodeVersion() {
1212
details: 'Generate React CLI requires Node 22 or higher',
1313
suggestions: [
1414
'Update your Node.js version to 22 or higher',
15-
'Use nvm to manage multiple Node versions: nvm install 22',
1615
],
1716
});
1817

readme.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ When you run GRC within your project the first time, it will ask you a series of
5555
}
5656
```
5757

58+
#### Test library options:
59+
60+
- `Testing Library` - Generates tests using [React Testing Library](https://testing-library.com/docs/react-testing-library/intro/)
61+
- `Vitest` - Generates tests using [Vitest](https://vitest.dev/) with React Testing Library
62+
- `None` - Generates basic tests using React's createRoot API
63+
5864
## Generate Components
5965

6066
```sh
@@ -119,7 +125,7 @@ Otherwise, if you don't pass any options, it will just use the default values th
119125
<tr>
120126
<td width="20%"><b>--withLazy</b></td>
121127
<td width="60%">
122-
Creates a corresponding lazy file (a file that lazy-loads your component out of the box and enables <a href="https://reactjs.org/docs/code-splitting.html#code-splitting">code splitting</a>) with this component.
128+
Creates a corresponding lazy file (a file that lazy-loads your component out of the box and enables <a href="https://react.dev/reference/react/lazy">code splitting</a>) with this component.
123129
</td>
124130
<td width="20%">Boolean</td>
125131
<td width="20%"><code>component.default.withLazy<code></td>
@@ -295,7 +301,6 @@ Notice in the `page.customTemplates` that we only specified the `test` custom te
295301
```jsx
296302
// templates/component/TemplateName.js
297303

298-
import React from 'react';
299304
import styles from './TemplateName.module.css';
300305

301306
const TemplateName = () => (
@@ -324,14 +329,14 @@ export default TemplateName;
324329
```jsx
325330
// templates/component/TemplateName.test.js
326331

327-
import React from 'react';
328-
import ReactDOM from 'react-dom';
332+
import { createRoot } from 'react-dom/client';
329333
import TemplateName from './TemplateName';
330334

331-
it('It should mount', () => {
332-
const div = document.createElement('div');
333-
ReactDOM.render(<TemplateName />, div);
334-
ReactDOM.unmountComponentAtNode(div);
335+
it('should mount', () => {
336+
const container = document.createElement('div');
337+
const root = createRoot(container);
338+
root.render(<TemplateName />);
339+
root.unmount();
335340
});
336341
```
337342

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
export default `import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import styles from './templatename.module.css';
1+
export default `import styles from './templatename.module.css';
42
53
const templatename = () => (
64
<div className={styles.templatename} data-testid="templatename">
75
templatename Component
86
</div>
97
);
108
11-
templatename.propTypes = {};
12-
13-
templatename.defaultProps = {};
14-
159
export default templatename;
1610
`;

src/templates/component/componentLazyTemplate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export default `import React, { lazy, Suspense } from 'react';
1+
export default `import { lazy, Suspense } from 'react';
22
33
const Lazytemplatename = lazy(() => import('./templatename'));
44
5-
const templatename = props => (
5+
const templatename = (props) => (
66
<Suspense fallback={null}>
77
<Lazytemplatename {...props} />
88
</Suspense>
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
export default `/* eslint-disable */
2-
import templatename from './templatename';
1+
export default `import templatename from './templatename';
32
43
export default {
5-
title: "templatename",
4+
title: 'templatename',
5+
component: templatename,
66
};
77
8-
export const Default = () => <templatename />;
9-
10-
Default.story = {
11-
name: 'default',
12-
};
8+
export const Default = {};
139
`;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
export default `import React from 'react';
2-
import ReactDOM from 'react-dom';
1+
export default `import { createRoot } from 'react-dom/client';
32
import templatename from './templatename';
43
5-
it('It should mount', () => {
6-
const div = document.createElement('div');
7-
ReactDOM.render(<templatename />, div);
8-
ReactDOM.unmountComponentAtNode(div);
4+
it('should mount', () => {
5+
const container = document.createElement('div');
6+
const root = createRoot(container);
7+
root.render(<templatename />);
8+
root.unmount();
99
});`;

src/templates/component/componentTestEnzymeTemplate.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/templates/component/componentTestTestingLibraryTemplate.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
export default `import React from 'react';
2-
import { render, screen } from '@testing-library/react';
1+
export default `import { render, screen } from '@testing-library/react';
32
import '@testing-library/jest-dom';
43
import templatename from './templatename';
54
65
describe('<templatename />', () => {
7-
test('it should mount', () => {
6+
test('should mount', () => {
87
render(<templatename />);
98
109
const templateName = screen.getByTestId('templatename');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default `import { describe, test, expect } from 'vitest';
2+
import { render, screen } from '@testing-library/react';
3+
import '@testing-library/jest-dom/vitest';
4+
import templatename from './templatename';
5+
6+
describe('<templatename />', () => {
7+
test('should mount', () => {
8+
render(<templatename />);
9+
10+
const templateName = screen.getByTestId('templatename');
11+
12+
expect(templateName).toBeInTheDocument();
13+
});
14+
});
15+
`;

src/templates/component/componentTsLazyTemplate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export default `import React, { lazy, Suspense } from 'react';
1+
export default `import { lazy, Suspense, ComponentProps } from 'react';
22
33
const Lazytemplatename = lazy(() => import('./templatename'));
44
5-
const templatename = (props: JSX.IntrinsicAttributes & { children?: React.ReactNode; }) => (
5+
const templatename = (props: ComponentProps<typeof Lazytemplatename>) => (
66
<Suspense fallback={null}>
77
<Lazytemplatename {...props} />
88
</Suspense>

0 commit comments

Comments
 (0)