mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 04:49:06 +00:00
disable test on windows due to rename not having posix semantics
This commit is contained in:
@@ -2,10 +2,14 @@ import { expect } from "bun:test";
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { devTest } from "../bake-harness";
|
||||
import { isWindows } from "harness";
|
||||
|
||||
devTest("vim file swap hot reload for entrypoints", {
|
||||
files: {
|
||||
"index.html": `<!DOCTYPE html>
|
||||
// skip on windows due to EPERM issues since we use libuv for uv_fs_rename and
|
||||
// it doesn't appaer to use posix semantics
|
||||
if (!isWindows) {
|
||||
devTest("vim file swap hot reload for entrypoints", {
|
||||
files: {
|
||||
"index.html": `<!DOCTYPE html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
@@ -13,20 +17,20 @@ devTest("vim file swap hot reload for entrypoints", {
|
||||
<p>Test foo</p>
|
||||
<script type="module" src="index.ts"></script>
|
||||
</body>`,
|
||||
"index.ts": ``,
|
||||
},
|
||||
async test(dev) {
|
||||
await using c = await dev.client("/");
|
||||
"index.ts": ``,
|
||||
},
|
||||
async test(dev) {
|
||||
await using c = await dev.client("/");
|
||||
|
||||
// Verify initial load works
|
||||
const initialResponse = await dev.fetch("/");
|
||||
expect(initialResponse.status).toBe(200);
|
||||
const initialText = await initialResponse.text();
|
||||
expect(initialText).toContain("Test foo");
|
||||
// Verify initial load works
|
||||
const initialResponse = await dev.fetch("/");
|
||||
expect(initialResponse.status).toBe(200);
|
||||
const initialText = await initialResponse.text();
|
||||
expect(initialText).toContain("Test foo");
|
||||
|
||||
// Simulate vim-style file editing multiple times to increase reliability
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const updatedContent = `<!DOCTYPE html>
|
||||
// Simulate vim-style file editing multiple times to increase reliability
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const updatedContent = `<!DOCTYPE html>
|
||||
<head>
|
||||
<title>Test</title>
|
||||
</head>
|
||||
@@ -35,25 +39,26 @@ devTest("vim file swap hot reload for entrypoints", {
|
||||
<script type="module" src="index.ts"></script>
|
||||
</body>`;
|
||||
|
||||
// Step 1: Create .index.html.swp file with new content
|
||||
const swapFile = path.join(dev.rootDir, ".index.html.swp");
|
||||
await Bun.file(swapFile).write(updatedContent);
|
||||
// Step 1: Create .index.html.swp file with new content
|
||||
const swapFile = path.join(dev.rootDir, ".index.html.swp");
|
||||
await Bun.file(swapFile).write(updatedContent);
|
||||
|
||||
// Step 2: Delete original index.html
|
||||
const originalFile = path.join(dev.rootDir, "index.html");
|
||||
fs.unlinkSync(originalFile);
|
||||
// Step 2: Delete original index.html
|
||||
const originalFile = path.join(dev.rootDir, "index.html");
|
||||
fs.unlinkSync(originalFile);
|
||||
|
||||
// Step 3: Rename .index.html.swp to index.html (atomic operation)
|
||||
fs.renameSync(swapFile, originalFile);
|
||||
// Step 3: Rename .index.html.swp to index.html (atomic operation)
|
||||
fs.renameSync(swapFile, originalFile);
|
||||
|
||||
// Wait a bit for file watcher to detect changes
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
// Wait a bit for file watcher to detect changes
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
||||
// Verify the content was updated
|
||||
const response = await dev.fetch("/");
|
||||
expect(response.status).toBe(200);
|
||||
const text = await response.text();
|
||||
expect(text).toContain(`Test bar ${i + 1}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
// Verify the content was updated
|
||||
const response = await dev.fetch("/");
|
||||
expect(response.status).toBe(200);
|
||||
const text = await response.text();
|
||||
expect(text).toContain(`Test bar ${i + 1}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user