Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 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
Prev Previous commit
Next Next commit
test runner progress
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jun 13, 2020
commit 9df45b102a06a5d8f52d8d1aee3af34df577bf4f
37 changes: 35 additions & 2 deletions src/utils/exec.ts
Original file line number Diff line number Diff 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 Down Expand 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 deletions src/validate.ts
Original file line number Diff line number Diff 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 Down Expand 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 deletion typings/tutorial.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface TestRunnerArgs {

export interface TestRunnerConfig {
command: string;
args?: TestRunnerArgs;
args: TestRunnerArgs;
directory?: string;
setup?: StepActions;
}
Expand Down