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

Commit16e42f1

Browse files
committed
working solution test runner
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent514b2ad commit16e42f1

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

‎src/utils/exec.ts

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import { promisify } from "util";
66
constasyncExec=promisify(cpExec);
77

88
exportfunctioncreateExec(cwd:string){
9-
returnfunctionexec(
9+
returnasyncfunctionexec(
1010
command:string
11-
):Promise<{stdout:string;stderr:string}>|never{
12-
returnasyncExec(command,{ cwd});
11+
):Promise<{stdout:string|null;stderr:string}>{
12+
try{
13+
constresult=awaitasyncExec(command,{ cwd});
14+
returnresult;
15+
}catch(e){
16+
return{stdout:null,stderr:e.message};
17+
}
1318
};
1419
}
1520

@@ -31,46 +36,57 @@ export function createCherryPick(cwd: string) {
3136
}
3237

3338
exportfunctioncreateCommandRunner(cwd:string){
34-
returnasyncfunctionrunCommands(commands:string[],dir?:string){
39+
returnasyncfunctionrunCommands(
40+
commands:string[],
41+
dir?:string
42+
):Promise<boolean>{
43+
leterrors=[];
3544
for(constcommandofcommands){
3645
try{
3746
console.log(`>${command}`);
3847
letcwdDir=cwd;
3948
if(dir){
4049
cwdDir=path.join(cwd,dir);
4150
}
42-
awaitcreateExec(cwdDir)(command);
51+
const{ stdout, stderr}=awaitcreateExec(cwdDir)(command);
52+
53+
console.warn(stderr);
54+
console.log(stdout);
4355
}catch(e){
44-
console.log(`Setup command failed: "${command}"`);
45-
console.log(e.message);
56+
console.error(`Command failed: "${command}"`);
57+
console.warn(e.message);
58+
errors.push(e.message);
4659
}
4760
}
61+
return!!errors.length;
4862
};
4963
}
5064

51-
functionisAbsolute(p:string){
52-
returnpath.normalize(p+"/")===path.normalize(path.resolve(p)+"/");
53-
}
65+
//function isAbsolute(p: string) {
66+
// return path.normalize(p + "/") === path.normalize(path.resolve(p) + "/");
67+
//}
5468

5569
exportfunctioncreateTestRunner(cwd:string,config:T.TestRunnerConfig){
5670
const{ command, args, directory}=config;
5771

58-
constcommandIsAbsolute=isAbsolute(command);
72+
//const commandIsAbsolute = isAbsolute(command);
5973

60-
letrunnerPath;
61-
if(commandIsAbsolute){
62-
// absolute path
63-
runnerPath=command;
64-
}else{
65-
// relative path
66-
runnerPath=path.join(cwd,directory||"",command);
74+
letwd=cwd;
75+
if(directory){
76+
wd=path.join(cwd,directory);
6777
}
6878

69-
constcommandWithArgs=`${runnerPath}${args.tap}`;
79+
constcommandWithArgs=`${command}${args.tap}`;
7080

71-
returnasyncfunctionrunTest(){
72-
const{ stdout, stderr}=awaitcreateExec(cwd)(commandWithArgs);
73-
console.log(stdout);
74-
console.warn(stderr);
81+
returnasyncfunctionrunTest():Promise<{
82+
stdout:string|null;
83+
stderr:string|null;
84+
}>{
85+
try{
86+
// console.log(await createExec(wd)("ls -a node_modules/.bin"));
87+
returnawaitcreateExec(wd)(commandWithArgs);
88+
}catch(e){
89+
returnPromise.resolve({stdout:null,stderr:e.message});
90+
}
7591
};
7692
}

‎src/validate.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ async function validate(args: string[]) {
5757
construnCommands=createCommandRunner(tmpDir);
5858
construnTest=createTestRunner(tmpDir,skeleton.config.testRunner);
5959

60-
// VALIDATE TUTORIAL TESTS
61-
6260
// setup
6361
if(commits.INIT){
6462
// load commits
@@ -131,7 +129,7 @@ async function validate(args: string[]) {
131129
// run test
132130
console.info("Running solution test");
133131
// expect pass
134-
//await runTest();
132+
awaitrunTest();
135133
}
136134
}
137135
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp