Skip to content

Commit 4e57617

Browse files
committed
use memory instead of read/writes for tests
1 parent b57c0ab commit 4e57617

File tree

9 files changed

+34
-97
lines changed

9 files changed

+34
-97
lines changed

lib/reducers/run-tests/run.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ var fs = require('fs');
55
var path = require('path');
66
var parse_loaders_1 = require('./parse-loaders');
77
function runTaskTests(setup) {
8-
var testFile = _base_1.store.getState().taskTests;
9-
if (testFile) {
8+
var tests = _base_1.store.getState().taskTests;
9+
if (tests && tests.length) {
1010
var config = window.coderoad;
1111
config.taskPosition = _base_1.store.getState().taskPosition;
12-
var fileType = testFile.substr(testFile.lastIndexOf('.') + 1, testFile.length) || null;
13-
var tests = fs.readFileSync(testFile, 'utf8');
14-
var output = parse_loaders_1.default(tests, fileType);
15-
var target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, "_tmp" + window.coderoad.suffix);
12+
var output = parse_loaders_1.default(tests, window.coderoad.suffix);
13+
var target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, "_tmp." + window.coderoad.suffix);
1614
fs.writeFileSync(target, output, 'utf8');
1715
window.coderoad.runner(target, config, test_result_1.handleResult);
1816
}

lib/reducers/task-tests/loader.js

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

lib/reducers/task-tests/task-tests.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
'use strict';
2-
var path = require('path');
1+
"use strict";
2+
var fs = require('fs');
33
var Type = require('../../actions/actionTypes');
4-
var loader_1 = require('./loader');
54
function taskTestsReducer(taskTests, action) {
65
if (taskTests === void 0) { taskTests = ''; }
76
switch (action.type) {
87
case Type.SET_PAGE:
9-
var target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, "_tmpTests" + window.coderoad.suffix);
10-
loader_1.default(target, action.payload.taskTests);
11-
return target;
8+
var tests_1 = '';
9+
action.payload.taskTests.forEach(function (file) {
10+
try {
11+
var data = fs.readFileSync(file, 'utf8');
12+
tests_1 += data + '\n';
13+
}
14+
catch (e) {
15+
console.log('Error reading test file', e);
16+
}
17+
});
18+
return tests_1;
1219
default:
1320
return taskTests;
1421
}

lib/services/setGlobals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var exists_1 = require('./exists');
44
function setGlobals(config) {
55
window.coderoad = Object.assign(window.coderoad, {
66
tutorial: config.name,
7-
suffix: config.config.testSuffix.substring(config.config.testSuffix.lastIndexOf('.'), config.config.testSuffix.length),
7+
suffix: config.config.testSuffix.substring(config.config.testSuffix.lastIndexOf('.') + 1, config.config.testSuffix.length),
88
tutorialDir: path.join(window.coderoad.dir, 'node_modules', config.name, config.config.testDir),
99
testRunner: config.config.testRunner,
1010
testRunnerOptions: config.config.testRunnerOptions || {}

src/reducers/run-tests/run.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ import * as fs from 'fs';
44
import * as path from 'path';
55
import parseLoaders from './parse-loaders';
66

7-
// TODO: use memcache for test files instead of read/writes
8-
97
export function runTaskTests(setup?: boolean): boolean {
10-
const testFile: string = store.getState().taskTests;
8+
const tests: string = store.getState().taskTests;
119

12-
if (testFile) {
10+
if (tests && tests.length) {
1311
let config = window.coderoad;
1412
config.taskPosition = store.getState().taskPosition;
13+
let output = parseLoaders(tests, window.coderoad.suffix);
1514

16-
let fileType: string = testFile.substr(testFile.lastIndexOf('.') + 1, testFile.length) || null;
17-
let tests = fs.readFileSync(testFile, 'utf8');
18-
let output = parseLoaders(tests, fileType);
19-
20-
let target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, `_tmp${window.coderoad.suffix}`);
15+
// write temporary test file in tutorial directory
16+
let target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, `_tmp.${window.coderoad.suffix}`);
2117
fs.writeFileSync(target, output, 'utf8');
2218

2319
// call test runner

src/reducers/task-tests/concat-tests.ts

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

src/reducers/task-tests/task-tests.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ import concatTests from './concat-tests';
66
export default function taskTestsReducer(taskTests = '', action: CR.Action): string {
77
switch (action.type) {
88
case Type.SET_PAGE:
9-
let target = path.join(window.coderoad.tutorialDir || window.coderoad.dir, `_tmpTests${window.coderoad.suffix}`);
10-
concatTests(target, action.payload.taskTests);
11-
return target;
9+
let tests = '';
10+
action.payload.taskTests.forEach(function(file: string) {
11+
try {
12+
let data = fs.readFileSync(file, 'utf8');
13+
tests += data + '\n';
14+
} catch (e) {
15+
console.log('Error reading test file', e);
16+
}
17+
});
18+
return tests;
1219
default:
1320
return taskTests;
1421
}

src/services/setGlobals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {fileExists} from './exists';
44
export function setGlobals(config: PackageJson) {
55
window.coderoad = Object.assign(window.coderoad, {
66
tutorial: config.name,
7-
suffix: config.config.testSuffix.substring(config.config.testSuffix.lastIndexOf('.'), config.config.testSuffix.length),
7+
suffix: config.config.testSuffix.substring(config.config.testSuffix.lastIndexOf('.') + 1, config.config.testSuffix.length),
88
tutorialDir: path.join(window.coderoad.dir, 'node_modules', config.name, config.config.testDir),
99
testRunner: config.config.testRunner,
1010
testRunnerOptions: config.config.testRunnerOptions || {}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
"src/reducers/run-tests/run.ts",
8585
"src/reducers/run-tests/test-result.ts",
8686
"src/reducers/task-position/task-position.ts",
87-
"src/reducers/task-tests/concat-tests.ts",
8887
"src/reducers/task-tests/task-tests.ts",
8988
"src/reducers/tasks/tasks.ts",
9089
"src/reducers/tutorials/tutorials.ts",

0 commit comments

Comments
 (0)