@@ -26,6 +26,7 @@ async function run() {
2626 writeFile ( ...initDemo ( ) ) ;
2727 writeFile ( ...initIndex ( ) ) ;
2828 writeFile ( ...initDoc ( ) ) ;
29+ writeFile ( ...initTest ( ) ) ;
2930 appendIndex ( ) ;
3031 console . log ( chalk . cyan ( '添加组件成功' ) ) ;
3132 } catch ( e ) {
@@ -163,6 +164,20 @@ export * from './${config.componentName}';
163164 return [ filename , content ] ;
164165}
165166
167+ function initTest ( ) : InitRes {
168+ const filename = getFilename ( 'test' ) ;
169+ const content = `
170+ import { render, fireEvent } from '@testing-library/react';
171+ import { ${ config . componentName } } from '..';
172+ import { testAttrs } from '~/testAttrs';
173+
174+ describe('${ config . componentName } ', () => {
175+ testAttrs(${ config . componentName } );
176+ });
177+ ` ;
178+ return [ filename , content ] ;
179+ }
180+
166181function initDoc ( ) : InitRes {
167182 const filename = getFilename ( 'doc' ) ;
168183 const content = `
@@ -231,7 +246,15 @@ function appendPlayground() {
231246}
232247
233248function getFilename (
234- type : 'doc' | 'scss' | 'index' | 'component' | 'types' | 'demo' | 'namespace' ,
249+ type :
250+ | 'doc'
251+ | 'scss'
252+ | 'index'
253+ | 'component'
254+ | 'types'
255+ | 'demo'
256+ | 'namespace'
257+ | 'test' ,
235258) {
236259 const name = config . name ;
237260 return (
@@ -243,6 +266,7 @@ function getFilename(
243266 index : 'index.ts' ,
244267 types : `${ name } .types.ts` ,
245268 demo : 'demo/basic.tsx' ,
269+ test : `__tests__/${ config . componentName } .test.tsx` ,
246270 } as Record < typeof type , string >
247271 ) [ type ] ;
248272}
0 commit comments