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

Commit9df45b1

Browse files
committed
test runner progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent37b3d50 commit9df45b1

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

‎src/utils/exec.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import*asTfrom"../../typings/tutorial";
12
import{execascpExec}from"child_process";
3+
import*aspathfrom"path";
24
import{promisify}from"util";
35

46
constasyncExec=promisify(cpExec);
@@ -29,15 +31,46 @@ export function createCherryPick(cwd: string) {
2931
}
3032

3133
exportfunctioncreateCommandRunner(cwd:string){
32-
returnasyncfunctionrunCommands(commands:string[]){
34+
returnasyncfunctionrunCommands(commands:string[],dir?:string){
3335
for(constcommandofcommands){
3436
try{
3537
console.log(`>${command}`);
36-
awaitcreateExec(cwd)(command);
38+
letcwdDir=cwd;
39+
if(dir){
40+
cwdDir=path.join(cwd,dir);
41+
}
42+
awaitcreateExec(cwdDir)(command);
3743
}catch(e){
3844
console.log(`Setup command failed: "${command}"`);
3945
console.log(e.message);
4046
}
4147
}
4248
};
4349
}
50+
51+
functionisAbsolute(p:string){
52+
returnpath.normalize(p+"/")===path.normalize(path.resolve(p)+"/");
53+
}
54+
55+
exportfunctioncreateTestRunner(cwd:string,config:T.TestRunnerConfig){
56+
const{ command, args, directory}=config;
57+
58+
constcommandIsAbsolute=isAbsolute(command);
59+
60+
letrunnerPath;
61+
if(commandIsAbsolute){
62+
// absolute path
63+
runnerPath=command;
64+
}else{
65+
// relative path
66+
runnerPath=path.join(cwd,directory||"",command);
67+
}
68+
69+
constcommandWithArgs=`${runnerPath}${args.tap}`;
70+
71+
returnasyncfunctionrunTest(){
72+
const{ stdout, stderr}=awaitcreateExec(cwd)(commandWithArgs);
73+
console.log(stdout);
74+
console.warn(stderr);
75+
};
76+
}

‎src/validate.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import * as fs from "fs-extra";
33
import*asyamlParserfrom"js-yaml";
44
import{getArg}from"./utils/args";
55
importgitP,{SimpleGit}from"simple-git/promise";
6-
import{createCommandRunner,createCherryPick}from"./utils/exec";
6+
import{
7+
createCommandRunner,
8+
createCherryPick,
9+
createTestRunner,
10+
}from"./utils/exec";
711
import{getCommits,CommitLogObject}from"./utils/commits";
812

913
asyncfunctionvalidate(args:string[]){
@@ -51,6 +55,7 @@ async function validate(args: string[]) {
5155
// no js cherry pick implementation
5256
constcherryPick=createCherryPick(tmpDir);
5357
construnCommands=createCommandRunner(tmpDir);
58+
construnTest=createTestRunner(tmpDir,skeleton.config.testRunner);
5459

5560
// VALIDATE TUTORIAL TESTS
5661

@@ -63,11 +68,15 @@ async function validate(args: string[]) {
6368
// run commands
6469
if(skeleton.config?.testRunner?.setup?.commands){
6570
console.info("Running setup commands...");
66-
awaitrunCommands(skeleton.config?.testRunner?.setup?.commands);
71+
72+
awaitrunCommands(
73+
skeleton.config?.testRunner?.setup?.commands,
74+
// add optional setup directory
75+
skeleton.config?.testRunner?.directory
76+
);
6777
}
6878
}
6979

70-
console.log(skeleton.levels);
7180
for(constlevelofskeleton.levels){
7281
if(level.setup){
7382
// load commits
@@ -84,6 +93,7 @@ async function validate(args: string[]) {
8493
// steps
8594
if(level.steps){
8695
for(conststepoflevel.steps){
96+
console.log(step);
8797
// load commits
8898
if(step.setup.commits){
8999
console.log(`Loading${step.id} commits...`);
@@ -94,6 +104,10 @@ async function validate(args: string[]) {
94104
console.log(`Running${step.id} commands...`);
95105
awaitrunCommands(step.setup.commands);
96106
}
107+
108+
// run test
109+
console.info("Running test");
110+
awaitrunTest();
97111
}
98112
}
99113
}

‎typings/tutorial.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface TestRunnerArgs {
6262

6363
exportinterfaceTestRunnerConfig{
6464
command:string;
65-
args?:TestRunnerArgs;
65+
args:TestRunnerArgs;
6666
directory?:string;
6767
setup?:StepActions;
6868
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp