forked from ChainLearnOfficial/chainlearn-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch10.js
More file actions
44 lines (41 loc) · 1.45 KB
/
Copy pathpatch10.js
File metadata and controls
44 lines (41 loc) · 1.45 KB
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
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const files = [
'src/components/layout/mobile-nav.test.tsx',
'src/components/layout/sidebar.test.tsx',
'src/tests/layout/mobile-nav.test.tsx',
'src/tests/layout/sidebar.test.tsx'
];
for (const file of files) {
if (!fs.existsSync(file)) continue;
let code = fs.readFileSync(file, 'utf8');
if (!code.includes('useAuthStore')) {
code = code.replace(
/import \{ render, screen \} from "@testing-library\/react";/,
`import { render, screen } from "@testing-library/react";\nimport { useAuthStore } from "@/store/auth-store";`
);
}
if (!code.includes('useAuthStore.setState')) {
if (!code.includes('beforeEach')) {
code = code.replace(
/describe\(".*", \(\) => \{/,
`describe("Nav", () => {\n beforeEach(() => {\n useAuthStore.setState({ isAuthenticated: true, hasHydrated: true });\n });\n`
);
} else {
code = code.replace(
/beforeEach\(\(\) => \{/,
`beforeEach(() => {\n useAuthStore.setState({ isAuthenticated: true, hasHydrated: true });`
);
}
}
fs.writeFileSync(file, code);
}
const headerFiles = [
'src/components/layout/header.test.tsx',
'src/tests/layout/header.test.tsx'
];
for (const file of headerFiles) {
if (!fs.existsSync(file)) continue;
let code = fs.readFileSync(file, 'utf8');
code = code.replace(/getByLabelText\("Toggle navigation"\)/g, 'getByLabelText(/Toggle navigation/i)');
fs.writeFileSync(file, code);
}