forked from vadimdemedes/ink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.js
99 lines (85 loc) · 2.05 KB
/
jest.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
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
90
91
92
93
94
95
96
97
98
99
'use strict';
const React = require('react');
const {default: PQueue} = require('p-queue');
const delay = require('delay');
const ms = require('ms');
const importJsx = require('import-jsx');
const {Static, Box, render} = require('../..');
const Summary = importJsx('./summary');
const Test = importJsx('./test');
const paths = [
'tests/login.js',
'tests/signup.js',
'tests/forgot-password.js',
'tests/reset-password.js',
'tests/view-profile.js',
'tests/edit-profile.js',
'tests/delete-profile.js',
'tests/posts.js',
'tests/post.js',
'tests/comments.js'
];
class Jest extends React.Component {
constructor() {
super();
this.state = {
startTime: Date.now(),
completedTests: [],
runningTests: []
};
}
render() {
const {startTime, completedTests, runningTests} = this.state;
return (
<Box flexDirection="column">
<Static>
{completedTests.map(test => (
<Test key={test.path} status={test.status} path={test.path}/>
))}
</Static>
{runningTests.length > 0 && (
<Box flexDirection="column" marginTop={1}>
{runningTests.map(test => (
<Test key={test.path} status={test.status} path={test.path}/>
))}
</Box>
)}
<Summary
isFinished={runningTests.length === 0}
passed={completedTests.filter(test => test.status === 'pass').length}
failed={completedTests.filter(test => test.status === 'fail').length}
time={ms(Date.now() - startTime)}
/>
</Box>
);
}
componentDidMount() {
const queue = new PQueue({concurrency: 4});
paths.forEach(path => {
queue.add(this.runTest.bind(this, path));
});
}
async runTest(path) {
this.setState(prevState => ({
runningTests: [
...prevState.runningTests,
{
status: 'runs',
path
}
]
}));
await delay(1000 * Math.random());
this.setState(prevState => ({
runningTests: prevState.runningTests.filter(test => test.path !== path),
completedTests: [
...prevState.completedTests,
{
status: Math.random() < 0.5 ? 'pass' : 'fail',
path
}
]
}));
}
}
render(<Jest/>);