aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Alex Lam S.L <alexlamsl@gmail.com> 2023-07-18 14:54:24 +0300
committerGravatar GitHub <noreply@github.com> 2023-07-18 04:54:24 -0700
commit179035702156bd7fa9f17bc7db1be2000219f787 (patch)
tree05873629066ba00f2c7fcf2c0fc9b9c1a5d15c12 /test
parent105919d7ae9681d9be18401b032128bf826a39d3 (diff)
downloadbun-179035702156bd7fa9f17bc7db1be2000219f787.tar.gz
bun-179035702156bd7fa9f17bc7db1be2000219f787.tar.zst
bun-179035702156bd7fa9f17bc7db1be2000219f787.zip
[jest] execute lifecycle hooks on empty blocks (#3663)
fixes #3494
Diffstat (limited to 'test')
-rw-r--r--test/js/bun/test/test-test.test.ts64
1 files changed, 53 insertions, 11 deletions
diff --git a/test/js/bun/test/test-test.test.ts b/test/js/bun/test/test-test.test.ts
index 2f824a9d0..af2a143b5 100644
--- a/test/js/bun/test/test-test.test.ts
+++ b/test/js/bun/test/test-test.test.ts
@@ -27,7 +27,7 @@ it("shouldn't crash when async test runner callback throws", async () => {
})
`;
- const test_dir = realpathSync(await mkdtemp(join(tmpdir(), "test")));
+ const test_dir = await mkdtemp(join(tmp, "test"));
try {
await writeFile(join(test_dir, "bad.test.js"), code);
const { stdout, stderr, exited } = spawn({
@@ -247,7 +247,7 @@ test("test async exceptions fail tests", () => {
});
`;
- const dir = join(tmpdir(), "test-throwing-bun");
+ const dir = join(tmp, "test-throwing-bun");
const filepath = join(dir, "test-throwing-eventemitter.test.js");
rmSync(filepath, {
force: true,
@@ -259,7 +259,7 @@ test("test async exceptions fail tests", () => {
writeFileSync(filepath, code);
const { stderr, exitCode } = spawnSync([bunExe(), "test", "test-throwing-eventemitter"], {
- cwd: realpathSync(dir),
+ cwd: dir,
env: bunEnv,
});
@@ -277,7 +277,7 @@ test("test async exceptions fail tests", () => {
});
it("should return non-zero exit code for invalid syntax", async () => {
- const test_dir = realpathSync(await mkdtemp(join(tmpdir(), "test")));
+ const test_dir = await mkdtemp(join(tmp, "test"));
try {
await writeFile(join(test_dir, "bad.test.js"), "!!!");
const { stdout, stderr, exited } = spawn({
@@ -302,7 +302,7 @@ it("should return non-zero exit code for invalid syntax", async () => {
});
it("invalid syntax counts towards bail", async () => {
- const test_dir = realpathSync(await mkdtemp(join(tmpdir(), "test")));
+ const test_dir = await mkdtemp(join(tmp, "test"));
try {
await writeFile(join(test_dir, "bad1.test.js"), "!!!");
await writeFile(join(test_dir, "bad2.test.js"), "!!!");
@@ -483,7 +483,7 @@ it("test.todo", () => {
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
const err = stderr!.toString();
expect(err).toContain("this test is marked as todo but passes");
@@ -504,7 +504,7 @@ it("test.todo doesnt cause exit code 1", () => {
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
const err = stderr!.toString();
@@ -519,7 +519,7 @@ it("test timeouts when expected", () => {
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
const err = stderr!.toString();
@@ -535,7 +535,7 @@ it("expect().toEqual() on objects with property indices doesn't print undefined"
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
let err = stderr!.toString();
@@ -555,7 +555,7 @@ it("test --preload supports global lifecycle hooks", () => {
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
expect(stdout.toString().trim()).toBe(
`
@@ -595,10 +595,52 @@ it("skip() and skipIf()", () => {
stdout: "pipe",
stderr: "pipe",
env: bunEnv,
- cwd: realpathSync(dirname(path)),
+ cwd: dirname(path),
});
const result = stdout!.toString();
expect(result).not.toContain("unreachable");
expect(result).toMatch(/reachable/);
expect(result.match(/reachable/g)).toHaveLength(6);
});
+
+it("should run beforeAll() & afterAll() even without tests", async () => {
+ const test_dir = await mkdtemp(join(tmp, "test-hooks-empty"));
+ try {
+ await writeFile(
+ join(test_dir, "empty.test.js"),
+ `
+beforeAll(() => console.log("???BEFORE ALL???"));
+afterAll(() => console.log("!!!AFTER ALL!!!"));
+
+describe("empty", () => {
+ beforeAll(() => console.log(">>>BEFORE ALL>>>"));
+ afterAll(() => console.log("<<<AFTER ALL<<<"));
+});
+ `,
+ );
+ const { stdout, stderr, exited } = spawn({
+ cmd: [bunExe(), "test", "empty.test.js"],
+ cwd: test_dir,
+ stdout: null,
+ stdin: "pipe",
+ stderr: "pipe",
+ env: bunEnv,
+ });
+ expect(stderr).toBeDefined();
+ const err = await new Response(stderr).text();
+ expect(err).toContain("0 pass");
+ expect(err).toContain("0 fail");
+ expect(stdout).toBeDefined();
+ const out = await new Response(stdout).text();
+ expect(out.split(/\r?\n/)).toEqual([
+ "???BEFORE ALL???",
+ ">>>BEFORE ALL>>>",
+ "<<<AFTER ALL<<<",
+ "!!!AFTER ALL!!!",
+ "",
+ ]);
+ expect(await exited).toBe(0);
+ } finally {
+ await rm(test_dir, { force: true, recursive: true });
+ }
+});