https://github.com/front-of-house/afix
Tiny fixture utility.
https://github.com/front-of-house/afix
Last synced: 26 days ago
JSON representation
Tiny fixture utility.
- Host: GitHub
- URL: https://github.com/front-of-house/afix
- Owner: front-of-house
- Created: 2021-06-15T02:29:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-01-06T23:34:31.000Z (over 3 years ago)
- Last Synced: 2025-03-04T07:18:13.003Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 167 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# afix
[](https://www.npmjs.com/package/afix) [](https://coveralls.io/github/sure-thing/afix?branch=main) [](https://bundlephobia.com/result?p=afix)
Tiny fixture utility.
```
npm i afix
```## Usage
Each call to `afix()` creates a new directory in `process.cwd()` and writes
files within the new directory.```typescript
import fs from 'fs'
import { afix } from 'afix'const fixture = afix({
config: ['config.js', 'export default { foo: true }'],
nested: ['some/path/file.js'],
})
const dir = fixture.mkdir('/some/dir')fs.existsSync(fixture.root) // true
fs.existsSync(fixture.files.config.path) // true
assert.equal(fs.readFileSync(fixture.files.config.path, 'utf8'), fixture.files.config.content)fs.existsSync(fixture.files.nested.path) // true
assert.equal(fs.readFileSync(fixture.files.nested.path, 'utf8'), fixture.files.nested.content)fs.existsSync(dir) // true
// remove fixture.root
fixture.cleanup()fs.existsSync(fixture.root) // false
```Plus, fixtures are automaticaly removed when the process exits.
## License
MIT License © [Sure Thing](https://github.com/sure-thing)