mirror of
https://github.com/denoland/deno.git
synced 2024-11-26 16:09:27 -05:00
test(std/examples): make tests runnable from any directory (#7399)
This commit is contained in:
parent
25053f92ff
commit
5b89e82164
9 changed files with 39 additions and 10 deletions
|
@ -4,6 +4,9 @@ import { TextProtoReader } from "../../textproto/mod.ts";
|
||||||
import { BufReader } from "../../io/bufio.ts";
|
import { BufReader } from "../../io/bufio.ts";
|
||||||
import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
|
import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
|
||||||
import { delay } from "../../async/delay.ts";
|
import { delay } from "../../async/delay.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)));
|
||||||
|
|
||||||
async function startServer(): Promise<
|
async function startServer(): Promise<
|
||||||
Deno.Process<Deno.RunOptions & { stdout: "piped" }>
|
Deno.Process<Deno.RunOptions & { stdout: "piped" }>
|
||||||
|
@ -16,7 +19,7 @@ async function startServer(): Promise<
|
||||||
"--allow-read",
|
"--allow-read",
|
||||||
"server.ts",
|
"server.ts",
|
||||||
],
|
],
|
||||||
cwd: "examples/chat",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertEquals } from "../testing/asserts.ts";
|
import { assertEquals } from "../testing/asserts.ts";
|
||||||
|
import { dirname, relative, resolve, fromFileUrl } from "../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = dirname(fromFileUrl(import.meta.url));
|
||||||
|
|
||||||
/** Example of how to do basic tests */
|
/** Example of how to do basic tests */
|
||||||
Deno.test("t1", function (): void {
|
Deno.test("t1", function (): void {
|
||||||
|
@ -17,8 +20,8 @@ Deno.test("catSmoke", async function (): Promise<void> {
|
||||||
Deno.execPath(),
|
Deno.execPath(),
|
||||||
"run",
|
"run",
|
||||||
"--allow-read",
|
"--allow-read",
|
||||||
"examples/cat.ts",
|
relative(Deno.cwd(), resolve(moduleDir, "cat.ts")),
|
||||||
"README.md",
|
relative(Deno.cwd(), resolve(moduleDir, "..", "README.md")),
|
||||||
],
|
],
|
||||||
stdout: "null",
|
stdout: "null",
|
||||||
stderr: "null",
|
stderr: "null",
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertStrictEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals } from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("[examples/cat] print multiple files", async () => {
|
Deno.test("[examples/cat] print multiple files", async () => {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
@ -12,7 +15,7 @@ Deno.test("[examples/cat] print multiple files", async () => {
|
||||||
"testdata/cat/hello.txt",
|
"testdata/cat/hello.txt",
|
||||||
"testdata/cat/world.txt",
|
"testdata/cat/world.txt",
|
||||||
],
|
],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertStrictEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals } from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("[examples/catj] print an array", async () => {
|
Deno.test("[examples/catj] print an array", async () => {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
@ -80,7 +83,7 @@ function catj(
|
||||||
): Deno.Process<Deno.RunOptions & { stdin: "piped"; stdout: "piped" }> {
|
): Deno.Process<Deno.RunOptions & { stdin: "piped"; stdout: "piped" }> {
|
||||||
return Deno.run({
|
return Deno.run({
|
||||||
cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files],
|
cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdin: "piped",
|
stdin: "piped",
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
env: { NO_COLOR: "true" },
|
env: { NO_COLOR: "true" },
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertStrictEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals } from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("[examples/colors] print a colored text", async () => {
|
Deno.test("[examples/colors] print a colored text", async () => {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const process = Deno.run({
|
const process = Deno.run({
|
||||||
cmd: [Deno.execPath(), "run", "colors.ts"],
|
cmd: [Deno.execPath(), "run", "colors.ts"],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { serve } from "../../http/server.ts";
|
import { serve } from "../../http/server.ts";
|
||||||
import { assertStrictEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals } from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "[examples/curl] send a request to a specified url",
|
name: "[examples/curl] send a request to a specified url",
|
||||||
|
@ -21,7 +24,7 @@ Deno.test({
|
||||||
"curl.ts",
|
"curl.ts",
|
||||||
"http://localhost:8081",
|
"http://localhost:8081",
|
||||||
],
|
],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertStrictEquals, assertNotEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals, assertNotEquals } from "../../testing/asserts.ts";
|
||||||
import { BufReader, ReadLineResult } from "../../io/bufio.ts";
|
import { BufReader, ReadLineResult } from "../../io/bufio.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("[examples/echo_server]", async () => {
|
Deno.test("[examples/echo_server]", async () => {
|
||||||
const encoder = new TextEncoder();
|
const encoder = new TextEncoder();
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const process = Deno.run({
|
const process = Deno.run({
|
||||||
cmd: [Deno.execPath(), "run", "--allow-net", "echo_server.ts"],
|
cmd: [Deno.execPath(), "run", "--allow-net", "echo_server.ts"],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { assertStrictEquals } from "../../testing/asserts.ts";
|
import { assertStrictEquals } from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("[examples/welcome] print a welcome message", async () => {
|
Deno.test("[examples/welcome] print a welcome message", async () => {
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
const process = Deno.run({
|
const process = Deno.run({
|
||||||
cmd: [Deno.execPath(), "run", "welcome.ts"],
|
cmd: [Deno.execPath(), "run", "welcome.ts"],
|
||||||
cwd: "examples",
|
cwd: moduleDir,
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -7,6 +7,9 @@ import {
|
||||||
assertStringContains,
|
assertStringContains,
|
||||||
assert,
|
assert,
|
||||||
} from "../../testing/asserts.ts";
|
} from "../../testing/asserts.ts";
|
||||||
|
import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
|
||||||
|
|
||||||
|
const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
|
||||||
|
|
||||||
Deno.test("xevalSuccess", async function (): Promise<void> {
|
Deno.test("xevalSuccess", async function (): Promise<void> {
|
||||||
const chunks: string[] = [];
|
const chunks: string[] = [];
|
||||||
|
@ -26,7 +29,7 @@ Deno.test("xevalDelimiter", async function (): Promise<void> {
|
||||||
assertEquals(chunks, ["!MAD", "ADAM!"]);
|
assertEquals(chunks, ["!MAD", "ADAM!"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const xevalPath = "examples/xeval.ts";
|
const xevalPath = "xeval.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "xevalCliReplvar",
|
name: "xevalCliReplvar",
|
||||||
|
@ -39,6 +42,7 @@ Deno.test({
|
||||||
"--replvar=abc",
|
"--replvar=abc",
|
||||||
"console.log(abc)",
|
"console.log(abc)",
|
||||||
],
|
],
|
||||||
|
cwd: moduleDir,
|
||||||
stdin: "piped",
|
stdin: "piped",
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
stderr: "null",
|
stderr: "null",
|
||||||
|
@ -55,6 +59,7 @@ Deno.test({
|
||||||
Deno.test("xevalCliSyntaxError", async function (): Promise<void> {
|
Deno.test("xevalCliSyntaxError", async function (): Promise<void> {
|
||||||
const p = Deno.run({
|
const p = Deno.run({
|
||||||
cmd: [Deno.execPath(), "run", xevalPath, "("],
|
cmd: [Deno.execPath(), "run", xevalPath, "("],
|
||||||
|
cwd: moduleDir,
|
||||||
stdin: "null",
|
stdin: "null",
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
stderr: "piped",
|
stderr: "piped",
|
||||||
|
|
Loading…
Reference in a new issue