-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest.js
35 lines (31 loc) · 1.06 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* eslint-disable @typescript-eslint/no-var-requires */
const ejs = require('ejs');
const path = require('path');
const fs = require('fs');
const tpl = `
import React from 'react';
import { render, screen } from '@testing-library/react';
import { debug } from 'jest-preview';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import <%=name%> from '../src/<%=name%>';
const title = '<%=name%>';
describe('<%=name%> test groups', () => {
test('render', () => {
render(<<%=name%> title="<%=name%>"/>);
const el = screen.getByTitle('<%=name%>');
expect(el).toBeDefined();
});
});
`;
fs.readdirSync(path.resolve(__dirname, './src')).forEach((file) => {
const filePath = path.resolve(__dirname, './src', file);
const stat = fs.lstatSync(filePath);
if (stat.isFile() && /^[A-Z]/.test(file)) {
const name = file.split('.')[0];
const testPath = path.resolve(__dirname, './test', name + '.test.tsx');
if (!fs.existsSync(testPath)) {
fs.writeFileSync(testPath, ejs.render(tpl, { name }));
}
}
});