aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-06-20 21:35:22 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-06-22 06:56:47 -0700
commit41b03b5c4c426bd3f2a3c7c6aaf454cee11744f0 (patch)
treefd1819ed5dfbe58edfe971b7c05c2c59549b8251
parentbfa5b2955533a60b2f12e6ac65d4868efcaf5222 (diff)
downloadbun-41b03b5c4c426bd3f2a3c7c6aaf454cee11744f0.tar.gz
bun-41b03b5c4c426bd3f2a3c7c6aaf454cee11744f0.tar.zst
bun-41b03b5c4c426bd3f2a3c7c6aaf454cee11744f0.zip
Cleanup tests
-rw-r--r--integration/bunjs-only-snippets/buffer.test.js6
-rw-r--r--integration/bunjs-only-snippets/crypto.test.js12
-rw-r--r--integration/bunjs-only-snippets/fetch.test.js5
-rw-r--r--integration/bunjs-only-snippets/gc.js3
-rw-r--r--integration/bunjs-only-snippets/streams.test.js23
-rw-r--r--integration/bunjs-only-snippets/text-encoder.test.js4
-rw-r--r--integration/bunjs-only-snippets/toml.test.js6
-rw-r--r--integration/bunjs-only-snippets/unsafe.test.js19
8 files changed, 37 insertions, 41 deletions
diff --git a/integration/bunjs-only-snippets/buffer.test.js b/integration/bunjs-only-snippets/buffer.test.js
index cbe204e63..dd5327ca3 100644
--- a/integration/bunjs-only-snippets/buffer.test.js
+++ b/integration/bunjs-only-snippets/buffer.test.js
@@ -1,5 +1,9 @@
import { gc } from "bun";
-import { describe, it, expect } from "bun:test";
+import { describe, it, expect, beforeEach, afterEach } from "bun:test";
+import { gc } from "./gc";
+
+beforeEach(() => gc());
+afterEach(() => gc());
it("buffer", () => {
var buf = new Buffer(20);
diff --git a/integration/bunjs-only-snippets/crypto.test.js b/integration/bunjs-only-snippets/crypto.test.js
index 2c784e496..c489e11c1 100644
--- a/integration/bunjs-only-snippets/crypto.test.js
+++ b/integration/bunjs-only-snippets/crypto.test.js
@@ -14,13 +14,13 @@ import { readFileSync } from "fs";
describe("crypto", () => {
for (let Hash of [MD5, MD4, SHA1, SHA256, SHA384, SHA512, SHA512_256]) {
- for (let input of [
- "hello world",
- "hello world".repeat(20).slice(),
- "",
- "a",
+ for (let [input, label] of [
+ ["hello world", '"hello world"'],
+ ["hello world".repeat(20).slice(), '"hello world" x 20'],
+ ["", "empty string"],
+ ["a", '"a"'],
]) {
- describe(input, () => {
+ describe(label, () => {
gc(true);
it(`${Hash.name} base64`, () => {
diff --git a/integration/bunjs-only-snippets/fetch.test.js b/integration/bunjs-only-snippets/fetch.test.js
index 9aea4d6d0..9b6093afd 100644
--- a/integration/bunjs-only-snippets/fetch.test.js
+++ b/integration/bunjs-only-snippets/fetch.test.js
@@ -1,9 +1,6 @@
import { it, describe, expect } from "bun:test";
import fs from "fs";
-
-function gc() {
- Bun.gc(true);
-}
+import { gc } from "./gc";
describe("fetch", () => {
const urls = ["https://example.com", "http://example.com"];
diff --git a/integration/bunjs-only-snippets/gc.js b/integration/bunjs-only-snippets/gc.js
index 327b7d9a5..9212e8b76 100644
--- a/integration/bunjs-only-snippets/gc.js
+++ b/integration/bunjs-only-snippets/gc.js
@@ -1,4 +1,5 @@
export function gc() {
+ // console.trace("GC");
Bun.gc(true);
}
@@ -6,7 +7,7 @@ export function gc() {
// so that the reference-counting logic is exercised
export function gcTick(trace = false) {
trace && console.trace("");
-
+ // console.trace("hello");
gc();
return new Promise((resolve) => {
setTimeout(resolve, 0);
diff --git a/integration/bunjs-only-snippets/streams.test.js b/integration/bunjs-only-snippets/streams.test.js
index 59da95b5a..ccbea1d09 100644
--- a/integration/bunjs-only-snippets/streams.test.js
+++ b/integration/bunjs-only-snippets/streams.test.js
@@ -1,14 +1,12 @@
-import {
- file,
- gc,
- readableStreamToArrayBuffer,
- readableStreamToArray,
-} from "bun";
-import { expect, it } from "bun:test";
+import { file, readableStreamToArrayBuffer, readableStreamToArray } from "bun";
+import { expect, it, beforeEach, afterEach } from "bun:test";
import { writeFileSync } from "node:fs";
-
+import { gc } from "./gc";
new Uint8Array();
+beforeEach(() => gc());
+afterEach(() => gc());
+
it("exists globally", () => {
expect(typeof ReadableStream).toBe("function");
expect(typeof ReadableStreamBYOBReader).toBe("function");
@@ -42,18 +40,14 @@ it("ReadableStream (direct)", async () => {
});
it("ReadableStream (bytes)", async () => {
- console.trace();
-
var stream = new ReadableStream({
start(controller) {
- console.log("there");
controller.enqueue(Buffer.from("abdefgh"));
},
pull(controller) {},
cancel() {},
type: "bytes",
});
- console.log("here");
const chunks = [];
const chunk = await stream.getReader().read();
chunks.push(chunk.value);
@@ -61,7 +55,6 @@ it("ReadableStream (bytes)", async () => {
});
it("ReadableStream (default)", async () => {
- console.trace();
var stream = new ReadableStream({
start(controller) {
controller.enqueue(Buffer.from("abdefgh"));
@@ -77,7 +70,6 @@ it("ReadableStream (default)", async () => {
});
it("readableStreamToArray", async () => {
- console.trace();
var queue = [Buffer.from("abdefgh")];
var stream = new ReadableStream({
pull(controller) {
@@ -98,7 +90,6 @@ it("readableStreamToArray", async () => {
});
it("readableStreamToArrayBuffer (bytes)", async () => {
- console.trace();
var queue = [Buffer.from("abdefgh")];
var stream = new ReadableStream({
pull(controller) {
@@ -135,7 +126,6 @@ it("readableStreamToArrayBuffer (default)", async () => {
});
it("ReadableStream for Blob", async () => {
- console.trace();
var blob = new Blob(["abdefgh", "ijklmnop"]);
expect(await blob.text()).toBe("abdefghijklmnop");
var stream;
@@ -168,7 +158,6 @@ it("ReadableStream for Blob", async () => {
});
it("ReadableStream for File", async () => {
- console.trace();
var blob = file(import.meta.dir + "/fetch.js.txt");
var stream = blob.stream(24);
const chunks = [];
diff --git a/integration/bunjs-only-snippets/text-encoder.test.js b/integration/bunjs-only-snippets/text-encoder.test.js
index 7c6a07efb..5687e0222 100644
--- a/integration/bunjs-only-snippets/text-encoder.test.js
+++ b/integration/bunjs-only-snippets/text-encoder.test.js
@@ -1,7 +1,5 @@
import { expect, it, describe } from "bun:test";
-function gcTrace() {
- Bun.gc(true);
-}
+import { gc as gcTrace } from "./gc";
const getByteLength = (str) => {
// returns the byte length of an utf8 string
diff --git a/integration/bunjs-only-snippets/toml.test.js b/integration/bunjs-only-snippets/toml.test.js
index ecf0f5f8a..44141b2d4 100644
--- a/integration/bunjs-only-snippets/toml.test.js
+++ b/integration/bunjs-only-snippets/toml.test.js
@@ -1,7 +1,12 @@
import { describe, it, expect } from "bun:test";
+import { gc } from "./gc";
it("syntax", async () => {
+ gc();
+
const toml = (await import("./toml-fixture.toml")).default;
+ gc();
+
expect(toml.framework).toBe("next");
expect(toml.bundle.packages["@emotion/react"]).toBe(true);
expect(toml.array[0].entry_one).toBe("one");
@@ -21,4 +26,5 @@ it("syntax", async () => {
"https://registry.mybigcompany.com"
);
expect(toml.install.scopes["@mybigcompany3"].three).toBe(4);
+ gc();
});
diff --git a/integration/bunjs-only-snippets/unsafe.test.js b/integration/bunjs-only-snippets/unsafe.test.js
index d47821f42..741dc0241 100644
--- a/integration/bunjs-only-snippets/unsafe.test.js
+++ b/integration/bunjs-only-snippets/unsafe.test.js
@@ -1,25 +1,26 @@
import { test, expect, it, describe } from "bun:test";
+import { gc } from "./gc";
it("arrayBufferToString u8", async () => {
var encoder = new TextEncoder();
const bytes = encoder.encode("hello world");
- Bun.gc(true);
+ gc(true);
expect(Bun.unsafe.arrayBufferToString(bytes)).toBe("hello world");
- Bun.gc(true);
+ gc(true);
await new Promise((resolve) => setTimeout(resolve, 0));
- Bun.gc(true);
+ gc(true);
});
it("arrayBufferToString ArrayBuffer", async () => {
var encoder = new TextEncoder();
var bytes = encoder.encode("hello world");
- Bun.gc(true);
+ gc(true);
const out = Bun.unsafe.arrayBufferToString(bytes.buffer);
expect(out).toBe("hello world");
- Bun.gc(true);
+ gc(true);
await new Promise((resolve) => setTimeout(resolve, 0));
globalThis.bytes = bytes;
- Bun.gc(true);
+ gc(true);
expect(out).toBe("hello world");
});
@@ -32,13 +33,13 @@ it("arrayBufferToString u16", () => {
.arrayBufferToString(uint16)
.split("")
.map((a) => a.charCodeAt(0));
- Bun.gc(true);
+ gc(true);
for (let i = 0; i < charCodes.length; i++) {
expect("hello world"[i]).toBe(String.fromCharCode(charCodes[i]));
}
- Bun.gc(true);
+ gc(true);
expect(charCodes.length).toBe("hello world".length);
- Bun.gc(true);
+ gc(true);
});
it("Bun.allocUnsafe", () => {