Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Jul 2, 2023
1 parent 4ecc1b2 commit 362898c
Show file tree
Hide file tree
Showing 3 changed files with 4,355 additions and 11,912 deletions.
194 changes: 1 addition & 193 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,196 +77,4 @@ test('eslint reports lint errors', async () => {

## API documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

- [createIFF][1]
- [Parameters][2]
- [CreateIFFResult#paths][3]
- [CreateIFFResult#join][4]
- [CreateIFFResult#addFixtures][5]
- [Parameters][6]
- [CreateIFFResult#fork][7]
- [Parameters][8]
- [CreateIFFResult#rmRootDir][9]
- [CreateIFFResult#rmFixtures][10]
- [CreateIFFResult#rootDir][11]
- [CreateIFFOptions#rootDir][12]
- [AddFixturesResult#paths][13]
- [AddFixturesResult#paths][14]

### createIFF

Create fixtures in the specified directory.
The path separator must be in POSIX format (`/`).
Use of Windows path separator is an undefined behavior.

```ts
const iff = await createIFF(
{
'a.txt': 'a',
'b': {
'a.txt': 'b-a',
},
'c/a/a.txt': 'c-a-a',
},
fixturesDir,
);
```

#### Parameters

- `directory` **T** The definition of fixtures to be created.
- `options` **CreateIFFOptions** Options for creating fixtures.

Returns **[Promise][15]\\&lt;CreateIFFResult\\<T>>** An object that provides functions to manipulate the fixtures.

### CreateIFFResult#paths

The paths of the fixtures.
For example, if you create a fixture `a.txt`, then `iff.paths['a.txt'] === iff.join('a.txt')`.

```ts
const iff = await createIFF(
{
'a.txt': 'a',
'b': {
'a.txt': 'b-a',
},
'c/a/a.txt': 'c-a-a',
},
fixturesDir,
);
expect(iff.paths).toStrictEqual({
'a.txt': iff.join('a.txt'),
'b': iff.join('b'),
'b/a.txt': iff.join('b/a.txt'),
'c': iff.join('c'),
'c/a': iff.join('c/a'),
'c/a/a.txt': iff.join('c/a/a.txt'),
});
```

The `paths` keys are strictly typed. However, index signatures are excluded for convenience.

```ts
const iff = await createIFF(
{
'a.txt': 'a',
'b': {
'a.txt': 'b-a',
},
['c.txt' as string]: 'c',
['d' as string]: {
'a.txt': 'd-a',
},
},
fixturesDir,
);
expectType<{
'a.txt': string;
'b': string;
'b/a.txt': string;
}>(iff.paths);
```

### CreateIFFResult#join

Join `rootDir` and `paths`.
That is, it is equivalent to `require('path').join(rootDir, ...paths)`.

### CreateIFFResult#addFixtures

Add fixtures to `rootDir`.

#### Parameters

- `directory` The definition of fixtures to be added.

Returns **any** The paths to fixtures created with `createIFF` and added with `CreateIFFResult#addFixtures`.

### CreateIFFResult#fork

Change the root directory and take over the fixture you created.

Internally, first a new root directory is created, and then the fixtures from the old root directory are copied into it.
Finally, the fixtures specified in `additionalDirectory` are added to the new root directory.

The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write,
then a fallback copy mechanism is used.

Example:

```ts
const baseIff = await createIFF({
'a.txt': 'a',
'b/a.txt': 'b-a',
},
}, { rootDir: baseRootDir });
const forkedIff = await baseIff.fork({
'b/b.txt': 'b-b',
'c.txt': 'c',
}, { rootDir: forkedRootDir });

// `forkedIff` inherits fixtures from `baseIff`.
expect(await readFile(join(forkedRootDir, 'a.txt'), 'utf-8')).toBe('a');
expect(await readFile(join(forkedRootDir, 'b/a.txt'), 'utf-8')).toBe('b-a');
expect(await readFile(join(forkedRootDir, 'b/b.txt'), 'utf-8')).toBe('b-b');
expect(await readFile(join(forkedRootDir, 'c.txt'), 'utf-8')).toBe('c');

// The `baseIff` fixtures are left in place.
expect(await readFile(join(baseRootDir, 'a.txt'), 'utf-8')).toBe('a');
expect(await readFile(join(baseRootDir, 'b/a.txt'), 'utf-8')).toBe('b-a');
```

#### Parameters

- `additionalDirectory` The definition of fixtures to be added.
- `options` Options for creating fixtures.

### CreateIFFResult#rmRootDir

Delete `rootDir`.

### CreateIFFResult#rmFixtures

Delete fixtures under `rootDir`.

### CreateIFFResult#rootDir

The directory where fixtures are written.
This directory is obtained by processing the directory specified in `CreateIFFOptions#rootDir`
using `path.resolve`.

### CreateIFFOptions#rootDir

Root directory for fixtures.

### AddFixturesResult#paths

- **See**: CreateIFFResult#paths

The paths of the added fixtures.

### AddFixturesResult#paths

- **See**: CreateIFFResult#paths

The paths of the added fixtures.

[1]: #createiff
[2]: #parameters
[3]: #createiffresultpaths
[4]: #createiffresultjoin
[5]: #createiffresultaddfixtures
[6]: #parameters-1
[7]: #createiffresultfork
[8]: #parameters-2
[9]: #createiffresultrmrootdir
[10]: #createiffresultrmfixtures
[11]: #createiffresultrootdir
[12]: #createiffoptionsrootdir
[13]: #addfixturesresultpaths
[14]: #addfixturesresultpaths-1
[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
See [/docs/api/index.md](/docs/api/index.md).
Loading

0 comments on commit 362898c

Please sign in to comment.