# test.build/core/persistence/journal.persistence.test.ts

> 23 lines of code and 0 definitions.

Tree: Codebase Testing
Language: typescript
Canonical: https://banes-lab.com/anatomy/testing#file-testing-test-build-core-persistence-journal-persistence-test-ts
Source text: https://banes-lab.com/source/testing/test.build/core/persistence/journal.persistence.test.ts.txt

Listed in [test.build/core/persistence](https://banes-lab.com/api/source/testing/test.build/core/persistence.md), after [test.build/core/persistence/icons.persistence.test.ts](https://banes-lab.com/source/testing/test.build/core/persistence/icons.persistence.test.ts.md) and before [test.build/core/persistence/page.persistence.test.ts](https://banes-lab.com/source/testing/test.build/core/persistence/page.persistence.test.ts.md).

## Contained in

- [test.build/core/persistence](https://banes-lab.com/anatomy/testing/folder-testing-test-build-core-persistence.md)

## Source

```typescript
import { describe, expect, it } from "vitest";
import { mkdtempSync, rmSync } from "node:fs";
import { persistJournal, readJournal } from "@banes-lab/build-scripts/core/persistence/journal.persistence.ts";
import { EMPTY_JOURNAL } from "@banes-lab/build-scripts/core/converters/journal.converter.ts";
import { join } from "node:path";
import { tmpdir } from "node:os";

describe("readJournal and persistJournal", () => {
    it("reads nothing where no journal was written, and reads back what was written", async () => {
        const dir = mkdtempSync(join(tmpdir(), "journal-"));
        try {
            const file = join(dir, "journal.generated.json");
            expect(readJournal(file)).toStrictEqual(EMPTY_JOURNAL);
            const journal = {
                moved: { "architecture:x": { json: "/json/records/architecture/x", to: null } },
                refs: {},
            };
            await persistJournal(journal, file);
            expect(readJournal(file)).toStrictEqual(journal);
        } finally {
            rmSync(dir, { force: true, recursive: true });
        }
    });
});
```
