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.

Commit26b74e6

Browse files
committed
move config paths into test load
1 parentdc04e95 commit26b74e6

File tree

15 files changed

+135
-98
lines changed

15 files changed

+135
-98
lines changed

‎lib/modules/tests/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function testLoad() {
1111
type:types_1.TEST_LOAD,payload:{
1212
dir:dir,
1313
tasks:tasks,
14-
load:tutorial.config.load,
14+
tutorial:tutorial,
1515
testFile:testFile,
1616
}
1717
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
varpath_1=require('path');
3+
varsystem_1=require('../../../polyfills/system');
4+
functionconfigPath(_a){
5+
vardir=_a.dir,tutorial=_a.tutorial,testPath=_a.testPath;
6+
if(system_1.isWindows){
7+
testPath=testPath.split('/').join('\\');
8+
}
9+
if(tutorial.config.dir){
10+
testPath=path_1.join(tutorial.config.dir,testPath);
11+
}
12+
else{
13+
testPath=path_1.join(dir,'node_modules',tutorial.name,testPath);
14+
}
15+
if(tutorial.config.testSuffix){
16+
testPath+=tutorial.config.testSuffix;
17+
}
18+
returntestPath;
19+
}
20+
Object.defineProperty(exports,"__esModule",{value:true});
21+
exports.default=configPath;

‎lib/modules/tests/test-run/load.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
"use strict";
22
varfs_1=require('fs');
3+
varconfig_path_1=require('./config-path');
34
functionloadTaskTests(_a){
4-
vardir=_a.dir,tasks=_a.tasks,load=_a.load,testFile=_a.testFile;
5+
vardir=_a.dir,tasks=_a.tasks,tutorial=_a.tutorial,testFile=_a.testFile;
56
vartests=[].concat.apply([],tasks.map(function(task){returntask.tests||[];})).reduce(function(output,file){
67
try{
7-
output+=fs_1.readFileSync(file,'utf8')+'\n';
8+
varabsoluteFilePath=config_path_1.default({
9+
dir:dir,
10+
tutorial:tutorial,
11+
testPath:file,
12+
});
13+
output+=fs_1.readFileSync(absoluteFilePath,'utf8')+'\n';
814
}
915
catch(e){
1016
console.log('Error reading test file',e);
1117
}
1218
returnoutput;
1319
},'');
14-
load({dir:dir,tests:tests,testFile:testFile});
20+
tutorial.config.load({dir:dir,tests:tests,testFile:testFile});
1521
}
1622
Object.defineProperty(exports,"__esModule",{value:true});
1723
exports.default=loadTaskTests;

‎lib/modules/tutorial/utils/config-runner.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use strict";
22
varpath_1=require('path');
3-
varsystem_1=require('./system');
3+
varsystem_1=require('../../../polyfills/system');
44
varnode_file_exists_1=require('node-file-exists');
55
functionconfigRunner(name,runner,dir){
66
varflatDep=path_1.join(dir,'node_modules',runner,'package.json');
@@ -25,8 +25,8 @@ function configRunner(name, runner, dir) {
2525
runnerRoot=runnerRoot.substring(0,runnerRoot.lastIndexOf(slash));
2626
varpathToMain=path_1.join(runnerRoot,runnerMain);
2727
return{
28-
load:require(pathToMain).load||{load:function(){returnconsole.log('invalid test loader');}},
29-
run:require(pathToMain).run||{run:function(){returnconsole.log('invalid test runner');}},
28+
load:require(pathToMain).load||{load:function(){returnconsole.log('Invalid test loader');}},
29+
run:require(pathToMain).run||{run:function(){returnconsole.log('Invalid test runner');}},
3030
};
3131
}
3232
Object.defineProperty(exports,"__esModule",{value:true});

‎lib/modules/tutorial/utils/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ function tutorialConfig(tutorialPj, dir) {
88
varrunner=config.runner;
99
varrunnerOptions=config.runnerOptions||{};
1010
varconfigEdit=tutorialPj.config.edit;
11-
vargetRunner=config_runner_1.default(name,config.runner,dir);
12-
if(!getRunner||!getRunner.run||!getRunner.load){
13-
console.log('Error loading test runner',getRunner);
11+
var_a=config_runner_1.default(name,runner,dir),run=_a.run,load=_a.load;
12+
if(!run||!load){
13+
console.log('Error loading test runner',"run: "+run+", load: "+load);
1414
}
1515
return{
1616
dir:path_1.join(dir,'node_modules',name,config.dir),
1717
runner:runner,
1818
runnerOptions:runnerOptions,
19-
run:getRunner.run,
20-
load:getRunner.load,
19+
run:run,
20+
load:load,
2121
testSuffix:configTestSuffix(config.testSuffix||'js'),
2222
issuesPath:config_repo_1.configIssuesPath(tutorialPj.bugs),
2323
repo:repo,

‎lib/polyfills/object-values.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
functionpolyfillObjectValues(){
33
if(typeofObject.values!=='function'){
44
Object.values=function(obj){
5-
varvals=[];
5+
varvals=newSet();
66
for(varkeyinobj){
7-
vals.push(obj[key]);
7+
vals.add(obj[key]);
88
}
9-
returnvals;
9+
returnArray.from(vals);
1010
};
1111
}
1212
}

‎lib/polyfills/system.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
exports.isWindows=window.navigator.appVersion.indexOf('Win')>-1||false;

‎src/components/Alert/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const styles = {
2121
alert:state.alert||defaultAlert,
2222
}),{alertClose})
2323
exportdefaultclassAlertextendsReact.Component<{
24-
alert?:CR.Alert,alertClose?:()=>Redux.ActionCreator
24+
alert?:CR.Alert,alertClose?:()=>Redux.ActionCreator<any>
2525
},{}>{
2626
publicrender(){
2727
const{alert, alertClose}=this.props;

‎src/modules/tests/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function testLoad(): Redux.ThunkAction<any, any, {}> {
1111
type:TEST_LOAD,payload:{
1212
dir,
1313
tasks,
14-
load:tutorial.config.load,
14+
tutorial,
1515
testFile,
1616
}
1717
});
@@ -20,11 +20,13 @@ export function testLoad(): Redux.ThunkAction<any, any, {}> {
2020

2121
exportfunctiontestRun():Redux.ThunkAction<any,any,{}>{
2222
return(dispatch,getState):void=>{
23+
2324
// less than a second since the last test run, skip
2425
consttimeSinceLastTestRun=performance.now()-getState().testRun.time;
2526
if(timeSinceLastTestRun<1000){
2627
return;
2728
}
29+
2830
const{dir, tutorial, taskPosition, pagePosition}=getState();
2931
consttasks=tutorial.pages[pagePosition].tasks;
3032
consthasTasks=tasks&&tasks.length>0;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import{join}from'path';
2+
3+
import{isWindows}from'../../../polyfills/system';
4+
5+
/**
6+
* set paths to tests as absolute paths
7+
*@param {string} dir
8+
*@param {string} name
9+
*@param {Tutorial.Config} config
10+
*@param {string} testPath
11+
*@returns string
12+
*/
13+
exportdefaultfunctionconfigPath({
14+
dir, tutorial, testPath
15+
}):string{
16+
17+
if(isWindows){
18+
// adjust paths for windows slashes
19+
testPath=testPath.split('/').join('\\');
20+
}
21+
22+
// adjust absolute file path
23+
if(tutorial.config.dir){
24+
testPath=join(tutorial.config.dir,testPath);
25+
}else{
26+
testPath=join(dir,'node_modules',tutorial.name,testPath);
27+
}
28+
29+
if(tutorial.config.testSuffix){
30+
// prevent repeat appending test suffix
31+
testPath+=tutorial.config.testSuffix;
32+
}
33+
34+
returntestPath;
35+
}
36+
/**
37+
* loops over task tests and set paths to absolute paths
38+
*@param {string} dir
39+
*@param {string} name
40+
*@param {Tutorial.Config} config
41+
*@param {CR.Page[]} pages
42+
*@returns CR
43+
*/
44+
// export default function configPaths(
45+
// dir: string, name: string, config: Tutorial.Config, pages: CR.Page[]
46+
// ): CR.Page[] {
47+
// return pages.map((page: CR.Page): CR.Page => {
48+
// if (!page.tasks) {
49+
// page.tasks = [];
50+
// }
51+
// page.tasks.map((task: CR.Task): CR.Task => {
52+
53+
// if (!task.tests) { return task; }
54+
55+
// // change testPaths to use absolute URLs
56+
// task.tests = task.tests.map((testPath: string) => {
57+
// // add unique string to tests
58+
// if (typeof testPath === 'string') {
59+
// return configTestString(dir, name, config, testPath);
60+
// } else {
61+
// console.error('Invalid task test', testPath);
62+
// return 'ERROR';
63+
// }
64+
// });
65+
// return task;
66+
// });
67+
// return page;
68+
// });
69+
// }

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import{readFileSync}from'fs';
2+
importconfigPathfrom'./config-path';
23

34
/**
45
* read files from paths and concat a data file together
@@ -8,7 +9,7 @@ import { readFileSync } from 'fs';
89
*@param {} load
910
*@param {} testFile}
1011
*/
11-
exportdefaultfunctionloadTaskTests({dir, tasks,load, testFile}){
12+
exportdefaultfunctionloadTaskTests({dir, tasks,tutorial, testFile}){
1213

1314
// first read files from paths and concat data together
1415

@@ -19,7 +20,12 @@ export default function loadTaskTests({dir, tasks, load, testFile}) {
1920
// concat test files together
2021
).reduce((output:string,file:string):string=>{
2122
try{
22-
output+=readFileSync(file,'utf8')+'\n';
23+
constabsoluteFilePath=configPath({
24+
dir,
25+
tutorial,
26+
testPath:file,
27+
});
28+
output+=readFileSync(absoluteFilePath,'utf8')+'\n';
2329
}catch(e){
2430
console.log('Error reading test file',e);
2531
}
@@ -29,5 +35,5 @@ export default function loadTaskTests({dir, tasks, load, testFile}) {
2935

3036

3137
// save the file
32-
load({dir, tests, testFile});
38+
tutorial.config.load({dir, tests, testFile});
3339
}

‎src/modules/tutorial/utils/config-paths.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

‎src/modules/tutorial/utils/config-runner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import{join}from'path';
2-
import{isWindows}from'./system';
2+
import{isWindows}from'../../../polyfills/system';
33
importfileExistsfrom'node-file-exists';
44

55
/**
@@ -42,7 +42,7 @@ export default function configRunner(name: string, runner: string, dir: string):
4242
letpathToMain=join(runnerRoot,runnerMain);
4343

4444
return{
45-
load:require(pathToMain).load||{load:()=>console.log('invalid test loader')},
46-
run:require(pathToMain).run||{run:()=>console.log('invalid test runner')},
45+
load:require(pathToMain).load||{load:()=>console.log('Invalid test loader')},
46+
run:require(pathToMain).run||{run:()=>console.log('Invalid test runner')},
4747
};
4848
}

‎src/modules/tutorial/utils/config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {join} from 'path';
22

33
import{configIssuesPath,configRepo}from'./config-repo';
44
importconfigRunnerfrom'./config-runner';
5-
import{isWindows}from'./system';
5+
import{isWindows}from'../../../polyfills/system';
66
importfileExistsfrom'node-file-exists';
77

88
/**
@@ -21,18 +21,18 @@ export function tutorialConfig(
2121
construnnerOptions:Object=config.runnerOptions||{};
2222
constconfigEdit=tutorialPj.config.edit;
2323

24-
constgetRunner=configRunner(name,config.runner,dir);
24+
const{ run, load}=configRunner(name,runner,dir);
2525

26-
if(!getRunner||!getRunner.run||!getRunner.load){
27-
console.log('Error loading test runner',getRunner);
26+
if(!run||!load){
27+
console.log('Error loading test runner',`run:${run}, load:${load}`);
2828
}
2929

3030
return{
3131
dir:join(dir,'node_modules',name,config.dir),
3232
runner,
3333
runnerOptions,
34-
run:getRunner.run,
35-
load:getRunner.load,
34+
run,
35+
load,
3636
testSuffix:configTestSuffix(config.testSuffix||'js'),
3737
issuesPath:configIssuesPath(tutorialPj.bugs),
3838
repo,
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp