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

Commit22017a5

Browse files
committed
create first test and lib dir
1 parented2181f commit22017a5

File tree

22 files changed

+386
-11
lines changed

22 files changed

+386
-11
lines changed

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode
33

44
node_modules
5+
.tmp

‎README.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
#Jest CodeRoad (WIP)
22

33
[Atom-CodeRoad](https://github.com/coderoad/atom-coderoad) Javascript test runner & reporter.
4-
5-
6-

‎lib/constants.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
exports.signal='@@@CodeRoad Results@@@';
3+
exports.runnerPath=['jest','bin','jest.js'];
4+
exports.runnerOptions=[
5+
'--bail',
6+
'--notify'
7+
];

‎lib/index.js‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"use strict";
2+
varwriteTests_1=require('./writeTests');
3+
varrunner_1=require('./runner');
4+
vartestPath_1=require('./testPath');
5+
functionload(_a){
6+
vardir=_a.dir,testFile=_a.testFile,tests=_a.tests;
7+
writeTests_1.default({
8+
dir:dir,
9+
tests:tests,
10+
testPath:testPath_1.default(testFile),
11+
});
12+
}
13+
exports.load=load;
14+
;
15+
functionrun(_a){
16+
vardir=_a.dir,taskPosition=_a.taskPosition,handleResult=_a.handleResult,testFile=_a.testFile;
17+
runner_1.default({
18+
dir:dir,
19+
taskPosition:taskPosition,
20+
handleResult:handleResult,
21+
testPath:testPath_1.default(testFile),
22+
});
23+
}
24+
exports.run=run;

‎lib/reporter/index.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use strict";
2+
varconstants_1=require('../constants');
3+
exports=module.exports=reporter;
4+
functionreporter(runner){
5+
varresult={
6+
passes:[],
7+
failures:[],
8+
pass:true,
9+
};
10+
runner.on('pass',function(test){
11+
varindex=getIndexAndTitle(test.fullTitle()).index;
12+
result.passes.push({
13+
msg:"Task "+index+" Complete",
14+
taskPosition:index,
15+
});
16+
});
17+
runner.on('fail',function(test,err){
18+
var_a=getIndexAndTitle(test.fullTitle()),msg=_a.msg,index=_a.index;
19+
result.failures.push({
20+
msg:msg,
21+
taskPosition:index-1,
22+
timedOut:test.timedOut,
23+
});
24+
result.pass=false;
25+
});
26+
runner.on('end',function(){
27+
process.stdout.write(constants_1.signal+JSON.stringify(result,null,2));
28+
});
29+
}
30+
functiongetIndexAndTitle(title){
31+
varindexString=title.match(/^[0-9]+/);
32+
if(!indexString){
33+
throw'Tests should begin with a number, indicating the task number';
34+
}
35+
return{
36+
index:parseInt(indexString[0],10),
37+
msg:title.slice(indexString[0].length+1),
38+
};
39+
}

‎lib/runner/index.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use strict";
2+
varstart_runner_1=require('./start-runner');
3+
varrunner_process_1=require('./runner-process');
4+
varisWindows=window.navigator.appVersion.indexOf('Win')>-1;
5+
functionrunner(_a){
6+
vardir=_a.dir,taskPosition=_a.taskPosition,handleResult=_a.handleResult,testPath=_a.testPath;
7+
if(isWindows){
8+
testPath=testPath.split('\\').join('\\\\');
9+
testPath=testPath.split('/').join('\\\\');
10+
}
11+
varrunner=runner_process_1.default({dir:dir,taskPosition:taskPosition,testPath:testPath});
12+
returnstart_runner_1.default({runner:runner,handleResult:handleResult,taskPosition:taskPosition});
13+
}
14+
Object.defineProperty(exports,"__esModule",{value:true});
15+
exports.default=runner;

‎lib/runner/paths/node.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
functiongetNode(){
4+
if(process.platform==='darwin'&&process.resourcesPath){
5+
returnpath_1.join(process.resourcesPath,'..','Frameworks','Atom Helper.app','Contents','MacOS','Atom Helper');
6+
}
7+
elseif(process.platform.match(/win/)){
8+
return'node';
9+
}
10+
returnprocess.execPath;
11+
}
12+
Object.defineProperty(exports,"__esModule",{value:true});
13+
exports.default=getNode;

‎lib/runner/paths/runner.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
varnode_file_exists_1=require('node-file-exists');
3+
varpath_1=require('path');
4+
varconstants_1=require('../../constants');
5+
varnestedPath=[__dirname,'..','..','..','..'].concat(constants_1.runnerPath);
6+
varflattenedPath=[__dirname,'..','..','..','node_modules'].concat(constants_1.runnerPath);
7+
functiongetRunner(){
8+
varnested=path_1.join.apply(this,nestedPath);
9+
varflattened=path_1.join.apply(this,flattenedPath);
10+
console.log('nested: ',nested,'flattened: ',flattened);
11+
if(node_file_exists_1.default(nested)){
12+
returnnested;
13+
}
14+
elseif(node_file_exists_1.default(flattened)){
15+
returnflattened;
16+
}
17+
thrownewError('Error finding test runner.');
18+
}
19+
Object.defineProperty(exports,"__esModule",{value:true});
20+
exports.default=getRunner;

‎lib/runner/runner-process.js‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varchild_process_1=require('child_process');
4+
varrunner_1=require('./paths/runner');
5+
varnode_1=require('./paths/node');
6+
varconstants_1=require('../constants');
7+
varreporterPath=path_1.join(__dirname,'..','reporter','index.js');
8+
varnode=node_1.default();
9+
varrunner=runner_1.default();
10+
functionspawnRunnerProcess(_a){
11+
vardir=_a.dir,taskPosition=_a.taskPosition,testPath=_a.testPath;
12+
varoptions={
13+
cwd:dir
14+
};
15+
if(options.env==null){
16+
options.env=Object.create(process.env);
17+
}
18+
Object.assign(options.env,{
19+
ATOM_SHELL_INTERNAL_RUN_AS_NODE:1,
20+
DIR:dir,
21+
TASK_POSITION:taskPosition,
22+
NODE_PATH:path_1.join(dir,'node_modules'),
23+
});
24+
returnchild_process_1.spawn(node,[
25+
runner,
26+
("--reporter="+reporterPath)
27+
]
28+
.concat(constants_1.runnerOptions)
29+
.concat(testPath),options);
30+
}
31+
Object.defineProperty(exports,"__esModule",{value:true});
32+
exports.default=spawnRunnerProcess;

‎lib/runner/start-runner.js‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
varprocess_console_log_1=require('process-console-log');
3+
varconstants_1=require('../constants');
4+
varsignalMatch=newRegExp(constants_1.signal);
5+
functionstartRunner(_a){
6+
varrunner=_a.runner,handleResult=_a.handleResult,taskPosition=_a.taskPosition;
7+
varfinal=null;
8+
newPromise(functionrun(resolve,reject){
9+
runner.stdout.on('data',functiononData(data){
10+
data=data.toString();
11+
varmatch=signalMatch.exec(data);
12+
if(!match){
13+
try{
14+
process_console_log_1.parseLog(data);
15+
}
16+
catch(e){
17+
process_console_log_1.parseLog(data);
18+
}
19+
return;
20+
}
21+
varresultString=data.substring(match.index+constants_1.signal.length);
22+
varresult=JSON.parse(JSON.stringify(resultString));
23+
if(typeofresult==='string'){
24+
result=JSON.parse(result);
25+
}
26+
switch(result.pass){
27+
casetrue:
28+
final=result.passes[result.passes.length-1];
29+
break;
30+
casefalse:
31+
final=result.failures[0];
32+
break;
33+
default:
34+
console.log('error processing result: ',result);
35+
}
36+
final.change=final.taskPosition-taskPosition;
37+
final.pass=final.change>0;
38+
final.completed=result.pass;
39+
handleResult(final);
40+
});
41+
runner.stderr.on('data',functiononError(data){
42+
console.log('test error',data.toString());
43+
});
44+
runner.on('close',functiononClose(code){
45+
resolve(final);
46+
});
47+
});
48+
}
49+
Object.defineProperty(exports,"__esModule",{value:true});
50+
exports.default=startRunner;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp