mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 02:48:50 +00:00
bun run prettier
This commit is contained in:
committed by
github-actions[bot]
parent
eac2f0dc8d
commit
577fc18fd9
@@ -1,19 +1,19 @@
|
||||
import { test, expect } from "bun:test";
|
||||
import { AsyncLocalStorage } from "async_hooks";
|
||||
import { expect, test } from "bun:test";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { tmpdir } from "os";
|
||||
import path from "path";
|
||||
|
||||
test("fs.watch preserves AsyncLocalStorage context", async () => {
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
const testFile = path.join(tmpdir(), "test-watch-async-context.txt");
|
||||
|
||||
|
||||
// Create test file
|
||||
fs.writeFileSync(testFile, "initial content");
|
||||
|
||||
|
||||
try {
|
||||
const contextValue = { userId: "user123", requestId: "req456" };
|
||||
|
||||
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
asyncLocalStorage.run(contextValue, () => {
|
||||
const watcher = fs.watch(testFile, (eventType, filename) => {
|
||||
@@ -23,7 +23,7 @@ test("fs.watch preserves AsyncLocalStorage context", async () => {
|
||||
expect(context).toEqual(contextValue);
|
||||
expect(context.userId).toBe("user123");
|
||||
expect(context.requestId).toBe("req456");
|
||||
|
||||
|
||||
watcher.close();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
@@ -31,14 +31,14 @@ test("fs.watch preserves AsyncLocalStorage context", async () => {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Trigger the watcher by modifying the file
|
||||
setTimeout(() => {
|
||||
fs.writeFileSync(testFile, "modified content");
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
await promise;
|
||||
} finally {
|
||||
// Clean up
|
||||
@@ -51,10 +51,10 @@ test("fs.watch preserves AsyncLocalStorage context", async () => {
|
||||
test("fs.watch without AsyncLocalStorage context", async () => {
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
const testFile = path.join(tmpdir(), "test-watch-no-context.txt");
|
||||
|
||||
|
||||
// Create test file
|
||||
fs.writeFileSync(testFile, "initial content");
|
||||
|
||||
|
||||
try {
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
// Set up watcher outside of AsyncLocalStorage context
|
||||
@@ -63,7 +63,7 @@ test("fs.watch without AsyncLocalStorage context", async () => {
|
||||
// Should have no context
|
||||
const context = asyncLocalStorage.getStore();
|
||||
expect(context).toBeUndefined();
|
||||
|
||||
|
||||
watcher.close();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
@@ -71,13 +71,13 @@ test("fs.watch without AsyncLocalStorage context", async () => {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Trigger the watcher by modifying the file
|
||||
setTimeout(() => {
|
||||
fs.writeFileSync(testFile, "modified content");
|
||||
}, 10);
|
||||
});
|
||||
|
||||
|
||||
await promise;
|
||||
} finally {
|
||||
// Clean up
|
||||
@@ -90,14 +90,14 @@ test("fs.watch without AsyncLocalStorage context", async () => {
|
||||
test("fs.watch nested AsyncLocalStorage context", async () => {
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
const testFile = path.join(tmpdir(), "test-watch-nested-context.txt");
|
||||
|
||||
|
||||
// Create test file
|
||||
fs.writeFileSync(testFile, "initial content");
|
||||
|
||||
|
||||
try {
|
||||
const outerContext = { level: "outer", value: 1 };
|
||||
const innerContext = { level: "inner", value: 2 };
|
||||
|
||||
|
||||
const promise = new Promise<void>((resolve, reject) => {
|
||||
asyncLocalStorage.run(outerContext, () => {
|
||||
asyncLocalStorage.run(innerContext, () => {
|
||||
@@ -108,7 +108,7 @@ test("fs.watch nested AsyncLocalStorage context", async () => {
|
||||
expect(context).toEqual(innerContext);
|
||||
expect(context.level).toBe("inner");
|
||||
expect(context.value).toBe(2);
|
||||
|
||||
|
||||
watcher.close();
|
||||
resolve();
|
||||
} catch (error) {
|
||||
@@ -116,7 +116,7 @@ test("fs.watch nested AsyncLocalStorage context", async () => {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Trigger the watcher by modifying the file
|
||||
setTimeout(() => {
|
||||
fs.writeFileSync(testFile, "modified content");
|
||||
@@ -124,7 +124,7 @@ test("fs.watch nested AsyncLocalStorage context", async () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
await promise;
|
||||
} finally {
|
||||
// Clean up
|
||||
@@ -132,4 +132,4 @@ test("fs.watch nested AsyncLocalStorage context", async () => {
|
||||
fs.unlinkSync(testFile);
|
||||
} catch {}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user