1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 00:21:05 -05:00

test(std/mime): make tests runnable from any directory (#7398)

This commit is contained in:
Casper Beyer 2020-09-09 17:24:47 +08:00 committed by GitHub
parent 11afd071ae
commit 79b2510617
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,7 +19,9 @@ const e = new TextEncoder();
const boundary = "--abcde"; const boundary = "--abcde";
const dashBoundary = e.encode("--" + boundary); const dashBoundary = e.encode("--" + boundary);
const nlDashBoundary = e.encode("\r\n--" + boundary); const nlDashBoundary = e.encode("\r\n--" + boundary);
const testdataDir = path.resolve("mime", "testdata");
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");
Deno.test("multipartScanUntilBoundary1", function (): void { Deno.test("multipartScanUntilBoundary1", function (): void {
const data = `--${boundary}`; const data = `--${boundary}`;
@ -92,7 +94,7 @@ Deno.test("multipartMultipartWriter", async function (): Promise<void> {
const mw = new MultipartWriter(buf); const mw = new MultipartWriter(buf);
await mw.writeField("foo", "foo"); await mw.writeField("foo", "foo");
await mw.writeField("bar", "bar"); await mw.writeField("bar", "bar");
const f = await Deno.open(path.resolve("./mime/testdata/sample.txt"), { const f = await Deno.open(path.join(testdataDir, "sample.txt"), {
read: true, read: true,
}); });
await mw.writeFile("file", "sample.txt", f); await mw.writeFile("file", "sample.txt", f);
@ -175,7 +177,7 @@ Deno.test("multipartMultipartWriter3", async function (): Promise<void> {
Deno.test({ Deno.test({
name: "[mime/multipart] readForm() basic", name: "[mime/multipart] readForm() basic",
async fn() { async fn() {
const o = await Deno.open(path.resolve("./mime/testdata/sample.txt")); const o = await Deno.open(path.join(testdataDir, "sample.txt"));
const mr = new MultipartReader( const mr = new MultipartReader(
o, o,
"--------------------------434049563556637648550474", "--------------------------434049563556637648550474",
@ -247,7 +249,7 @@ Deno.test({
Deno.test({ Deno.test({
name: "[mime/multipart] removeAll() should remove all tempfiles", name: "[mime/multipart] removeAll() should remove all tempfiles",
async fn() { async fn() {
const o = await Deno.open(path.resolve("./mime/testdata/sample.txt")); const o = await Deno.open(path.join(testdataDir, "sample.txt"));
const mr = new MultipartReader( const mr = new MultipartReader(
o, o,
"--------------------------434049563556637648550474", "--------------------------434049563556637648550474",
@ -274,7 +276,7 @@ Deno.test({
Deno.test({ Deno.test({
name: "[mime/multipart] entries()", name: "[mime/multipart] entries()",
async fn() { async fn() {
const o = await Deno.open(path.resolve("./mime/testdata/sample.txt")); const o = await Deno.open(path.join(testdataDir, "sample.txt"));
const mr = new MultipartReader( const mr = new MultipartReader(
o, o,
"--------------------------434049563556637648550474", "--------------------------434049563556637648550474",