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

Commit00a6941

Browse files
committed
init
0 parents  commit00a6941

37 files changed

+3376
-0
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

‎CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to[Semantic Versioning](http://semver.org/).
4+
5+
##[0.1.0] - 2016-08-14
6+
- created

‎README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#JS CodeRoad
2+
3+
JavaScript features bundled for[CodeRoad](https://coderoad.github.io) test runners.
4+
5+
##Features
6+
- handles`import`'s and`export`'s
7+
- overrides`console.log` to return correct types
8+
-`exists` function for testing folders and files
9+
-`BASE` paths get replaced with user directory file paths
10+
- provides easy testing of globals

‎lib/constants.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@@@';

‎lib/helpers/babelModules.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
Object.defineProperty(exports,"__esModule",{value:true});
3+
exports.default="require('babel-core/register')({plugins: [['transform-es2015-modules-commonjs',{loose:true}]]});";

‎lib/helpers/fileExists.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
functionfileExistsPolyfill(dir){
3+
return"function _fileExists(e,r){void 0===r&&(r=!0);try{accessSync(e,F_OK)}catch(c){if(c)return r||console.log(c),!1}return!0}var _require=require(\"fs\"),accessSync=_require.accessSync,F_OK=_require.F_OK,_require2=require(\"path\"),resolve=_require2.resolve;function exists(p){return _fileExists(resolve('"+dir+"',p))}";
4+
}
5+
Object.defineProperty(exports,"__esModule",{value:true});
6+
exports.default=fileExistsPolyfill;

‎lib/helpers/import-paths.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varimportPathRegex=/require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
4+
varrelativePathRegex=/^BASE/;
5+
functionfixImportPaths(dir,str){
6+
varentries=newSet([]);
7+
returnstr.split('\n').map(function(line){
8+
varisMatch=line.match(importPathRegex);
9+
if(!isMatch){
10+
returnline;
11+
}
12+
varimportPath=isMatch[1]||isMatch[2];
13+
if(importPath.match(relativePathRegex)){
14+
varnewPath=path_1.join(dir,importPath.replace('BASE',''));
15+
varnewLine=line.replace(importPath,newPath);
16+
if(!entries.has(newLine)){
17+
entries.add(newLine);
18+
returnnewLine;
19+
}
20+
return'';
21+
}
22+
returnline;
23+
}).join('\n');
24+
}
25+
Object.defineProperty(exports,"__esModule",{value:true});
26+
exports.default=fixImportPaths;

‎lib/helpers/importPaths.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varimportPathRegex=/require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
4+
varrelativePathRegex=/^BASE/;
5+
functionfixImportPaths(_a){
6+
vardir=_a.dir,content=_a.content;
7+
varentries=newSet([]);
8+
returncontent.split('\n').map(function(line){
9+
varisMatch=line.match(importPathRegex);
10+
if(!isMatch){
11+
returnline;
12+
}
13+
varimportPath=isMatch[1]||isMatch[2];
14+
if(importPath.match(relativePathRegex)){
15+
varnewPath=path_1.join(dir,importPath.replace('BASE',''));
16+
varnewLine=line.replace(importPath,newPath);
17+
if(!entries.has(newLine)){
18+
entries.add(newLine);
19+
returnnewLine;
20+
}
21+
return'';
22+
}
23+
returnline;
24+
}).join('\n');
25+
}
26+
Object.defineProperty(exports,"__esModule",{value:true});
27+
exports.default=fixImportPaths;

‎lib/helpers/overrideRequire.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
Object.defineProperty(exports,"__esModule",{value:true});
3+
exports.default="require = require('rewire');";

‎lib/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use strict";
2+
varbabelModules_1=require('./helpers/babelModules');
3+
varprocess_console_log_1=require('process-console-log');
4+
varfileExists_1=require('./helpers/fileExists');
5+
varoverrideRequire_1=require('./helpers/overrideRequire');
6+
varimportPaths_1=require('./helpers/importPaths');
7+
varjsCodeRoad=function(_a){
8+
vardir=_a.dir,content=_a.content;
9+
return('(function(){\n'
10+
+process_console_log_1.logger
11+
+babelModules_1.default
12+
+fileExists_1.default(dir)
13+
+overrideRequire_1.default
14+
+importPaths_1.default({dir:dir,content:content})
15+
+'\n}());');
16+
};
17+
Object.defineProperty(exports,"__esModule",{value:true});
18+
exports.default=jsCodeRoad;

‎lib/runner/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"use strict";
2+
varstart_runner_1=require('./start-runner');
3+
varrunner_process_1=require('./runner-process');
4+
functionrunner(_a){
5+
vardir=_a.dir,taskPosition=_a.taskPosition,handleResult=_a.handleResult,testPath=_a.testPath;
6+
varrunner=runner_process_1.default({dir:dir,taskPosition:taskPosition,testPath:testPath});
7+
returnstart_runner_1.default({runner:runner,handleResult:handleResult,taskPosition:taskPosition});
8+
}
9+
Object.defineProperty(exports,"__esModule",{value:true});
10+
exports.default=runner;

‎lib/runner/paths/mocha.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
varnode_file_exists_1=require('node-file-exists');
3+
varpath_1=require('path');
4+
functiongetMocha(){
5+
varmocha=path_1.join(__dirname,'..','..','..','..','mocha','bin','mocha');
6+
if(!node_file_exists_1.default(mocha)){
7+
mocha=path_1.join(__dirname,'..','..','..','node_modules','mocha','bin','mocha');
8+
if(!node_file_exists_1.default(mocha)){
9+
varerror='Error finding mocha';
10+
throw(error);
11+
}
12+
}
13+
returnmocha;
14+
}
15+
Object.defineProperty(exports,"__esModule",{value:true});
16+
exports.default=getMocha;

‎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.resolve(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/runner-process.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varchild_process_1=require('child_process');
4+
varmocha_1=require('./paths/mocha');
5+
varnode_1=require('./paths/node');
6+
varreporterPath=path_1.join(__dirname,'..','reporter','index.js');
7+
varnode=node_1.default();
8+
varmocha=mocha_1.default();
9+
functionspawnRunnerProcess(_a){
10+
vardir=_a.dir,taskPosition=_a.taskPosition,testPath=_a.testPath;
11+
varoptions={
12+
cwd:dir
13+
};
14+
if(options.env==null){
15+
options.env=Object.create(process.env);
16+
}
17+
Object.assign(options.env,{
18+
ATOM_SHELL_INTERNAL_RUN_AS_NODE:1,
19+
DIR:dir,
20+
TASK_POSITION:taskPosition,
21+
NODE_PATH:path_1.join(dir,'node_modules'),
22+
});
23+
returnchild_process_1.spawn(node,[
24+
mocha,
25+
'--bail',
26+
'--harmony',
27+
'--no-colors',
28+
'--timeout=3000',
29+
'--compilers js:babel-core/register',
30+
("--reporter="+reporterPath),
31+
testPath,
32+
],options);
33+
}
34+
Object.defineProperty(exports,"__esModule",{value:true});
35+
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;

‎lib/testPath.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
functiontmpTestName(testFile){
4+
returnpath_1.resolve(__dirname,'..','.tmp',testFile+'.js');
5+
}
6+
Object.defineProperty(exports,"__esModule",{value:true});
7+
exports.default=tmpTestName;

‎lib/writeTests/helpers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
functionhelpers(projectDir){
3+
return"\n// run time compiler\nrequire('babel-core/register')({plugins: [['transform-es2015-modules-commonjs',{\nloose:true}]]});\n\n// fileExists test helper\nfunction fileExists(e,r){void 0===r&&(r=!0);try{accessSync(e,F_OK)}catch(c){if(c)return r||console.log(c),!1}return!0}var _require=require(\"fs\"),accessSync=_require.accessSync,F_OK=_require.F_OK,_require2=require(\"path\"),resolve=_require2.resolve;function exists(p){return fileExists(resolve('"+projectDir+"',p))}\n\n// overwrite require to catch globals in tests\nrequire = require('rewire');\n\n";
4+
}
5+
Object.defineProperty(exports,"__esModule",{value:true});
6+
exports.default=helpers;

‎lib/writeTests/import-paths.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varimportPathRegex=/require\(["'](BASE.+)["']\)([a-zA-Z0-9\-\_]+)?|^import.+?\s?["'](BASE.+)["'];?$/m;
4+
varrelativePathRegex=/^BASE/;
5+
functionfixImportPaths(dir,str){
6+
varentries=newSet([]);
7+
returnstr.split('\n').map(function(line){
8+
varisMatch=line.match(importPathRegex);
9+
if(!isMatch){
10+
returnline;
11+
}
12+
varimportPath=isMatch[1]||isMatch[2];
13+
if(importPath.match(relativePathRegex)){
14+
varnewPath=path_1.join(dir,importPath.replace('BASE',''));
15+
varnewLine=line.replace(importPath,newPath);
16+
if(!entries.has(newLine)){
17+
entries.add(newLine);
18+
returnnewLine;
19+
}
20+
return'';
21+
}
22+
returnline;
23+
}).join('\n');
24+
}
25+
Object.defineProperty(exports,"__esModule",{value:true});
26+
exports.default=fixImportPaths;

‎lib/writeTests/index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
varfs=require('fs');
3+
varpath_1=require('path');
4+
varprocess_console_log_1=require('process-console-log');
5+
varimport_paths_1=require('./import-paths');
6+
varhelpers_1=require('./helpers');
7+
vartmpPath=path_1.join(__dirname,'..','..','.tmp');
8+
functionwriteTest(_a){
9+
vardir=_a.dir,tests=_a.tests,testPath=_a.testPath;
10+
varoutput="(function(){\n"
11+
.concat(process_console_log_1.logger)
12+
.concat(helpers_1.default(dir))
13+
.concat(import_paths_1.default(dir,tests))
14+
.concat('\n}());');
15+
writeTestFile(testPath,output);
16+
}
17+
Object.defineProperty(exports,"__esModule",{value:true});
18+
exports.default=writeTest;
19+
functionwriteTestFile(testPath,output){
20+
if(!fs.existsSync(tmpPath)){
21+
fs.mkdirSync(tmpPath);
22+
}
23+
returnnewPromise(function(resolve,reject){
24+
fs.writeFile(testPath,output,function(err){
25+
if(err){
26+
reject(err);
27+
}
28+
resolve();
29+
});
30+
});
31+
}

‎package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name":"js-coderoad",
3+
"version":"0.1.0",
4+
"description":"bundled javascript features for coderoad test runners",
5+
"keywords": [
6+
"coderoad",
7+
"mocha",
8+
"javascript",
9+
"js"
10+
],
11+
"homepage":"https://github.com/coderoad/js-coderoad#readme",
12+
"bugs": {
13+
"url":"https://github.com/coderoad/js-coderoad/issues"
14+
},
15+
"license":"ISC",
16+
"author":"Shawn McKay <shawn.j.mckay@gmail.com>",
17+
"files": [
18+
"lib",
19+
"package.json",
20+
"*.md"
21+
],
22+
"main":"lib/index.js",
23+
"repository": {
24+
"type":"git",
25+
"url":"git+https://github.com/coderoad/js-coderoad.git"
26+
},
27+
"scripts": {
28+
"test":"echo\"Error: no test specified\" && exit 1"
29+
},
30+
"dependencies": {
31+
"babel-plugin-transform-es2015-modules-commonjs":"6.11.5",
32+
"babel-register":"6.11.6",
33+
"node-file-exists":"1.1.0",
34+
"process-console-log":"0.2.3",
35+
"rewire-coderoad":"3.1.1"
36+
}
37+
}

‎src/helpers/babelModules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// babel with es2015 import/export
2+
exportdefault`require('babel-core/register')({plugins: [['transform-es2015-modules-commonjs',{loose:true}]]});`;

‎src/helpers/fileExists.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// exists(path/to/file) - relative to project directory
2+
exportdefaultfunctionfileExistsPolyfill(dir:string):string{
3+
return`function _fileExists(e,r){void 0===r&&(r=!0);try{accessSync(e,F_OK)}catch(c){if(c)return r||console.log(c),!1}return!0}var _require=require("fs"),accessSync=_require.accessSync,F_OK=_require.F_OK,_require2=require("path"),resolve=_require2.resolve;function exists(p){return _fileExists(resolve('${dir}',p))}`;
4+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp