Skip to content

Commit 695cb26

Browse files
committed
fix test run on page load bug, discriminate between timing for throttling testRun action
1 parent 3ca9813 commit 695cb26

File tree

12 files changed

+74
-21
lines changed

12 files changed

+74
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
# [0.10.10] - 2016-07-30
6+
- performance increase
7+
- fix test run on page load
8+
59
## [0.10.9] - 2016-07-24
610
- improved error handling
711

lib/components/Page/Task/taskCheckbox.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ var TaskCheckbox = (function (_super) {
2929
_super.apply(this, arguments);
3030
}
3131
TaskCheckbox.prototype.render = function () {
32-
var _a = this.props, testRun = _a.testRun, isCurrentTask = _a.isCurrentTask;
33-
if (!isCurrentTask || !testRun) {
32+
var _a = this.props, isRunning = _a.isRunning, isCurrentTask = _a.isCurrentTask;
33+
if (!isCurrentTask || !isRunning) {
3434
return null;
3535
}
3636
return React.createElement(indeterminate_check_box_1.default, {color: colors_1.orange500, style: styles.checkbox});
3737
};
3838
TaskCheckbox = __decorate([
3939
react_redux_1.connect(function (state, props) { return ({
40-
testRun: state.testRun,
40+
isRunning: state.testRun.running,
4141
isCurrentTask: state.taskPosition === props.index,
4242
}); }),
4343
__metadata('design:paramtypes', [])

lib/modules/tests/actions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ var actions_1 = require('../../actions');
33
var types_1 = require('./types');
44
function testRun() {
55
return function (dispatch, getState) {
6+
var timeSinceLastTestRun = performance.now() - getState().testRun.time;
7+
if (timeSinceLastTestRun < 1000) {
8+
return;
9+
}
610
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
711
dispatch({
812
type: types_1.TEST_RUN, payload: { taskTests: taskTests, dir: dir, tutorial: tutorial, taskPosition: taskPosition }
@@ -61,6 +65,8 @@ function testComplete(result) {
6165
result.msg = "Task " + result.taskPosition + " Complete";
6266
dispatch(testResult(result));
6367
break;
68+
default:
69+
return;
6470
}
6571
dispatch({ type: types_1.TEST_COMPLETE });
6672
};

lib/modules/tests/test-run/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
"use strict";
22
var types_1 = require('../types');
33
var run_1 = require('./run');
4+
var defaultTestRun = {
5+
running: false,
6+
time: performance.now(),
7+
};
48
function runTest(testRun, action) {
5-
if (testRun === void 0) { testRun = false; }
9+
if (testRun === void 0) { testRun = defaultTestRun; }
610
switch (action.type) {
711
case types_1.TEST_RUN:
812
var _a = action.payload, taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
9-
return run_1.default(taskTests, dir, tutorial, taskPosition);
13+
return {
14+
running: true,
15+
time: run_1.default(taskTests, dir, tutorial, taskPosition),
16+
};
1017
case types_1.TEST_COMPLETE:
11-
return false;
18+
return {
19+
running: false,
20+
time: performance.now() + 800,
21+
};
1222
case 'PAGE_SET':
13-
return false;
23+
return {
24+
running: false,
25+
time: performance.now() + 2000,
26+
};
1427
default:
1528
return testRun;
1629
}

lib/modules/tests/test-run/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function runTaskTests(taskTests, dir, tutorial, taskPosition) {
1313
};
1414
tutorialConfig.run({ testString: testString, config: config, handleResult: handle_result_1.default });
1515
}
16-
return true;
16+
return performance.now();
1717
}
1818
Object.defineProperty(exports, "__esModule", { value: true });
1919
exports.default = runTaskTests;

lib/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
55
exports.default = core_coderoad_1.configureStore({
66
reducer: reducers_1.default,
77
devMode: false,
8-
throttle: { TEST_RUN: 800 },
8+
throttle: {},
99
});

src/components/Page/Task/taskCheckbox.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ const styles = {
1414
};
1515

1616
@connect((state, props) => ({
17-
testRun: state.testRun,
17+
isRunning: state.testRun.running,
1818
isCurrentTask: state.taskPosition === props.index,
1919
}))
2020
export default class TaskCheckbox extends React.Component<{
21-
testRun?: boolean, isCurrentTask?: boolean, index: number
21+
isRunning?: boolean, isCurrentTask?: boolean, index: number
2222
}, {}> {
2323
public render() {
24-
const {testRun, isCurrentTask} = this.props;
25-
if (!isCurrentTask || !testRun) { return null; }
24+
const {isRunning, isCurrentTask} = this.props;
25+
if (!isCurrentTask || !isRunning) { return null; }
2626
return <IndeterminateCheckBox
2727
color={orange500}
2828
style={styles.checkbox}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Subscriptions from './subscriptions';
99
import {loadPolyfills, render} from 'core-coderoad';
1010
import * as injectTapEventPlugin from 'react-tap-event-plugin';
1111

12+
// React optimization
1213
process.env.NODE_ENV = 'production';
1314

1415
class Main {

src/modules/tests/actions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import {TEST_COMPLETE, TEST_RESULT, TEST_RUN} from './types';
33

44
export function testRun(): ReduxThunk.ThunkInterface {
55
return (dispatch, getState): void => {
6+
// less than a second since the last test run, skip
7+
const timeSinceLastTestRun = performance.now() - getState().testRun.time;
8+
if (timeSinceLastTestRun < 1000) {
9+
return;
10+
}
611
const {taskTests, dir, tutorial, taskPosition} = getState();
712
dispatch({
813
type: TEST_RUN, payload: { taskTests, dir, tutorial, taskPosition }
@@ -70,6 +75,8 @@ export function testComplete(result: Test.Result) {
7075
// check if page is completed
7176
dispatch(testResult(result));
7277
break;
78+
default:
79+
return;
7380
}
7481
dispatch({ type: TEST_COMPLETE });
7582
};

src/modules/tests/test-run/index.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
import {TEST_COMPLETE, TEST_RUN} from '../types';
22
import runTaskTests from './run';
33

4+
interface IRunTest {
5+
running: boolean;
6+
time: number;
7+
}
8+
9+
const defaultTestRun: IRunTest = {
10+
running: false,
11+
time: performance.now(),
12+
};
13+
414
export default function runTest(
5-
testRun = false, action: Action
6-
): boolean {
15+
testRun = defaultTestRun, action: Action
16+
): IRunTest {
717
switch (action.type) {
818

919
case TEST_RUN:
1020
const {taskTests, dir, tutorial, taskPosition} = action.payload;
11-
return runTaskTests(taskTests, dir, tutorial, taskPosition);
21+
// call test runner
22+
return {
23+
running: true,
24+
time: runTaskTests(taskTests, dir, tutorial, taskPosition),
25+
};
1226

1327
case TEST_COMPLETE:
14-
return false;
28+
return {
29+
running: false,
30+
time: performance.now() + 800,
31+
};
1532

1633
case 'PAGE_SET':
17-
return false;
34+
// add extra time, as page loading takes longer
35+
return {
36+
running: false,
37+
time: performance.now() + 2000,
38+
};
1839

1940
default:
2041
return testRun;

src/modules/tests/test-run/run.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import parseLoaders from './parse-loaders';
55

66
export default function runTaskTests(
77
taskTests: string, dir: string, tutorial: CR.Tutorial, taskPosition: number
8-
): boolean {
8+
): number {
99
const tests: string = taskTests;
1010

1111
if (tests && tests.length) {
@@ -23,5 +23,7 @@ export default function runTaskTests(
2323
// call test runner
2424
tutorialConfig.run({testString, config, handleResult});
2525
}
26-
return true;
26+
// return finishing time of test
27+
// used to throttle test runs
28+
return performance.now();
2729
}

src/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ import {configureStore} from 'core-coderoad';
44
export default configureStore({
55
reducer,
66
devMode: false,
7-
throttle: { TEST_RUN: 800 },
87
});

0 commit comments

Comments
 (0)