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

Feature/validate#34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 11 commits intomasterfromfeature/validate
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
test runner progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 13, 2020
commit9df45b102a06a5d8f52d8d1aee3af34df577bf4f
37 changes: 35 additions & 2 deletionssrc/utils/exec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
import * as T from "../../typings/tutorial";
import { exec as cpExec } from "child_process";
import * as path from "path";
import { promisify } from "util";

const asyncExec = promisify(cpExec);
Expand DownExpand Up@@ -29,15 +31,46 @@ export function createCherryPick(cwd: string) {
}

export function createCommandRunner(cwd: string) {
return async function runCommands(commands: string[]) {
return async function runCommands(commands: string[], dir?: string) {
for (const command of commands) {
try {
console.log(`> ${command}`);
await createExec(cwd)(command);
let cwdDir = cwd;
if (dir) {
cwdDir = path.join(cwd, dir);
}
await createExec(cwdDir)(command);
} catch (e) {
console.log(`Setup command failed: "${command}"`);
console.log(e.message);
}
}
};
}

function isAbsolute(p: string) {
return path.normalize(p + "/") === path.normalize(path.resolve(p) + "/");
}

export function createTestRunner(cwd: string, config: T.TestRunnerConfig) {
const { command, args, directory } = config;

const commandIsAbsolute = isAbsolute(command);

let runnerPath;
if (commandIsAbsolute) {
// absolute path
runnerPath = command;
} else {
// relative path
runnerPath = path.join(cwd, directory || "", command);
}

const commandWithArgs = `${runnerPath} ${args.tap}`;

return async function runTest() {
const { stdout, stderr } = await createExec(cwd)(commandWithArgs);
console.log(stdout);
console.warn(stderr);
};
}
20 changes: 17 additions & 3 deletionssrc/validate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,11 @@ import * as fs from "fs-extra";
import * as yamlParser from "js-yaml";
import { getArg } from "./utils/args";
import gitP, { SimpleGit } from "simple-git/promise";
import { createCommandRunner, createCherryPick } from "./utils/exec";
import {
createCommandRunner,
createCherryPick,
createTestRunner,
} from "./utils/exec";
import { getCommits, CommitLogObject } from "./utils/commits";

async function validate(args: string[]) {
Expand DownExpand Up@@ -51,6 +55,7 @@ async function validate(args: string[]) {
// no js cherry pick implementation
const cherryPick = createCherryPick(tmpDir);
const runCommands = createCommandRunner(tmpDir);
const runTest = createTestRunner(tmpDir, skeleton.config.testRunner);

// VALIDATE TUTORIAL TESTS

Expand All@@ -63,11 +68,15 @@ async function validate(args: string[]) {
// run commands
if (skeleton.config?.testRunner?.setup?.commands) {
console.info("Running setup commands...");
await runCommands(skeleton.config?.testRunner?.setup?.commands);

await runCommands(
skeleton.config?.testRunner?.setup?.commands,
// add optional setup directory
skeleton.config?.testRunner?.directory
);
}
}

console.log(skeleton.levels);
for (const level of skeleton.levels) {
if (level.setup) {
// load commits
Expand All@@ -84,6 +93,7 @@ async function validate(args: string[]) {
// steps
if (level.steps) {
for (const step of level.steps) {
console.log(step);
// load commits
if (step.setup.commits) {
console.log(`Loading ${step.id} commits...`);
Expand All@@ -94,6 +104,10 @@ async function validate(args: string[]) {
console.log(`Running ${step.id} commands...`);
await runCommands(step.setup.commands);
}

// run test
console.info("Running test");
await runTest();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletiontypings/tutorial.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ export interface TestRunnerArgs {

exportinterfaceTestRunnerConfig{
command:string;
args?:TestRunnerArgs;
args:TestRunnerArgs;
directory?:string;
setup?:StepActions;
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp