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

Commit1edef30

Browse files
committed
init
0 parents  commit1edef30

File tree

10 files changed

+273
-0
lines changed

10 files changed

+273
-0
lines changed

‎.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
tslint.json
3+
src/*.js
4+
test/**/*.ts
5+
tsconfig.json
6+
typings
7+
tsd.json

‎README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Mocha CodeRoad
2+
3+
[Atom-CodeRoad](https://github.com/coderoad/atom-coderoad) test runner & reporter.
4+
5+
npm install mocha-coderoad

‎lib/create-runner.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
varpath=require('path');
3+
varspawn=require('child_process').spawn;
4+
functioncreateRunner(config,testFile){
5+
varoptions={
6+
cwd:config.dir
7+
};
8+
if(options.env==null){
9+
options.env=Object.create(process.env);
10+
}
11+
options.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE=1;
12+
options.env.DIR=config.dir;
13+
options.env.TUTORIAL_DIR=config.tutorialDir;
14+
options.env.TASK_POSITION=config.taskPosition;
15+
varnode=null;
16+
if(process.platform==='darwin'&&process.resourcesPath){
17+
node=path.resolve(process.resourcesPath,'..','Frameworks','Atom Helper.app','Contents','MacOS','Atom Helper');
18+
}
19+
else{
20+
node=process.execPath;
21+
}
22+
varava=path.join(__dirname,'..','..','ava','cli');
23+
vartapJson=path.join('..','..','tap-json','bin','tap-json');
24+
returnspawn(node,[
25+
ava,
26+
'--fail-fast',
27+
'--tap | '+tapJson,
28+
testFile
29+
],options);
30+
}
31+
exports.createRunner=createRunner;

‎lib/runner.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"use strict";
2+
varutils_1=require('./utils');
3+
varcreate_runner_1=require('./create-runner');
4+
;
5+
functionrunner(testFile,config,handleResult,handleLog){
6+
varrunner=create_runner_1.createRunner(config,testFile);
7+
varfinal=null;
8+
varsignalMatch=newRegExp(utils_1.signal);
9+
returnnewPromise(function(resolve,reject){
10+
runner.stdout.on('data',function(data){
11+
data=data.toString();
12+
varresult=JSON.parse(JSON.stringify(data));
13+
if(typeofresult==='string'){
14+
result=JSON.parse(result);
15+
}
16+
varfinish=result.asserts[result.asserts.length-1];
17+
varobj=getIndexAndTitle(finish.comment);
18+
if(result.stats.failures>0){
19+
final={
20+
msg:obj.msg,
21+
taskPosition:obj.index-1
22+
};
23+
}
24+
else{
25+
final={
26+
msg:"Task "+obj.index+" Complete",
27+
taskPosition:obj.index
28+
};
29+
}
30+
final.change=final.taskPosition-config.taskPosition;
31+
final.pass=final.change>0;
32+
handleResult(final);
33+
});
34+
runner.stderr.on('data',function(data){
35+
console.log('test error',data.toString());
36+
});
37+
runner.on('close',function(code){
38+
if(code===0){
39+
resolve(final);
40+
}
41+
else{
42+
resolve(final);
43+
}
44+
});
45+
});
46+
}
47+
Object.defineProperty(exports,"__esModule",{value:true});
48+
exports.default=runner;
49+
functiongetIndexAndTitle(title){
50+
varindexString=title.match(/^[0-9]+/);
51+
if(!indexString){
52+
throw'Tests should begin with a number, indicating the task number';
53+
}
54+
return{
55+
index:parseInt(indexString[0]),
56+
msg:title.slice(indexString[0].length+1)
57+
};
58+
}

‎lib/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.signal='@@@CodeRoad Results@@@';

‎package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name":"ava-coderoad",
3+
"version":"0.1.0",
4+
"description":"ava test runner & reporter for atom-coderoad",
5+
"main":"lib/runner.js",
6+
"scripts": {
7+
"test":"echo\"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type":"git",
11+
"url":"git+https://github.com/coderoad/ava-coderoad.git"
12+
},
13+
"files": ["lib"],
14+
"keywords": [
15+
"coderoad",
16+
"ava"
17+
],
18+
"author":"Shawn McKay <shawn.j.mckay@gmail.com>",
19+
"license":"ISC",
20+
"bugs": {
21+
"url":"https://github.com/coderoad/ava-coderoad/issues"
22+
},
23+
"homepage":"https://github.com/coderoad/ava-coderoad#readme",
24+
"dependencies": {
25+
"ava":"0.12.0",
26+
"tap-json":"0.1.1"
27+
},
28+
"devDependencies": {}
29+
}

‎src/create-runner.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import*aspathfrom'path';
2+
constspawn=require('child_process').spawn;
3+
4+
exportfunctioncreateRunner(config,testFile){
5+
// 1. node electron setup
6+
letoptions:any={
7+
cwd:config.dir
8+
};
9+
if(options.env==null){
10+
options.env=Object.create(process.env);
11+
}
12+
options.env.ATOM_SHELL_INTERNAL_RUN_AS_NODE=1;
13+
options.env.DIR=config.dir;
14+
options.env.TUTORIAL_DIR=config.tutorialDir;
15+
options.env.TASK_POSITION=config.taskPosition;
16+
17+
// 2. get absolute path to node exec
18+
letnode=null;
19+
if(process.platform==='darwin'&&process.resourcesPath){
20+
node=path.resolve(process.resourcesPath,'..','Frameworks','Atom Helper.app','Contents','MacOS','Atom Helper');
21+
}else{
22+
node=process.execPath;
23+
}
24+
25+
// let runnerOptions = []; // setRunnerOptions(config);
26+
letava=path.join(__dirname,'..','..','ava','cli');
27+
lettapJson=path.join('..','..','tap-json','bin','tap-json');
28+
29+
// 3. spawn child process calling ava test runner
30+
returnspawn(node,[
31+
// into shared node_modules directory
32+
ava,
33+
'--fail-fast',
34+
'--tap | '+tapJson,
35+
testFile
36+
],options);
37+
38+
}

‎src/runner.ts

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import{signal}from'./utils';
2+
import{createRunner}from'./create-runner';
3+
4+
interfaceResult{
5+
msg:string;
6+
taskPosition:number;
7+
pass:boolean;
8+
change:number;
9+
timedOut?:boolean;
10+
};
11+
12+
interfaceConfig{
13+
dir:string;
14+
taskPosition:number;
15+
}
16+
17+
exportdefaultfunctionrunner(testFile,config:Config,handleResult,handleLog){
18+
19+
letrunner=createRunner(config,testFile);
20+
varfinal=null;
21+
letsignalMatch=newRegExp(signal);
22+
23+
returnnewPromise((resolve,reject)=>{
24+
runner.stdout.on('data',function(data):void{
25+
26+
data=data.toString();
27+
28+
// parse only final output data
29+
// let match = signalMatch.exec(data); // 0
30+
//
31+
// if (!match) {
32+
// handleLog(data);
33+
// return;
34+
// }
35+
//
36+
// /* Result */
37+
// // transform string result into object
38+
// let resultString = data.substring(match.index + signal.length);
39+
letresult=JSON.parse(JSON.stringify(data));
40+
// // why parse twice? I don't know, but it works
41+
if(typeofresult==='string'){
42+
result=JSON.parse(result);
43+
}
44+
45+
letfinish=result.asserts[result.asserts.length-1];
46+
letobj=getIndexAndTitle(finish.comment);
47+
48+
if(result.stats.failures>0){
49+
// fail: return first failure
50+
final={
51+
msg:obj.msg,
52+
taskPosition:obj.index-1
53+
};
54+
}else{
55+
// pass
56+
final={
57+
msg:`Task${obj.index} Complete`,
58+
taskPosition:obj.index
59+
};
60+
}
61+
final.change=final.taskPosition-config.taskPosition;
62+
final.pass=final.change>0;
63+
// // return result to atom-coderoad
64+
handleResult(final);
65+
});
66+
67+
runner.stderr.on('data',function(data){
68+
console.log('test error',data.toString());
69+
});
70+
71+
runner.on('close',function(code){
72+
if(code===0){
73+
resolve(final);
74+
}else{
75+
resolve(final);
76+
}
77+
});
78+
});
79+
}
80+
81+
functiongetIndexAndTitle(title:string):{index:number,msg:string}{
82+
// tests prefixed with task number: "01 title"
83+
letindexString=title.match(/^[0-9]+/);
84+
if(!indexString){
85+
throw'Tests should begin with a number, indicating the task number';
86+
}
87+
return{
88+
index:parseInt(indexString[0]),
89+
msg:title.slice(indexString[0].length+1)
90+
};
91+
}

‎src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exportvarsignal='@@@CodeRoad Results@@@';

‎test/runner.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
importtestfrom'ava';
2+
3+
test('01 Pass',t=>{
4+
t.same(1,1);
5+
});
6+
7+
test('01 Test Pass',t=>{
8+
t.same([1,2],[1,2]);
9+
});
10+
11+
console.log('something');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp