Skip to content

Commit 09a0c59

Browse files
committed
improved error handling & messages
1 parent 1dfee83 commit 09a0c59

File tree

9 files changed

+45
-59
lines changed

9 files changed

+45
-59
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ src
22
tsconfig.json
33
tsd.json
44
tslint.json
5+
.gitattributes

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ function concatTests(targetFile, files) {
44
if (fs.existsSync(targetFile)) {
55
fs.unlink(targetFile);
66
}
7-
files.forEach(function (tests) {
8-
if (typeof tests === 'string') {
9-
readAppend(targetFile, tests);
10-
}
11-
else if (Object.prototype.toString.call(tests) === '[object Array]') {
12-
tests.forEach(function (test) {
13-
readAppend(targetFile, test);
14-
});
7+
files.forEach(function (test) {
8+
if (typeof test === 'string') {
9+
readAppend(targetFile, test);
1510
}
1611
});
1712
return targetFile;

lib/services/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var PackageService = (function () {
4646
if (task.tests) {
4747
task.tests = task.tests.map(function (tests) {
4848
if (_.isString(tests)) {
49-
return [].concat(configTestString(config, _this.packageName, tests));
49+
return configTestString(config, _this.packageName, tests);
5050
}
5151
else {
5252
console.error('Invalid task test', tests);

lib/services/setGlobals.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function loadRunnerDep(config) {
3030
console.log(message);
3131
throw message;
3232
}
33+
var slash = navigator.appVersion.indexOf('Win') !== -1 ? '\\' : '/';
34+
runnerMain = path.join.apply(null, runnerMain.split(slash));
3335
runnerRoot = runnerRoot.substring(0, runnerRoot.lastIndexOf('/'));
3436
var pathToMain = path.join(runnerRoot, runnerMain);
3537
if (!!require(pathToMain).default) {

src/reducers/alert/alert.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,30 @@ export default function alertReducer(alert = defaultAlert, action: CR.Action): C
2626
if (result.pass && result.change > 0) {
2727
// Pass
2828
statusBarAlert.style.color = '#73C990';
29-
current = {
29+
return {
3030
message: result.msg,
3131
open: true,
3232
action: 'pass',
3333
duration: result.duration || 1500
3434
};
35-
return current;
3635
} else if (result.pass === false && result.change < 1) {
3736
// Fail
3837
statusBarAlert.style.color = '#FF4081';
39-
current = {
38+
return {
4039
message: result.msg,
4140
open: true,
4241
action: 'fail',
4342
duration: result.duration || 2500
4443
};
45-
return current;
4644
}
4745
// Alert
4846
statusBarAlert.style.color = '#9DA5B4';
49-
current = {
47+
return {
5048
message: result.msg,
5149
open: true,
5250
action: 'note',
5351
duration: result.duration || 2500
5452
};
55-
return current;
5653
case Type.PAGE_COMPLETE:
5754
return {
5855
message: `Page ${action.payload.position.page + 1} Complete`,

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,15 @@ export function concatTests(targetFile: string, files: any): string {
77
}
88

99
// load tests in order
10-
files.forEach(function(tests) {
11-
// path to file
12-
if (typeof tests === 'string') {
13-
readAppend(targetFile, tests);
14-
15-
// array of paths to file
16-
} else if (Object.prototype.toString.call(tests) === '[object Array]') {
17-
tests.forEach(function(test) {
18-
readAppend(targetFile, test);
19-
});
20-
}
21-
});
10+
files.forEach((test: string) => readAppend(targetFile, test));
2211
return targetFile;
2312
}
2413

2514
function readAppend(targetFile: string, file: string): void {
2615
try {
2716
let data = fs.readFileSync(file, 'utf8');
2817
fs.appendFileSync(targetFile, data, 'utf8');
18+
return;
2919
} catch (e) {
3020
console.log('Error reading test file', e);
3121
}

src/services/package.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ class PackageService {
4545
let config = this.config.config;
4646
return !tasks ? [] : tasks.map((task: CR.Task) => {
4747
if (task.tests) {
48-
task.tests = task.tests.map((tests: string) => {
49-
if (_.isString(tests)) {
50-
return [].concat(configTestString(config, this.packageName, tests));
48+
task.tests = task.tests.map((test: string) => {
49+
// add unique string to tests
50+
if (_.isString(test) && task.tests.indexOf(test) === -1) {
51+
return configTestString(config, this.packageName, test);
5152
} else {
52-
console.error('Invalid task test', tests);
53+
console.error('Invalid task test', test);
5354
}
5455
});
5556
}

src/services/setup-checks.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export function verifySetupComplete() {
99
hasDirectory()
1010
.then(hasPackageJson)
1111
.then(hasTutorialDep)
12-
.then(hasTestRunner)
1312
.then(() => {
1413
store.dispatch(Action.setupWarning(null));
1514
store.dispatch(Action.loadTutorials());
@@ -73,23 +72,6 @@ function hasTutorialDep(): Promise<CR.SetupWarning> {
7372
});
7473
}
7574

76-
// 4
77-
function hasTestRunner(): Promise<CR.SetupWarning> {
78-
return new Promise((resolve, reject) => {
79-
const hasTestRunner = true;
80-
if (!hasTestRunner) {
81-
reject({
82-
key: 'noTestRunner',
83-
title: 'Error with Tutorial',
84-
click: null,
85-
text: 'no test runner found'
86-
});
87-
}
88-
resolve();
89-
});
90-
}
91-
92-
9375
function _hasKeys(obj: Object): boolean {
9476
return Object.keys(obj).length > 0;
9577
}

src/services/tutorials.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as path from 'path';
33
import * as fs from 'fs';
44
import {fileExists} from '../services/exists';
55

6+
let tutorialError = 'This is an error with the tutorial itself';
7+
68
export function packageJsonExists(): boolean {
79
const pathToPackageJson = path.join(window.coderoad.dir, 'package.json');
810
return fileExists(pathToPackageJson);
@@ -17,18 +19,34 @@ export function loadRootPackageJson(): PackageJson {
1719
}
1820

1921
function _isTutorial(name: string): boolean {
22+
// has package.json
2023
let pathToTutorialPackageJson = path.join(window.coderoad.dir, 'node_modules', name, 'package.json');
21-
if (fileExists(pathToTutorialPackageJson)) {
22-
// has package.json
23-
let packageJson = JSON.parse(fs.readFileSync(pathToTutorialPackageJson, 'utf8'));
24-
// main path to coderoad.json
25-
if (packageJson.main && packageJson.main.match(/coderoad.json$/)) {
26-
let pathToCoderoadJson = path.join(window.coderoad.dir, 'node_modules', name, packageJson.main);
27-
// coderoad.json file exists
28-
return fileExists(pathToCoderoadJson);
29-
}
24+
if (!fileExists(pathToTutorialPackageJson)) {
25+
console.log(`Error with ${name}: no package.json file found. ${tutorialError}`);
26+
return false;
27+
}
28+
// main path to coderoad.json
29+
let packageJson = JSON.parse(fs.readFileSync(pathToTutorialPackageJson, 'utf8'));
30+
if (!packageJson.main && packageJson.main.match(/coderoad.json$/)) {
31+
console.log(`Error with ${name}: main does not load a coderoad.json file. ${tutorialError}`);
32+
return false;
33+
}
34+
// coderoad.json file exists
35+
let pathToCoderoadJson = path.join(window.coderoad.dir, 'node_modules', name, packageJson.main);
36+
if (!fileExists(pathToCoderoadJson)) {
37+
console.log(`Error with ${name}: no coderoad.json file. ${tutorialError}`);
38+
return false;
39+
};
40+
if (!packageJson.config || !packageJson.config.testRunner) {
41+
console.log(`Error with ${name}: no test runner specified. ${tutorialError}`);
42+
return false;
43+
}
44+
let pathToTestRunner = path.join(window.coderoad.dir, 'node_modules', packageJson.config.testRunner);
45+
if (!fileExists(pathToTestRunner)) {
46+
console.log(`Error with ${name}: ${packageJson.config.testRunner} test runner not installed`);
47+
return false;
3048
}
31-
return false;
49+
return true;
3250
}
3351

3452
export function searchForTutorials(deps: Object): string[] {

0 commit comments

Comments
 (0)