Skip to content

Commit

Permalink
Close Issue tasty-api#8: Implement opportunity to run tests in parall…
Browse files Browse the repository at this point in the history
…el mode
  • Loading branch information
DariaLutkova committed May 26, 2020
1 parent 2c79a89 commit 1017932
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
5 changes: 3 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ app.get('/api/reports/:id', async (req, res) => {
});

app.post('/api/test', (req, res) => {
const filters = req.body.data;
const filters = req.body.data.filters;
const isParallel = req.body.data.isParallel;
const tests = filters.tests.length;
let done = 0;

io.emit('tests:start');

TastyRunner.setFilters(filters);

TastyRunner.run(filters.type, false, [], {
TastyRunner.run(filters.type, isParallel, [], {
onTestEnd: () => {
done ++;
io.emit('tests:test:finished', Math.round((done / tests) * 100));
Expand Down
7 changes: 5 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ export const fetchTests = async (filters) => {
}
};

export const runTests = async (filters) => {
export const runTests = async (filters, isParallel) => {
try {
const res = await axios.post('/api/test', {
data: filters,
data: {
filters,
isParallel
},
});

return res.data;
Expand Down
26 changes: 19 additions & 7 deletions src/subpages/Tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Badge, Button, Col, ListGroup, Row, Spinner, Toast, ProgressBar } from 'react-bootstrap';
import { Badge, Button, Col, ListGroup, Row, Spinner, Toast, ProgressBar, Form } from 'react-bootstrap';
import _ from 'lodash';
import * as api from '../api';
import { FaPlay as Run } from 'react-icons/fa';
Expand All @@ -16,6 +16,7 @@ class Tests extends React.Component {
loadLog: '',
errors: [],
percentage: 0,
isParallelMode: false,
};

socket = socketIOClient();
Expand Down Expand Up @@ -151,7 +152,7 @@ class Tests extends React.Component {
[`${this.type}Log`]: '',
});

await api.runTests(filters);
await api.runTests(filters, this.state.isParallelMode);
};

get type() {
Expand Down Expand Up @@ -234,7 +235,7 @@ class Tests extends React.Component {
};

render() {
const { tests, errors, percentage } = this.state;
const { tests, errors, percentage, isParallelMode } = this.state;

if (!tests) return <Spinner />;

Expand All @@ -256,10 +257,21 @@ class Tests extends React.Component {
this.renderStats()
)}
</Row>
<Row className="my-3">
<Button className="ml-3 my-auto" variant="outline-primary" onClick={this.handleToggleAll}>
{this.state.selected.length === this.state.tests.length ? 'Unselect All' : 'Select All'}
</Button>
<Row className="my-3 align-items-center">
<Col>
<Button className="my-auto" variant="outline-primary" onClick={this.handleToggleAll}>
{this.state.selected.length === this.state.tests.length ? 'Unselect All' : 'Select All'}
</Button>
<Form.Group className='mb-0' controlId="formBasicCheckbox">
<Form.Check
className='mt-2'
type="checkbox"
label="Run in Parallel Mode"
value={isParallelMode}
onClick={() => this.setState({ isParallelMode: !isParallelMode })}
/>
</Form.Group>
</Col>
</Row>
<Row>
<Col className="md-3" md={4}>
Expand Down

0 comments on commit 1017932

Please sign in to comment.