Skip to content

Commit 3db0e16

Browse files
committed
improved comments in setup and tests
1 parent e7a4b94 commit 3db0e16

File tree

12 files changed

+107
-25
lines changed

12 files changed

+107
-25
lines changed

lib/modules/setup/utils/check-system.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ function isAboveVersion(a, b) {
3333
}
3434
return true;
3535
}
36-
function minVersion(command, minVersion) {
36+
function minVersion(command) {
37+
var minVersion = versions[command];
3738
return new Promise(function (resolve, reject) {
3839
var minOrLater = atom_plugin_command_line_1.default(command, '-v')
3940
.then(function (res) { return isAboveVersion(res, minVersion); });
@@ -45,6 +46,7 @@ function minVersion(command, minVersion) {
4546
}
4647
});
4748
}
49+
exports.minVersion = minVersion;
4850
function atomMinVersion() {
4951
return new Promise(function (resolve, reject) {
5052
var minOrLater = atom_plugin_command_line_1.default('atom', '-v').then(function (res) {
@@ -59,14 +61,6 @@ function atomMinVersion() {
5961
});
6062
}
6163
exports.atomMinVersion = atomMinVersion;
62-
function npmMinVersion() {
63-
return minVersion('npm', versions.npm);
64-
}
65-
exports.npmMinVersion = npmMinVersion;
66-
function nodeMinVersion() {
67-
return minVersion('node', versions.node);
68-
}
69-
exports.nodeMinVersion = nodeMinVersion;
7064
function requiresXCode() {
7165
if (!navigator.platform.match(/Mac/)) {
7266
return true;

lib/modules/setup/utils/verify.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function setupVerify(dir, packageJson) {
1616
}
1717
var checks = {
1818
system: {
19-
node: !!check_system_1.nodeMinVersion(),
20-
npm: !!check_system_1.npmMinVersion(),
19+
node: !!check_system_1.minVersion('node'),
20+
npm: !!check_system_1.minVersion('npm'),
2121
xcode: !!check_system_1.requiresXCode(),
2222
atom: !!check_system_1.atomMinVersion(),
2323
},

src/modules/setup/package-json/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { join } from 'path';
44
import { SETUP_PACKAGE } from '../types';
55
import fileExists from 'node-file-exists';
66

7+
/**
8+
* read a file and return contents as JSON
9+
*/
710
const readParse = p => JSON.parse(readFileSync(p, 'utf8'));
811

912
/**

src/modules/setup/utils/check-system.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ const versions = {
66
npm: '3.0.0'
77
};
88

9-
function matchVersions(v: string): string[] {
9+
/**
10+
* extracts versions intro array from a string
11+
* "0.1.0" -> ['0', '1', '0']
12+
* or returns null
13+
* @param {string} v
14+
*/
15+
function matchVersions(v: string): string[]|null {
1016
return v.match(/([0-9]+)\.([0-9]+)/);
1117
}
1218

19+
/**
20+
* checks that a version is >= b version
21+
* @param {string} a
22+
* @param {string} b
23+
* @returns boolean
24+
*/
1325
function isAboveVersion(a: string, b: string): boolean {
1426
if (a === b) { return true; }
1527
const a_components = a.split('.');
@@ -26,7 +38,14 @@ function isAboveVersion(a: string, b: string): boolean {
2638
return true;
2739
}
2840

29-
function minVersion(command: string, minVersion: string): Promise<boolean> {
41+
/**
42+
* calls command line to check that system version is above requirement
43+
* @param {string} command
44+
* @param {string} minVersion
45+
* @returns Promise
46+
*/
47+
export function minVersion(command: string): Promise<boolean> {
48+
const minVersion = versions[command];
3049
return new Promise((resolve, reject) => {
3150
let minOrLater: Promise<boolean> = commandLine(command, '-v')
3251
.then((res: string) => isAboveVersion(res, minVersion));
@@ -38,6 +57,10 @@ function minVersion(command: string, minVersion: string): Promise<boolean> {
3857
});
3958
}
4059

60+
/**
61+
* checks that the version of atom is above a minimum version
62+
* @returns Promise
63+
*/
4164
export function atomMinVersion(): Promise<boolean> {
4265
return new Promise((resolve, reject) => {
4366
let minOrLater = commandLine('atom', '-v').then((res: string) => {
@@ -51,14 +74,6 @@ export function atomMinVersion(): Promise<boolean> {
5174
});
5275
}
5376

54-
export function npmMinVersion(): Promise<boolean> {
55-
return minVersion('npm', versions.npm);
56-
}
57-
58-
export function nodeMinVersion(): Promise<boolean> {
59-
return minVersion('node', versions.node);
60-
}
61-
6277
/**
6378
* checks if is a mac
6479
* checks if xcode is installed

src/modules/setup/utils/verify.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {atomMinVersion, nodeMinVersion, npmMinVersion, requiresXCode} from './check-system';
1+
import {atomMinVersion, minVersion, requiresXCode} from './check-system';
22
import {tutorials} from 'coderoad-cli';
33

44
/**
@@ -32,8 +32,8 @@ export default function setupVerify(
3232

3333
let checks: CR.Checks = {
3434
system: {
35-
node: !!nodeMinVersion(),
36-
npm: !!npmMinVersion(),
35+
node: !!minVersion('node'),
36+
npm: !!minVersion('npm'),
3737
xcode: !!requiresXCode(),
3838
atom: !!atomMinVersion(),
3939
},

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import {TEST_RESULT} from '../types';
22

3+
/**
4+
* task position reducer
5+
* @param {} taskPosition=0
6+
* @param {Action} action
7+
* @returns number
8+
*/
39
export default function taskPosition(
410
taskPosition = 0, action: Action
511
): number {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path="../../../typings/globals/jest/index.d.ts" />
2+
3+
import reducer from './index';
4+
5+
describe('task position reducer', () => {
6+
7+
it('should do nothing if no triggered action type', () => {
8+
const action = { type: 'unknown' };
9+
expect(reducer(undefined, action)).toBe(0);
10+
});
11+
12+
it('should reset to 0 on PAGE_SET', () => {
13+
const action = { type: 'PAGE_SET' };
14+
expect(reducer(2, action)).toBe(0);
15+
});
16+
17+
it('should set the task position on TEST_RESULT', () => {
18+
const action = { type: 'TEST_RESULT', payload: { result: { taskPosition: 3 } } };
19+
expect(reducer(1, action)).toBe(3);
20+
});
21+
22+
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import store from '../../../store';
22
import {testComplete} from '../actions';
33

4-
// function is passed into the test runner and called on completion
4+
/**
5+
* function is passed into the test runner and called on completion
6+
* @param {Test.Result} result
7+
* @returns void
8+
*/
59
export default function handleResult(result: Test.Result): void {
610
store.dispatch(testComplete(result));
711
};

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const defaultTestRun: IRunTest = {
1616
time: performance.now(),
1717
};
1818

19+
/**
20+
* runs unit tests
21+
* @param {} testRun=defaultTestRun
22+
* @param {Action} action
23+
* @returns IRunTest
24+
*/
1925
export default function runTest(
2026
testRun = defaultTestRun, action: Action
2127
): IRunTest {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import { readFileSync } from 'fs';
22

3+
/**
4+
* read files from paths and concat a data file together
5+
* save the test data file to the test runner .tmp directory
6+
* @param {} {dir
7+
* @param {} tasks
8+
* @param {} load
9+
* @param {} testFile}
10+
*/
311
export default function loadTaskTests({dir, tasks, load, testFile}) {
412

13+
// first read files from paths and concat data together
14+
515
// map over task tests from coderoad.json
616
const tests = [].concat.apply([], tasks.map(
717
task => task.tests || []
@@ -17,5 +27,7 @@ export default function loadTaskTests({dir, tasks, load, testFile}) {
1727
return output;
1828
}, '');
1929

30+
31+
// save the file
2032
load({dir, tests, testFile});
2133
}

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

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

3+
/**
4+
* call test runner
5+
* @param {} {hasTasks
6+
* @param {} dir
7+
* @param {} tutorial
8+
* @param {} taskPosition
9+
* @param {} testFile}
10+
* @returns number
11+
*/
312
export default function runTaskTests({
413
hasTasks, dir, tutorial, taskPosition, testFile
514
}): number {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
/**
2+
* turn a number into a two digit string
3+
* for example: 1 -> '01'
4+
*/
15
const twoDigitify = n => n > 9 ? '' + n : '0' + n;
26

7+
/**
8+
* create a file name for the compiled test file
9+
* for example: 'coderoad-functional-school__0.1.0__01'
10+
* @param {} {tutorial
11+
* @param {} pagePosition}
12+
* @returns string
13+
*/
314
export default function getTestName({tutorial, pagePosition}): string {
415
if (!tutorial || !tutorial.name || !tutorial.version || typeof pagePosition !== 'number') {
516
console.log('Error creating temporary test name');

0 commit comments

Comments
 (0)