Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit3db0e16

Browse files
committed
improved comments in setup and tests
1 parente7a4b94 commit3db0e16

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
returntrue;
3535
}
36-
functionminVersion(command,minVersion){
36+
functionminVersion(command){
37+
varminVersion=versions[command];
3738
returnnewPromise(function(resolve,reject){
3839
varminOrLater=atom_plugin_command_line_1.default(command,'-v')
3940
.then(function(res){returnisAboveVersion(res,minVersion);});
@@ -45,6 +46,7 @@ function minVersion(command, minVersion) {
4546
}
4647
});
4748
}
49+
exports.minVersion=minVersion;
4850
functionatomMinVersion(){
4951
returnnewPromise(function(resolve,reject){
5052
varminOrLater=atom_plugin_command_line_1.default('atom','-v').then(function(res){
@@ -59,14 +61,6 @@ function atomMinVersion() {
5961
});
6062
}
6163
exports.atomMinVersion=atomMinVersion;
62-
functionnpmMinVersion(){
63-
returnminVersion('npm',versions.npm);
64-
}
65-
exports.npmMinVersion=npmMinVersion;
66-
functionnodeMinVersion(){
67-
returnminVersion('node',versions.node);
68-
}
69-
exports.nodeMinVersion=nodeMinVersion;
7064
functionrequiresXCode(){
7165
if(!navigator.platform.match(/Mac/)){
7266
returntrue;

‎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
varchecks={
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
importfileExistsfrom'node-file-exists';
66

7+
/**
8+
* read a file and return contents as JSON
9+
*/
710
constreadParse=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-
functionmatchVersions(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+
functionmatchVersions(v:string):string[]|null{
1016
returnv.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
functionisAboveVersion(a:string,b:string):boolean{
1426
if(a===b){returntrue;}
1527
consta_components=a.split('.');
@@ -26,7 +38,14 @@ function isAboveVersion(a: string, b: string): boolean {
2638
returntrue;
2739
}
2840

29-
functionminVersion(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+
exportfunctionminVersion(command:string):Promise<boolean>{
48+
constminVersion=versions[command];
3049
returnnewPromise((resolve,reject)=>{
3150
letminOrLater: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
exportfunctionatomMinVersion():Promise<boolean>{
4265
returnnewPromise((resolve,reject)=>{
4366
letminOrLater=commandLine('atom','-v').then((res:string)=>{
@@ -51,14 +74,6 @@ export function atomMinVersion(): Promise<boolean> {
5174
});
5275
}
5376

54-
exportfunctionnpmMinVersion():Promise<boolean>{
55-
returnminVersion('npm',versions.npm);
56-
}
57-
58-
exportfunctionnodeMinVersion():Promise<boolean>{
59-
returnminVersion('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
letchecks: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
exportdefaultfunctiontaskPosition(
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+
importreducerfrom'./index';
4+
5+
describe('task position reducer',()=>{
6+
7+
it('should do nothing if no triggered action type',()=>{
8+
constaction={type:'unknown'};
9+
expect(reducer(undefined,action)).toBe(0);
10+
});
11+
12+
it('should reset to 0 on PAGE_SET',()=>{
13+
constaction={type:'PAGE_SET'};
14+
expect(reducer(2,action)).toBe(0);
15+
});
16+
17+
it('should set the task position on TEST_RESULT',()=>{
18+
constaction={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
importstorefrom'../../../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
exportdefaultfunctionhandleResult(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
exportdefaultfunctionrunTest(
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
exportdefaultfunctionloadTaskTests({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
consttests=[].concat.apply([],tasks.map(
717
task=>task.tests||[]
@@ -17,5 +27,7 @@ export default function loadTaskTests({dir, tasks, load, testFile}) {
1727
returnoutput;
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
importhandleResultfrom'./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
exportdefaultfunctionrunTaskTests({
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
consttwoDigitify=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
exportdefaultfunctiongetTestName({tutorial, pagePosition}):string{
415
if(!tutorial||!tutorial.name||!tutorial.version||typeofpagePosition!=='number'){
516
console.log('Error creating temporary test name');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp