forked from petyosi/react-virtuoso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-cases.mjs
89 lines (75 loc) · 2.12 KB
/
test-cases.mjs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import * as fs from 'fs'
const examples = fs
.readdirSync('./e2e')
.filter((name) => name.match(/tsx$/))
.filter((name) => name !== 'server.tsx')
const code = `import React, { useEffect } from 'react'
import * as ReactDOM from 'react-dom'
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'
export default function App() {
const [exampleComponents, setExampleComponents] = React.useState([])
useEffect(() => {
void Promise.all([
${examples
.map((path) => {
const p = path.replace('.tsx', '')
return `Promise.all([ import("./${p}") , "/${p}" ])\n`
})
.join(', ')}
]).then((components) => {
setExampleComponents(() => {
return components.map(([comp, name]) => {
return { name, component: comp.default }
})
})
})
}, [])
return (
<Router>
<div style={{ height: '100%', display: 'flex' }}>
<div style={{ flex: 1, height: '100%' }} id="test-root" >
<Switch>
{exampleComponents.map(({ name, component }, index) => (
<Route key={index} path={name} component={component} />
))}
</Switch>
</div>
<ul style={{ minWidth: 200 }} id="side-nav">
{ exampleComponents.map(({ name }, index) => <li key={index}><Link to={name}>{name}</Link></li>) }
</ul>
</div>
</Router>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
`
const htmlCode = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>RV Test Cases</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
html, body {
padding: 0;
margin: 0;
}
#root {
min-height: 500px;
}
@media screen and (max-width: 900px) {
#side-nav {
display: none;
}
}
</style>
</head>
<body>
<div id="root"></div>
<script src="./__examples.jsx"></script>
</body>
</html>
`
fs.writeFileSync('e2e/__examples.jsx', code)
fs.writeFileSync('e2e/__examples.html', htmlCode)