Skip to content

Commit b5178c1

Browse files
committed
remove taskTests reducer, move into test run and load
1 parent 323433b commit b5178c1

File tree

16 files changed

+63
-139
lines changed

16 files changed

+63
-139
lines changed

.eslintrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
{}
1+
{
2+
"es6": true,
3+
"jest": true,
4+
"env": {
5+
"node": true,
6+
"browser": true
7+
},
8+
"rules": {
9+
"quotes": ["warning", "single"]
10+
}
11+
}

lib/modules/page/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ var page_position_1 = require('./page-position');
33
exports.pagePosition = page_position_1.default;
44
var task_actions_1 = require('./task-actions');
55
exports.taskActions = task_actions_1.default;
6-
var task_tests_1 = require('./task-tests');
7-
exports.taskTests = task_tests_1.default;

lib/modules/page/task-tests/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function taskTestsReducer(taskTests, action) {
55
if (taskTests === void 0) { taskTests = ''; }
66
switch (action.type) {
77
case types_1.PAGE_SET:
8-
var _a = action.payload, tutorial = _a.tutorial, tasks = _a.tasks;
8+
var tasks = action.payload.tasks;
99
return [].concat.apply([], tasks.map(function (task) { return task.tests || []; })).reduce(function (output, file) {
1010
try {
1111
output += fs_1.readFileSync(file, 'utf8') + '\n';

lib/modules/tests/actions.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ var testName_1 = require('./test-run/testName');
44
var types_1 = require('./types');
55
function testLoad() {
66
return function (dispatch, getState) {
7-
var _a = getState(), dir = _a.dir, pagePosition = _a.pagePosition, tutorial = _a.tutorial, taskTests = _a.taskTests;
7+
var _a = getState(), dir = _a.dir, pagePosition = _a.pagePosition, tutorial = _a.tutorial;
8+
var tasks = tutorial.pages[pagePosition].tasks || [];
89
var testFile = testName_1.default({ tutorial: tutorial, pagePosition: pagePosition });
910
dispatch({
1011
type: types_1.TEST_LOAD, payload: {
1112
dir: dir,
12-
tests: taskTests,
13+
tasks: tasks,
1314
load: tutorial.config.load,
1415
testFile: testFile,
1516
}
@@ -23,11 +24,13 @@ function testRun() {
2324
if (timeSinceLastTestRun < 1000) {
2425
return;
2526
}
26-
var _a = getState(), taskTests = _a.taskTests, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition, pagePosition = _a.pagePosition;
27+
var _a = getState(), dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition, pagePosition = _a.pagePosition;
28+
var tasks = tutorial.pages[pagePosition].tasks;
29+
var hasTasks = tasks && tasks.length > 0;
2730
var testFile = testName_1.default({ tutorial: tutorial, pagePosition: pagePosition });
2831
dispatch({
2932
type: types_1.TEST_RUN,
30-
payload: { taskTests: taskTests, dir: dir, tutorial: tutorial, taskPosition: taskPosition, testFile: testFile }
33+
payload: { hasTasks: hasTasks, dir: dir, tutorial: tutorial, taskPosition: taskPosition, testFile: testFile }
3134
});
3235
};
3336
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
"use strict";
2+
var fs_1 = require('fs');
23
function loadTaskTests(_a) {
3-
var dir = _a.dir, tests = _a.tests, load = _a.load, testFile = _a.testFile;
4+
var dir = _a.dir, tasks = _a.tasks, load = _a.load, testFile = _a.testFile;
5+
var tests = [].concat.apply([], tasks.map(function (task) { return task.tests || []; })).reduce(function (output, file) {
6+
try {
7+
output += fs_1.readFileSync(file, 'utf8') + '\n';
8+
}
9+
catch (e) {
10+
console.log('Error reading test file', e);
11+
}
12+
return output;
13+
}, '');
414
load({ dir: dir, tests: tests, testFile: testFile });
515
}
616
Object.defineProperty(exports, "__esModule", { value: true });

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
22
var handle_result_1 = require('./handle-result');
33
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) {
4+
var hasTasks = _a.hasTasks, dir = _a.dir, tutorial = _a.tutorial, taskPosition = _a.taskPosition, testFile = _a.testFile;
5+
if (hasTasks) {
66
tutorial.config.run({ dir: dir, taskPosition: taskPosition, handleResult: handle_result_1.default, testFile: testFile });
77
}
88
return performance.now();

lib/reducers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ exports.default = redux_1.combineReducers({
1717
alert: alert_1.default, checks: setup_1.checks, editor: editor_1.reducer, dir: dir_1.default, hintPosition: hints_1.default,
1818
packageJson: setup_1.packageJson, pagePosition: page_1.pagePosition, progress: progress_1.reducer, route: route_1.reducer,
1919
tutorial: tutorial_1.reducer, tutorials: tutorials_1.reducer,
20-
taskActions: page_1.taskActions, taskPosition: tests_1.taskPosition, taskTests: page_1.taskTests, testRun: tests_1.testRun, window: window_1.reducer
20+
taskActions: page_1.taskActions, taskPosition: tests_1.taskPosition, testRun: tests_1.testRun, window: window_1.reducer
2121
});

src/modules/page/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export {default as pagePosition} from './page-position';
22
export {default as taskActions} from './task-actions';
3-
export {default as taskTests} from './task-tests';

src/modules/page/task-tests/index.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/modules/page/task-tests/reducer.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/modules/tests/actions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import {TEST_COMPLETE, TEST_LOAD, TEST_RESULT, TEST_RUN} from './types';
44

55
export function testLoad(): Redux.ThunkAction<any, any, {}> {
66
return (dispatch, getState): void => {
7-
const { dir, pagePosition, tutorial, taskTests } = getState();
7+
const { dir, pagePosition, tutorial } = getState();
8+
const tasks = tutorial.pages[pagePosition].tasks || [];
89
const testFile = getTestName({tutorial, pagePosition});
910
dispatch({
1011
type: TEST_LOAD, payload: {
1112
dir,
12-
tests: taskTests,
13+
tasks,
1314
load: tutorial.config.load,
1415
testFile,
1516
}
@@ -24,12 +25,14 @@ export function testRun(): Redux.ThunkAction<any, any, {}> {
2425
if (timeSinceLastTestRun < 1000) {
2526
return;
2627
}
27-
const {taskTests, dir, tutorial, taskPosition, pagePosition} = getState();
28+
const {dir, tutorial, taskPosition, pagePosition} = getState();
29+
const tasks = tutorial.pages[pagePosition].tasks;
30+
const hasTasks = tasks && tasks.length > 0;
2831
const testFile = getTestName({tutorial, pagePosition});
2932

3033
dispatch({
3134
type: TEST_RUN,
32-
payload: { taskTests, dir, tutorial, taskPosition, testFile }
35+
payload: { hasTasks, dir, tutorial, taskPosition, testFile }
3336
});
3437
};
3538
}

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
export default function loadTaskTests({dir, tests, load, testFile}) {
1+
import { readFileSync } from 'fs';
2+
3+
export default function loadTaskTests({dir, tasks, load, testFile}) {
4+
5+
// map over task tests from coderoad.json
6+
const tests = [].concat.apply([], tasks.map(
7+
task => task.tests || []
8+
)
9+
// concat test files together
10+
).reduce((output: string, file: string): string => {
11+
try {
12+
output += readFileSync(file, 'utf8') + '\n';
13+
} catch (e) {
14+
console.log('Error reading test file', e);
15+
}
16+
// return concatenated test files
17+
return output;
18+
}, '');
19+
220
load({dir, tests, testFile});
321
}

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import handleResult from './handle-result';
22

33
export default function runTaskTests({
4-
taskTests, dir, tutorial, taskPosition, testFile
4+
hasTasks, dir, tutorial, taskPosition, testFile
55
}): number {
66

7-
if (taskTests && taskTests.length) {
7+
if (hasTasks) {
88
// call test runner
99
tutorial.config.run({dir, taskPosition, handleResult, testFile});
1010
}

src/reducers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {default as alert} from './modules/alert';
55
import {default as dir} from './modules/dir';
66
import {reducer as editor} from './modules/editor';
77
import {default as hintPosition} from './modules/hints';
8-
import {pagePosition, taskActions, taskTests} from './modules/page';
8+
import {pagePosition, taskActions} from './modules/page';
99
import {reducer as progress} from './modules/progress';
1010
import {reducer as route} from './modules/route';
1111
import {checks, packageJson} from './modules/setup';
@@ -18,5 +18,5 @@ export default combineReducers({
1818
alert, checks, editor, dir, hintPosition,
1919
packageJson, pagePosition, progress, route,
2020
tutorial, tutorials,
21-
taskActions, taskPosition, taskTests, testRun, window
21+
taskActions, taskPosition, testRun, window
2222
});

src/typings/coderoad/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ declare namespace CR {
2727
page: Page;
2828
progress: Progress;
2929
tasks: Task[];
30-
taskTests: string[];
3130
taskPosition: number;
3231
hintPosition: number;
3332
taskActions: string[];

0 commit comments

Comments
 (0)