Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 8523580

Browse files
committed
Fix resolves persist path relative to rootPath tests on Windows
1 parent 8c23cd9 commit 8523580

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

packages/cache/test/plugin.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "assert";
2+
import path from "path";
23
import {
34
CacheError,
45
CachePlugin,
@@ -20,6 +21,7 @@ import {
2021
logPluginOptions,
2122
parsePluginArgv,
2223
parsePluginWranglerConfig,
24+
useTmp,
2325
utf8Decode,
2426
} from "@miniflare/shared-test";
2527
import test from "ava";
@@ -161,11 +163,14 @@ test("CachePlugin: setup: includes CacheStorage in globals", async (t) => {
161163
t.true((await caches.open("test")) instanceof NoOpCache);
162164
});
163165
test("CachePlugin: setup: resolves persist path relative to rootPath", async (t) => {
166+
const tmp = await useTmp(t);
164167
const map = new Map<string, StoredValueMeta<CachedMeta>>();
165-
const factory = new MemoryStorageFactory({ ["/root/test:default"]: map });
168+
const factory = new MemoryStorageFactory({
169+
[`${tmp}${path.sep}test:default`]: map,
170+
});
166171

167172
const plugin = new CachePlugin(
168-
{ log, compat, rootPath: "/root" },
173+
{ log, compat, rootPath: tmp },
169174
{ cachePersist: "test" }
170175
);
171176
plugin.setup(factory);

packages/durable-objects/test/plugin.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "path";
12
import { setImmediate } from "timers/promises";
23
import { Response } from "@miniflare/core";
34
import {
@@ -17,6 +18,7 @@ import {
1718
logPluginOptions,
1819
parsePluginArgv,
1920
parsePluginWranglerConfig,
21+
useTmp,
2022
} from "@miniflare/shared-test";
2123
import test from "ava";
2224
import { TestObject, testId } from "./object";
@@ -108,13 +110,14 @@ test("DurableObjectsPlugin: getObject: object storage is namespaced by object na
108110
await state.storage.put("key", "value");
109111
t.true(map.has("key"));
110112
});
111-
test("DurableObjectsPlugin: getObject: resolves persist path relative to rootPath", async (t) => {
113+
test("DurableObjectsPlugin: getObject: reresolves persist path relative to rootPath", async (t) => {
114+
const tmp = await useTmp(t);
112115
const map = new Map<string, StoredValue>();
113116
const factory = new MemoryStorageFactory({
114-
[`/root/test:TEST:${testId.toString()}`]: map,
117+
[`${tmp}${path.sep}test:TEST:${testId.toString()}`]: map,
115118
});
116119
const plugin = new DurableObjectsPlugin(
117-
{ log, compat, rootPath: "/root" },
120+
{ log, compat, rootPath: tmp },
118121
{
119122
durableObjects: { TEST: "TestObject" },
120123
durableObjectsPersist: "test",

packages/kv/test/plugin.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import assert from "assert";
2+
import path from "path";
23
import { KVNamespace, KVPlugin } from "@miniflare/kv";
34
import {
45
Compatibility,
@@ -11,6 +12,7 @@ import {
1112
logPluginOptions,
1213
parsePluginArgv,
1314
parsePluginWranglerConfig,
15+
useTmp,
1416
} from "@miniflare/shared-test";
1517
import test from "ava";
1618

@@ -74,11 +76,14 @@ test("KVPlugin: getNamespace: creates namespace", async (t) => {
7476
t.true(map.has("key"));
7577
});
7678
test("KVPlugin: getNamespace: resolves persist path relative to rootPath", async (t) => {
79+
const tmp = await useTmp(t);
7780
const map = new Map<string, StoredValueMeta>();
78-
const factory = new MemoryStorageFactory({ ["/root/test:NAMESPACE"]: map });
81+
const factory = new MemoryStorageFactory({
82+
[`${tmp}${path.sep}test:NAMESPACE`]: map,
83+
});
7984

8085
const plugin = new KVPlugin(
81-
{ log, compat, rootPath: "/root" },
86+
{ log, compat, rootPath: tmp },
8287
{ kvPersist: "test" }
8388
);
8489
const namespace = await plugin.getNamespace(factory, "NAMESPACE");

packages/shared/test/data.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
viewToArray,
1515
viewToBuffer,
1616
} from "@miniflare/shared";
17+
import { useTmp } from "@miniflare/shared-test";
1718
import test from "ava";
1819

1920
test("nonCircularClone: creates copy of data", (t) => {
@@ -76,9 +77,11 @@ test("titleCase: converts string from PascalCase or camelCase to Title Case", (t
7677
t.is(titleCase("optionOneName"), "Option One Name");
7778
});
7879

79-
test("resolveStoragePersist: resolves file system paths relative to root", (t) => {
80-
t.is(resolveStoragePersist("/root", "data"), "/root/data");
81-
t.is(resolveStoragePersist("/root", "/another/root"), "/another/root");
80+
test("resolveStoragePersist: resolves file system paths relative to root", async (t) => {
81+
const tmp = await useTmp(t);
82+
const tmp2 = await useTmp(t);
83+
t.is(resolveStoragePersist(tmp, "data"), path.resolve(tmp, "data"));
84+
t.is(resolveStoragePersist(tmp, tmp2), tmp2);
8285
});
8386
test("resolveStoragePersist: leaves other paths untouched", (t) => {
8487
t.is(resolveStoragePersist("/root"), undefined);

0 commit comments

Comments
 (0)