-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add help + types integration tests (#4)
- Loading branch information
1 parent
48cc663
commit 3b3ed43
Showing
12 changed files
with
146 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true | ||
"deno.lint": true, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
}, | ||
"[javascriptreact]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "denoland.vscode-deno" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ fmt: | |
|
||
lint: | ||
deno lint | ||
|
||
test: | ||
deno test -A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { bold, red } from "../deps.ts"; | ||
|
||
export function error(message: string): never { | ||
console.log(red(`${bold("error")}: ${message}`)); | ||
console.error(red(`${bold("error")}: ${message}`)); | ||
Deno.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "https://deno.land/[email protected]/testing/asserts.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { assertEquals, assertStringIncludes } from "./deps.ts"; | ||
import { output, test } from "./utils.ts"; | ||
|
||
test({ args: [] }, async (proc) => { | ||
const [stdout, stderr, { code }] = await output(proc); | ||
assertStringIncludes(stderr, "SUBCOMMANDS:"); | ||
assertStringIncludes(stderr, "run "); | ||
assertStringIncludes(stderr, "types "); | ||
assertEquals(code, 1); | ||
assertEquals(stdout, ""); | ||
}); | ||
|
||
test({ args: ["-h"] }, async (proc) => { | ||
const [stdout, stderr, { code }] = await output(proc); | ||
assertStringIncludes(stderr, "SUBCOMMANDS:"); | ||
assertStringIncludes(stderr, "run "); | ||
assertStringIncludes(stderr, "types "); | ||
assertEquals(code, 1); | ||
assertEquals(stdout, ""); | ||
}); | ||
|
||
test({ args: ["run", "-h"] }, async (proc) => { | ||
const [stdout, stderr, { code }] = await output(proc); | ||
assertStringIncludes(stderr, "USAGE:"); | ||
assertStringIncludes(stderr, "deployctl run"); | ||
assertEquals(code, 1); | ||
assertEquals(stdout, ""); | ||
}); | ||
|
||
test({ args: ["types", "-h"] }, async (proc) => { | ||
const [stdout, stderr, { code }] = await output(proc); | ||
assertStringIncludes(stderr, "USAGE:"); | ||
assertStringIncludes(stderr, "deployctl types"); | ||
assertEquals(code, 1); | ||
assertEquals(stdout, ""); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { assertEquals, assertStringIncludes } from "./deps.ts"; | ||
import { output, test } from "./utils.ts"; | ||
|
||
test({ args: ["types"] }, async (proc) => { | ||
const [stdout, stderr, { code }] = await output(proc); | ||
assertEquals(stderr, ""); | ||
assertEquals(code, 0); | ||
assertStringIncludes(stdout, `/// <reference no-default-lib="true" />`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
export interface Permissions { | ||
net: boolean; | ||
read: boolean; | ||
write: boolean; | ||
env: boolean; | ||
run: boolean; | ||
} | ||
|
||
export function deployctl( | ||
args: string[], | ||
permissions: Permissions = { | ||
net: true, | ||
read: true, | ||
write: true, | ||
env: true, | ||
run: true, | ||
}, | ||
): Deno.Process { | ||
const cmd = [ | ||
Deno.execPath(), | ||
"run", | ||
"--no-check", | ||
]; | ||
|
||
if (permissions?.net) cmd.push("--allow-net"); | ||
if (permissions?.read) cmd.push("--allow-read"); | ||
if (permissions?.write) cmd.push("--allow-write"); | ||
if (permissions?.env) cmd.push("--allow-env"); | ||
if (permissions?.run) cmd.push("--allow-run"); | ||
|
||
cmd.push(new URL("../deployctl.ts", import.meta.url).toString()); | ||
|
||
return Deno.run({ | ||
cmd: [...cmd, ...args], | ||
stdin: "null", | ||
stdout: "piped", | ||
stderr: "piped", | ||
}); | ||
} | ||
|
||
export interface TestOptions { | ||
args: string[]; | ||
name?: string; | ||
permissions?: Permissions; | ||
} | ||
|
||
export function test( | ||
opts: TestOptions, | ||
fn: (proc: Deno.Process) => void | Promise<void>, | ||
) { | ||
const name = opts.name ?? ["deployctl", ...opts.args].join(" "); | ||
Deno.test(name, async () => { | ||
const proc = deployctl(opts.args, opts.permissions); | ||
try { | ||
await fn(proc); | ||
} finally { | ||
proc.close(); | ||
} | ||
}); | ||
} | ||
|
||
export async function output( | ||
proc: Deno.Process, | ||
): Promise<[string, string, Deno.ProcessStatus]> { | ||
const stdout = await proc.output(); | ||
const stderr = await proc.stderrOutput(); | ||
const status = await proc.status(); | ||
return [ | ||
new TextDecoder().decode(stdout), | ||
new TextDecoder().decode(stderr), | ||
status, | ||
]; | ||
} |