import React from 'react'; import PQueue from 'p-queue'; import delay from 'delay'; import ms from 'ms'; import {Static, Box, render} from '../../src/index.js'; import Summary from './summary.jsx'; import Test from './test.js'; 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', ]; type State = { startTime: number; completedTests: Array<{ path: string; status: string; }>; runningTests: Array<{ path: string; status: string; }>; }; class Jest extends React.Component, State> { constructor(properties: Record) { super(properties); this.state = { startTime: Date.now(), completedTests: [], runningTests: [], }; } render() { const {startTime, completedTests, runningTests} = this.state; return ( {test => ( )} {runningTests.length > 0 && ( {runningTests.map(test => ( ))} )} test.status === 'pass').length} failed={completedTests.filter(test => test.status === 'fail').length} time={ms(Date.now() - startTime)} /> ); } componentDidMount() { const queue = new PQueue({concurrency: 4}); for (const path of paths) { void queue.add(this.runTest.bind(this, path)); } } async runTest(path: string) { this.setState(previousState => ({ runningTests: [ ...previousState.runningTests, { status: 'runs', path, }, ], })); await delay(1000 * Math.random()); this.setState(previousState => ({ runningTests: previousState.runningTests.filter( test => test.path !== path, ), completedTests: [ ...previousState.completedTests, { status: Math.random() < 0.5 ? 'pass' : 'fail', path, }, ], })); } } render();