Skip to content

Commit e0a4381

Browse files
committed
windows fix
1 parent a49135b commit e0a4381

File tree

10 files changed

+39
-47
lines changed

10 files changed

+39
-47
lines changed

lib/reducers/alert/alert.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,29 @@ function alertReducer(alert, action) {
2424
var result = action.payload.result;
2525
if (result.pass && result.change > 0) {
2626
statusBarAlert.style.color = '#73C990';
27-
current = {
27+
return {
2828
message: result.msg,
2929
open: true,
3030
action: 'pass',
3131
duration: result.duration || 1500
3232
};
33-
return current;
3433
}
3534
else if (result.pass === false && result.change < 1) {
3635
statusBarAlert.style.color = '#FF4081';
37-
current = {
36+
return {
3837
message: result.msg,
3938
open: true,
4039
action: 'fail',
4140
duration: result.duration || 2500
4241
};
43-
return current;
4442
}
4543
statusBarAlert.style.color = '#9DA5B4';
46-
current = {
44+
return {
4745
message: result.msg,
4846
open: true,
4947
action: 'note',
5048
duration: result.duration || 2500
5149
};
52-
return current;
5350
case Type.PAGE_COMPLETE:
5451
return {
5552
message: "Page " + (action.payload.position.page + 1) + " Complete",

lib/reducers/run-tests/run.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function runTaskTests(setup) {
66
if (tests && tests.length) {
77
var config = window.coderoad;
88
config.taskPosition = _base_1.store.getState().taskPosition;
9-
window.coderoad.runner(tests, config, test_result_1.handleResult, test_result_1.handleLog);
9+
window.coderoad.runner(tests, config, test_result_1.handleResult);
1010
}
1111
return true;
1212
}

lib/reducers/run-tests/test-result.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,3 @@ function handleResult(result) {
1717
}
1818
exports.handleResult = handleResult;
1919
;
20-
function handleLog(message) {
21-
console.log(message);
22-
_base_1.store.dispatch(Action.logMessage(message));
23-
}
24-
exports.handleLog = handleLog;

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ function concatTests(targetFile, files) {
44
if (fs.existsSync(targetFile)) {
55
fs.unlink(targetFile);
66
}
7-
files.forEach(function (test) {
8-
if (typeof test === 'string') {
9-
readAppend(targetFile, test);
10-
}
11-
});
7+
files.forEach(function (test) { return readAppend(targetFile, test); });
128
return targetFile;
139
}
1410
exports.concatTests = concatTests;
1511
function readAppend(targetFile, file) {
1612
try {
1713
var data = fs.readFileSync(file, 'utf8');
1814
fs.appendFileSync(targetFile, data, 'utf8');
15+
return;
1916
}
2017
catch (e) {
2118
console.log('Error reading test file', e);

lib/services/exists.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var fs = require('fs');
33
function fileExists(pathToFile) {
44
try {
5-
fs.accessSync(pathToFile, fs.R_OK | fs.W_OK);
5+
fs.accessSync(pathToFile, fs.F_OK);
66
}
77
catch (e) {
88
if (e) {

lib/services/package.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ var PackageService = (function () {
4444
var config = this.config.config;
4545
return !tasks ? [] : tasks.map(function (task) {
4646
if (task.tests) {
47-
task.tests = task.tests.map(function (tests) {
48-
if (_.isString(tests)) {
49-
return configTestString(config, _this.packageName, tests);
47+
task.tests = task.tests.map(function (test) {
48+
if (_.isString(test) && task.tests.indexOf(test) === -1) {
49+
return configTestString(config, _this.packageName, test);
5050
}
5151
else {
52-
console.error('Invalid task test', tests);
52+
console.error('Invalid task test', test);
5353
}
5454
});
5555
}

lib/services/setGlobals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function loadRunnerDep(config) {
3232
}
3333
var slash = navigator.appVersion.indexOf('Win') !== -1 ? '\\' : '/';
3434
runnerMain = path.join.apply(null, runnerMain.split(slash));
35-
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf('/'));
35+
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf(slash));
3636
var pathToMain = path.join(runnerRoot, runnerMain);
3737
if (!!require(pathToMain).default) {
3838
window.coderoad.runner = require(pathToMain).default;

lib/services/setup-checks.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function verifySetupComplete() {
77
hasDirectory()
88
.then(hasPackageJson)
99
.then(hasTutorialDep)
10-
.then(hasTestRunner)
1110
.then(function () {
1211
_base_1.store.dispatch(Action.setupWarning(null));
1312
_base_1.store.dispatch(Action.loadTutorials());
@@ -66,20 +65,6 @@ function hasTutorialDep() {
6665
resolve();
6766
});
6867
}
69-
function hasTestRunner() {
70-
return new Promise(function (resolve, reject) {
71-
var hasTestRunner = true;
72-
if (!hasTestRunner) {
73-
reject({
74-
key: 'noTestRunner',
75-
title: 'Error with Tutorial',
76-
click: null,
77-
text: 'no test runner found'
78-
});
79-
}
80-
resolve();
81-
});
82-
}
8368
function _hasKeys(obj) {
8469
return Object.keys(obj).length > 0;
8570
}

lib/services/tutorials.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var path = require('path');
33
var fs = require('fs');
44
var exists_1 = require('../services/exists');
5+
var tutorialError = 'This is an error with the tutorial itself';
56
function packageJsonExists() {
67
var pathToPackageJson = path.join(window.coderoad.dir, 'package.json');
78
return exists_1.fileExists(pathToPackageJson);
@@ -17,14 +18,31 @@ function loadRootPackageJson() {
1718
exports.loadRootPackageJson = loadRootPackageJson;
1819
function _isTutorial(name) {
1920
var pathToTutorialPackageJson = path.join(window.coderoad.dir, 'node_modules', name, 'package.json');
20-
if (exists_1.fileExists(pathToTutorialPackageJson)) {
21-
var packageJson = JSON.parse(fs.readFileSync(pathToTutorialPackageJson, 'utf8'));
22-
if (packageJson.main && packageJson.main.match(/coderoad.json$/)) {
23-
var pathToCoderoadJson = path.join(window.coderoad.dir, 'node_modules', name, packageJson.main);
24-
return exists_1.fileExists(pathToCoderoadJson);
25-
}
26-
}
27-
return false;
21+
if (!exists_1.fileExists(pathToTutorialPackageJson)) {
22+
console.log("Error with " + name + ": no package.json file found. " + tutorialError);
23+
return false;
24+
}
25+
var packageJson = JSON.parse(fs.readFileSync(pathToTutorialPackageJson, 'utf8'));
26+
if (!packageJson.main && packageJson.main.match(/coderoad.json$/)) {
27+
console.log("Error with " + name + ": main does not load a coderoad.json file. " + tutorialError);
28+
return false;
29+
}
30+
var pathToCoderoadJson = path.join(window.coderoad.dir, 'node_modules', name, packageJson.main);
31+
if (!exists_1.fileExists(pathToCoderoadJson)) {
32+
console.log("Error with " + name + ": no coderoad.json file. " + tutorialError);
33+
return false;
34+
}
35+
;
36+
if (!packageJson.config || !packageJson.config.testRunner) {
37+
console.log("Error with " + name + ": no test runner specified. " + tutorialError);
38+
return false;
39+
}
40+
var pathToTestRunner = path.join(window.coderoad.dir, 'node_modules', packageJson.config.testRunner);
41+
if (!exists_1.fileExists(pathToTestRunner)) {
42+
console.log("Error with " + name + ": " + packageJson.config.testRunner + " test runner not installed");
43+
return false;
44+
}
45+
return true;
2846
}
2947
function searchForTutorials(deps) {
3048
if (!!deps && Object.keys(deps).length > 0) {

src/services/setGlobals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function loadRunnerDep(config: PackageJson) {
3737
let slash = navigator.appVersion.indexOf('Win') !== -1 ? '\\' : '/';
3838
runnerMain = path.join.apply(null, runnerMain.split(slash));
3939
// trim root path to folder
40-
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf('/'));
40+
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf(slash));
4141

4242
let pathToMain = path.join(runnerRoot, runnerMain);
4343

0 commit comments

Comments
 (0)