new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vitest · Config reference · all subjects

out of scope

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

File system mocking recommendation

Vitest does not provide a file system mocking API out of the box. While you can use vi.mock to mock the fs module manually, it is hard to maintain. Vitest recommends using memfs to mock the file system instead, which creates an in-memory file system that simulates file system operations without touching the actual disk.

memfs __mocks__ file structure for fs

To automatically redirect every fs call to memfs, create __mocks__/fs.cjs at the root of the project. The file should require memfs and export fs: const { fs } = require('memfs'); module.exports = fs;

memfs __mocks__ file structure for fs/promises

To automatically redirect every fs/promises call to memfs, create __mocks__/fs/promises.cjs at the root of the project. The file should require memfs and export fs.promises: const { fs } = require('memfs'); module.exports = fs.promises;

vi.mock for fs in tests

In test files, call vi.mock('node:fs') and vi.mock('node:fs/promises') to tell Vitest to use the fs mock from the __mocks__ folder. This can also be done in a setup file if fs should always be mocked.

memfs vol.reset usage

Use vol.reset() in a beforeEach hook to reset the state of the in-memory file system between tests.

memfs vol.fromJSON usage

Use vol.fromJSON to define multiple files at once in the in-memory file system. It takes an object mapping file paths to file contents, and an optional cwd parameter specifying the default working directory. Example: vol.fromJSON({ './dir1/hw.txt': 'hello dir1', './dir2/hw.txt': 'hello dir2' }, '/tmp');

Give your agent this brain