Skip to content

Commit f63b205

Browse files
committed
restructuring test running for load and run - nearly complete
1 parent 011b0e6 commit f63b205

File tree

19 files changed

+121
-150
lines changed

19 files changed

+121
-150
lines changed

lib/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var actions_4 = require('./modules/progress/actions');
1212
exports.progressLoad = actions_4.progressLoad;
1313
exports.progressCompletePage = actions_4.progressCompletePage;
1414
var actions_5 = require('./modules/tests/actions');
15+
exports.testLoad = actions_5.testLoad;
1516
exports.testRun = actions_5.testRun;
1617
exports.testResult = actions_5.testResult;
1718
exports.testComplete = actions_5.testComplete;

lib/components/Routes/index.js

-47
This file was deleted.

lib/modules/page/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function pageSet(pagePosition) {
2121
dispatch({
2222
type: types_1.PAGE_SET, payload: { pagePosition: pagePosition, tutorial: tutorial, progress: progress, tasks: tasks }
2323
});
24+
dispatch(actions_1.testLoad());
2425
};
2526
}
2627
exports.pageSet = pageSet;

lib/modules/tests/actions.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
"use strict";
22
var actions_1 = require('../../actions');
3+
var testName_1 = require('./test-run/testName');
34
var types_1 = require('./types');
5+
function testLoad() {
6+
return function (dispatch, getState) {
7+
var _a = getState(), dir = _a.dir, pagePosition = _a.pagePosition, tutorial = _a.tutorial, taskTests = _a.taskTests;
8+
var testFile = testName_1.default({ tutorial: tutorial, pagePosition: pagePosition });
9+
dispatch({
10+
type: types_1.TEST_LOAD, payload: {
11+
dir: dir,
12+
tests: taskTests,
13+
load: tutorial.config.load,
14+
testFile: testFile,
15+
}
16+
});
17+
};
18+
}
19+
exports.testLoad = testLoad;
420
function testRun() {
521
return function (dispatch, getState) {
622
var timeSinceLastTestRun = performance.now() - getState().testRun.time;
723
if (timeSinceLastTestRun < 1000) {
824
return;
925
}
10-
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
26+
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition, pagePosition = _a.pagePosition;
27+
var testFile = testName_1.default({ tutorial: tutorial, pagePosition: pagePosition });
1128
dispatch({
12-
type: types_1.TEST_RUN, payload: { taskTests: taskTests, dir: dir, tutorial: tutorial, taskPosition: taskPosition }
29+
type: types_1.TEST_RUN,
30+
payload: { taskTests: taskTests, dir: dir, tutorial: tutorial, taskPosition: taskPosition, testFile: testFile }
1331
});
1432
};
1533
}
1634
exports.testRun = testRun;
17-
function testLoad() {
18-
return function (dispatch, getState) {
19-
var _a = getState(), dir = _a.dir, pagePosition = _a.pagePosition, tutorial = _a.tutorial;
20-
dispatch({
21-
type: types_1.TEST_LOAD, payload: {
22-
dir: dir,
23-
pagePosition: pagePosition,
24-
tutorial: {
25-
name: tutorial.name,
26-
version: tutorial.version
27-
}
28-
}
29-
});
30-
};
31-
}
32-
exports.testLoad = testLoad;
3335
function testResult(result) {
3436
return function (dispatch, getState) {
3537
var _a = getState(), taskActions = _a.taskActions, progress = _a.progress, pagePosition = _a.pagePosition;

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,22 @@ var defaultTestRun = {
1111
function runTest(testRun, action) {
1212
if (testRun === void 0) { testRun = defaultTestRun; }
1313
switch (action.type) {
14+
case types_1.TEST_LOAD:
15+
load_1.default(action.payload);
16+
return {
17+
running: false,
18+
time: performance.now() + pageSetTimeout,
19+
};
1420
case types_1.TEST_RUN:
15-
var _a = action.payload, taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition;
1621
return {
1722
running: true,
18-
time: run_1.default(taskTests, dir, tutorial, taskPosition),
23+
time: run_1.default(action.payload),
1924
};
2025
case types_1.TEST_COMPLETE:
2126
return {
2227
running: false,
2328
time: performance.now() + testCompleteTimeout,
2429
};
25-
case 'PAGE_SET':
26-
load_1.default();
27-
return {
28-
running: false,
29-
time: performance.now() + pageSetTimeout,
30-
};
3130
default:
3231
return testRun;
3332
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
2-
function loadTaskTests() {
3-
console.log('load');
2+
function loadTaskTests(_a) {
3+
var dir = _a.dir, tutorial = _a.tutorial, tests = _a.tests, pagePosition = _a.pagePosition, load = _a.load;
4+
load({ dir: dir, tutorial: tutorial, tests: tests, pagePosition: pagePosition });
45
}
56
Object.defineProperty(exports, "__esModule", { value: true });
67
exports.default = loadTaskTests;

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

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
"use strict";
22
var handle_result_1 = require('./handle-result');
3-
var parse_loaders_1 = require('./parse-loaders');
4-
function runTaskTests(taskTests, dir, tutorial, taskPosition) {
5-
var tests = taskTests;
6-
if (tests && tests.length) {
7-
var tutorialConfig = tutorial.config;
8-
var testString = parse_loaders_1.default(tests, tutorialConfig.testSuffix, tutorial, dir);
9-
var config = {
10-
dir: dir,
11-
tutorialDir: tutorialConfig.dir,
12-
taskPosition: taskPosition
13-
};
14-
tutorialConfig.run({ testString: testString, config: config, handleResult: handle_result_1.default });
3+
function runTaskTests(_a) {
4+
var taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition, testFile = _a.testFile;
5+
if (taskTests && taskTests.length) {
6+
tutorial.config.run({ dir: dir, taskPosition: taskPosition, handleResult: handle_result_1.default, testFile: testFile });
157
}
168
return performance.now();
179
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
function getTestName(_a) {
3+
var tutorial = _a.tutorial, pagePosition = _a.pagePosition;
4+
if (!tutorial || !tutorial.name || !tutorial.version || typeof pagePosition !== 'number') {
5+
console.log('Error creating temporary test name');
6+
}
7+
return tutorial.name + "__" + tutorial.version + "__" + pagePosition;
8+
}
9+
Object.defineProperty(exports, "__esModule", { value: true });
10+
exports.default = getTestName;

lib/modules/tutorial/utils/config-runner.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,10 @@ function configRunner(name, runner, dir) {
2424
runnerMain = path_1.join.apply(null, runnerMain.split(slash));
2525
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf(slash));
2626
var pathToMain = path_1.join(runnerRoot, runnerMain);
27-
if (!!require(pathToMain).default) {
28-
return require(pathToMain).default;
29-
}
30-
else {
31-
return require(pathToMain);
32-
}
27+
return {
28+
load: require(pathToMain).load,
29+
run: require(pathToMain).run,
30+
};
3331
}
3432
Object.defineProperty(exports, "__esModule", { value: true });
3533
exports.default = configRunner;

lib/modules/tutorial/utils/config.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ function tutorialConfig(tutorialPj, dir) {
99
var runner = config.runner;
1010
var runnerOptions = config.runnerOptions || {};
1111
var configEdit = tutorialPj.config.edit;
12+
var getRunner = config_runner_1.default(name, config.runner, dir);
1213
return {
1314
dir: tutorialDir,
1415
runner: runner,
1516
runnerOptions: runnerOptions,
16-
run: config_runner_1.default(name, config.runner, dir),
17+
run: getRunner.run,
18+
load: getRunner.load,
1719
testSuffix: configTestSuffix(config.testSuffix),
1820
issuesPath: config_repo_1.configIssuesPath(tutorialPj.bugs),
1921
repo: repo,

src/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export {alertOpen, alertClose, alertReplay} from './modules/alert/actions';
22
export {hintPositionSet} from './modules/hints/actions';
33
export {pageSet, pageNext} from './modules/page/actions';
44
export {progressLoad, progressCompletePage} from './modules/progress/actions';
5-
export {testRun, testResult, testComplete} from './modules/tests/actions';
5+
export {testLoad, testRun, testResult, testComplete} from './modules/tests/actions';
66
export {setupVerify, setupPackage} from './modules/setup/actions';
77
export {tutorialSet} from './modules/tutorial';
88
export {tutorialsFind, tutorialUpdate} from './modules/tutorials';

src/modules/page/actions.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {hintPositionSet, routeSet} from '../../actions';
1+
import {hintPositionSet, routeSet, testLoad} from '../../actions';
22
import {PAGE_SET} from './types';
33

44
export function pageNext(): ReduxThunk.ThunkInterface | Action {
@@ -24,5 +24,6 @@ export function pageSet(pagePosition = 0): ReduxThunk.ThunkInterface {
2424
dispatch({
2525
type: PAGE_SET, payload: { pagePosition, tutorial, progress, tasks }
2626
});
27+
dispatch(testLoad());
2728
};
2829
}

src/modules/tests/actions.ts

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import {alertOpen, hintPositionSet, progressCompletePage} from '../../actions';
2+
import getTestName from './test-run/testName';
23
import {TEST_COMPLETE, TEST_LOAD, TEST_RESULT, TEST_RUN} from './types';
34

5+
export function testLoad() {
6+
return (dispatch, getState): void => {
7+
const { dir, pagePosition, tutorial, taskTests } = getState();
8+
const testFile = getTestName({tutorial, pagePosition});
9+
10+
dispatch({
11+
type: TEST_LOAD, payload: {
12+
dir,
13+
tests: taskTests,
14+
load: tutorial.config.load,
15+
testFile,
16+
}
17+
});
18+
};
19+
}
20+
421
export function testRun(): ReduxThunk.ThunkInterface {
522
return (dispatch, getState): void => {
623
// less than a second since the last test run, skip
724
const timeSinceLastTestRun = performance.now() - getState().testRun.time;
825
if (timeSinceLastTestRun < 1000) {
926
return;
1027
}
11-
const {taskTests, dir, tutorial, taskPosition} = getState();
12-
dispatch({
13-
type: TEST_RUN, payload: { taskTests, dir, tutorial, taskPosition }
14-
});
15-
};
16-
}
28+
const {taskTests, dir, tutorial, taskPosition, pagePosition} = getState();
29+
const testFile = getTestName({tutorial, pagePosition});
1730

18-
export function testLoad() {
19-
return (dispatch, getState): void => {
20-
const { dir, pagePosition, tutorial } = getState();
2131
dispatch({
22-
type: TEST_LOAD, payload: {
23-
dir,
24-
pagePosition,
25-
tutorial: {
26-
name: tutorial.name,
27-
version: tutorial.version
28-
}
29-
}
32+
type: TEST_RUN,
33+
payload: { taskTests, dir, tutorial, taskPosition, testFile }
3034
});
3135
};
3236
}

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

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {TEST_COMPLETE, TEST_RUN} from '../types';
1+
import {TEST_COMPLETE, TEST_LOAD, TEST_RUN} from '../types';
22
import loadTaskTests from './load';
33
import runTaskTests from './run';
44

@@ -21,12 +21,19 @@ export default function runTest(
2121
): IRunTest {
2222
switch (action.type) {
2323

24+
case TEST_LOAD:
25+
loadTaskTests(action.payload);
26+
// add extra time, as page loading takes longer
27+
return {
28+
running: false,
29+
time: performance.now() + pageSetTimeout,
30+
};
31+
2432
case TEST_RUN:
25-
const {taskTests, dir, tutorial, taskPosition} = action.payload;
2633
// call test runner
2734
return {
2835
running: true,
29-
time: runTaskTests(taskTests, dir, tutorial, taskPosition),
36+
time: runTaskTests(action.payload),
3037
};
3138

3239
case TEST_COMPLETE:
@@ -35,14 +42,6 @@ export default function runTest(
3542
time: performance.now() + testCompleteTimeout,
3643
};
3744

38-
case 'PAGE_SET':
39-
loadTaskTests();
40-
// add extra time, as page loading takes longer
41-
return {
42-
running: false,
43-
time: performance.now() + pageSetTimeout,
44-
};
45-
4645
default:
4746
return testRun;
4847
}

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export default function loadTaskTests() {
2-
console.log('load')
3-
// tutorialConfig.run({});
1+
export default function loadTaskTests({dir, tutorial, tests, pagePosition, load}) {
2+
load({dir, tutorial, tests, pagePosition});
43
}

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

+15-16
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,24 @@ import {join} from 'path';
33
import handleResult from './handle-result';
44
import parseLoaders from './parse-loaders';
55

6-
export default function runTaskTests(
7-
taskTests: string, dir: string, tutorial: CR.Tutorial, taskPosition: number
8-
): number {
9-
const tests: string = taskTests;
6+
export default function runTaskTests({
7+
taskTests, dir, tutorial, taskPosition, testFile
8+
}): number {
109

11-
if (tests && tests.length) {
12-
const tutorialConfig: Tutorial.Config = tutorial.config;
13-
const testString = parseLoaders(
14-
tests, tutorialConfig.testSuffix, tutorial, dir
15-
);
16-
17-
const config: Test.Config = {
18-
dir,
19-
tutorialDir: tutorialConfig.dir,
20-
taskPosition
21-
};
10+
if (taskTests && taskTests.length) {
11+
// const tutorialConfig: Tutorial.Config = tutorial.config;
12+
// const testString = parseLoaders(
13+
// tests, tutorialConfig.testSuffix, tutorial, dir
14+
// );
15+
//
16+
// const config: Test.Config = {
17+
// dir,
18+
// tutorialDir: tutorialConfig.dir,
19+
// taskPosition
20+
// };
2221

2322
// call test runner
24-
tutorialConfig.run({testString, config, handleResult});
23+
tutorial.config.run({dir, taskPosition, handleResult, testFile});
2524
}
2625
// return finishing time of test
2726
// used to throttle test runs

0 commit comments

Comments
 (0)