Skip to content

Commit

Permalink
Fix resolves persist path relative to rootPath tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbbot committed Nov 22, 2021
1 parent 8c23cd9 commit 8523580
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
9 changes: 7 additions & 2 deletions packages/cache/test/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "assert";
import path from "path";
import {
CacheError,
CachePlugin,
Expand All @@ -20,6 +21,7 @@ import {
logPluginOptions,
parsePluginArgv,
parsePluginWranglerConfig,
useTmp,
utf8Decode,
} from "@miniflare/shared-test";
import test from "ava";
Expand Down Expand Up @@ -161,11 +163,14 @@ test("CachePlugin: setup: includes CacheStorage in globals", async (t) => {
t.true((await caches.open("test")) instanceof NoOpCache);
});
test("CachePlugin: setup: resolves persist path relative to rootPath", async (t) => {
const tmp = await useTmp(t);
const map = new Map<string, StoredValueMeta<CachedMeta>>();
const factory = new MemoryStorageFactory({ ["/root/test:default"]: map });
const factory = new MemoryStorageFactory({
[`${tmp}${path.sep}test:default`]: map,
});

const plugin = new CachePlugin(
{ log, compat, rootPath: "/root" },
{ log, compat, rootPath: tmp },
{ cachePersist: "test" }
);
plugin.setup(factory);
Expand Down
9 changes: 6 additions & 3 deletions packages/durable-objects/test/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "path";
import { setImmediate } from "timers/promises";
import { Response } from "@miniflare/core";
import {
Expand All @@ -17,6 +18,7 @@ import {
logPluginOptions,
parsePluginArgv,
parsePluginWranglerConfig,
useTmp,
} from "@miniflare/shared-test";
import test from "ava";
import { TestObject, testId } from "./object";
Expand Down Expand Up @@ -108,13 +110,14 @@ test("DurableObjectsPlugin: getObject: object storage is namespaced by object na
await state.storage.put("key", "value");
t.true(map.has("key"));
});
test("DurableObjectsPlugin: getObject: resolves persist path relative to rootPath", async (t) => {
test("DurableObjectsPlugin: getObject: reresolves persist path relative to rootPath", async (t) => {
const tmp = await useTmp(t);
const map = new Map<string, StoredValue>();
const factory = new MemoryStorageFactory({
[`/root/test:TEST:${testId.toString()}`]: map,
[`${tmp}${path.sep}test:TEST:${testId.toString()}`]: map,
});
const plugin = new DurableObjectsPlugin(
{ log, compat, rootPath: "/root" },
{ log, compat, rootPath: tmp },
{
durableObjects: { TEST: "TestObject" },
durableObjectsPersist: "test",
Expand Down
9 changes: 7 additions & 2 deletions packages/kv/test/plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from "assert";
import path from "path";
import { KVNamespace, KVPlugin } from "@miniflare/kv";
import {
Compatibility,
Expand All @@ -11,6 +12,7 @@ import {
logPluginOptions,
parsePluginArgv,
parsePluginWranglerConfig,
useTmp,
} from "@miniflare/shared-test";
import test from "ava";

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

const plugin = new KVPlugin(
{ log, compat, rootPath: "/root" },
{ log, compat, rootPath: tmp },
{ kvPersist: "test" }
);
const namespace = await plugin.getNamespace(factory, "NAMESPACE");
Expand Down
9 changes: 6 additions & 3 deletions packages/shared/test/data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
viewToArray,
viewToBuffer,
} from "@miniflare/shared";
import { useTmp } from "@miniflare/shared-test";
import test from "ava";

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

test("resolveStoragePersist: resolves file system paths relative to root", (t) => {
t.is(resolveStoragePersist("/root", "data"), "/root/data");
t.is(resolveStoragePersist("/root", "/another/root"), "/another/root");
test("resolveStoragePersist: resolves file system paths relative to root", async (t) => {
const tmp = await useTmp(t);
const tmp2 = await useTmp(t);
t.is(resolveStoragePersist(tmp, "data"), path.resolve(tmp, "data"));
t.is(resolveStoragePersist(tmp, tmp2), tmp2);
});
test("resolveStoragePersist: leaves other paths untouched", (t) => {
t.is(resolveStoragePersist("/root"), undefined);
Expand Down

0 comments on commit 8523580

Please sign in to comment.