-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b73f78
commit 1db2371
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/scripts/src/commands/app-data/convert/cacheStrategy/jsonFile.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { TimeLike } from "fs"; | ||
import { JsonFileCache } from "./jsonFile"; | ||
import { IContentsEntry } from "shared"; | ||
|
||
interface IContentsEntryWithValue extends IContentsEntry { | ||
value?: any; | ||
} | ||
|
||
/** | ||
* Mock implementation of JsonFileCache that only uses in-memory caching | ||
* instead of persisting files to disk | ||
*/ | ||
export class MockJsonFileCache extends JsonFileCache { | ||
private mockContents: Record<string, IContentsEntryWithValue> = {}; | ||
|
||
constructor() { | ||
super("", 0); | ||
} | ||
|
||
public add(data: any, entryName?: string, stats?: { mtime: TimeLike }) { | ||
if (data) { | ||
if (!entryName) { | ||
entryName = this.generateCacheEntryName(data); | ||
} | ||
if (!this.mockContents[entryName]) { | ||
this.mockContents[entryName] = {} as any; | ||
} | ||
this.mockContents[entryName].value = data; | ||
return { filePath: entryName, entryName, data }; | ||
} | ||
} | ||
|
||
public clear() { | ||
this.mockContents = {}; | ||
} | ||
|
||
public remove(entryName: string) { | ||
if (this.mockContents.hasOwnProperty(entryName)) { | ||
delete this.mockContents[entryName]; | ||
} | ||
} | ||
|
||
public get<T = any>(entryName: string) { | ||
return this.mockContents[entryName] as T; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters