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
working solution test runner
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
@ShMcK
ShMcK committedJun 13, 2020
commit16e42f125505545830b2806532a3262d063ce1eb
62 changes: 39 additions & 23 deletionssrc/utils/exec.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,10 +6,15 @@ import { promisify } from "util";
const asyncExec = promisify(cpExec);

export function createExec(cwd: string) {
return function exec(
returnasyncfunction exec(
command: string
): Promise<{ stdout: string; stderr: string }> | never {
return asyncExec(command, { cwd });
): Promise<{ stdout: string | null; stderr: string }> {
try {
const result = await asyncExec(command, { cwd });
return result;
} catch (e) {
return { stdout: null, stderr: e.message };
}
};
}

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

export function createCommandRunner(cwd: string) {
return async function runCommands(commands: string[], dir?: string) {
return async function runCommands(
commands: string[],
dir?: string
): Promise<boolean> {
let errors = [];
for (const command of commands) {
try {
console.log(`> ${command}`);
let cwdDir = cwd;
if (dir) {
cwdDir = path.join(cwd, dir);
}
await createExec(cwdDir)(command);
const { stdout, stderr } = await createExec(cwdDir)(command);

console.warn(stderr);
console.log(stdout);
} catch (e) {
console.log(`Setup command failed: "${command}"`);
console.log(e.message);
console.error(`Command failed: "${command}"`);
console.warn(e.message);
errors.push(e.message);
}
}
return !!errors.length;
};
}

function isAbsolute(p: string) {
return path.normalize(p + "/") === path.normalize(path.resolve(p) + "/");
}
//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);
//const commandIsAbsolute = isAbsolute(command);

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

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

return async function runTest() {
const { stdout, stderr } = await createExec(cwd)(commandWithArgs);
console.log(stdout);
console.warn(stderr);
return async function runTest(): Promise<{
stdout: string | null;
stderr: string | null;
}> {
try {
// console.log(await createExec(wd)("ls -a node_modules/.bin"));
return await createExec(wd)(commandWithArgs);
} catch (e) {
return Promise.resolve({ stdout: null, stderr: e.message });
}
};
}
4 changes: 1 addition & 3 deletionssrc/validate.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,8 +57,6 @@ async function validate(args: string[]) {
const runCommands = createCommandRunner(tmpDir);
const runTest = createTestRunner(tmpDir, skeleton.config.testRunner);

// VALIDATE TUTORIAL TESTS

// setup
if (commits.INIT) {
// load commits
Expand DownExpand Up@@ -131,7 +129,7 @@ async function validate(args: string[]) {
// run test
console.info("Running solution test");
// expect pass
//await runTest();
await runTest();
}
}
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp