Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ describe('opfsSiteStorage', () => {
let storage: NonNullable<typeof exportedOpfsSiteStorage>;
let loadPersistedBlueprintBundle: ReturnType<typeof vi.fn>;
let loadPersistedBlueprintBundleFromPath: ReturnType<typeof vi.fn>;
let loggerError: ReturnType<typeof vi.fn>;

beforeEach(async () => {
vi.resetModules();
loadPersistedBlueprintBundle = vi.fn();
loadPersistedBlueprintBundleFromPath = vi.fn();
loggerError = vi.fn();
const activeWorkerWrites = new Set<string>();
opfsRoot = new MemoryDirectoryHandle('');
vi.stubGlobal('navigator', {
Expand Down Expand Up @@ -73,6 +75,9 @@ describe('opfsSiteStorage', () => {
vi.doMock('@wp-playground/blueprints', () => ({
getBlueprintDeclaration: vi.fn(async (blueprint) => blueprint),
}));
vi.doMock('@php-wasm/logger', () => ({
logger: { error: loggerError },
}));
Comment thread
adamziel marked this conversation as resolved.

const module = await import('./opfs-site-storage');
storage = module.opfsSiteStorage!;
Expand Down Expand Up @@ -107,6 +112,14 @@ describe('opfsSiteStorage', () => {
).rejects.toThrow("Site with slug 'a/b' already exists.");
});

it('silently skips directories left by interrupted first saves', async () => {
const sitesRoot = await getSitesRoot(opfsRoot);
await sitesRoot.getDirectoryHandle('site-incomplete', { create: true });
Comment thread
adamziel marked this conversation as resolved.

await expect(storage.list()).resolves.toEqual([]);
expect(loggerError).not.toHaveBeenCalled();
});

it('stores setup URL params alongside site metadata', async () => {
const originalUrlParams = {
searchParams: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ class OpfsSiteStorage {
sites.push(site);
}
} catch (e) {
if (isMissingOpfsEntry(e)) {
// An interrupted first save can leave the directory behind
// before its metadata file is written.
continue;
}
// @TODO: Still return this site's info, just in an error state.
logger.error(`Error reading site ${entry.name}:`, e);
// @TODO: Handle per-site errors somehow.
Expand Down
Loading