@zokugun/vitest-toolkit 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +143 -34
- package/lib/esm/build-cli-file-tests.d.mts +9 -0
- package/lib/esm/build-cli-file-tests.mjs +103 -0
- package/lib/esm/index.d.mts +4 -0
- package/lib/esm/index.mjs +4 -0
- package/lib/esm/mock-cli-file-tests.d.mts +2 -0
- package/lib/esm/mock-cli-file-tests.mjs +65 -0
- package/lib/esm/mocks/index.d.mts +1 -0
- package/lib/esm/mocks/index.mjs +1 -0
- package/lib/esm/mocks/memfs/index.d.mts +125 -0
- package/lib/esm/mocks/memfs/index.mjs +64 -0
- package/lib/esm/with-temp.d.mts +1 -0
- package/lib/esm/with-temp.mjs +18 -0
- package/package.json +101 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2026-present Baptiste Augrain
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,52 +1,161 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
[@zokugun/vitest-toolkit](https://github.com/zokugun/node-vitest-toolkit)
|
|
2
|
+
=========================================================================
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/@zokugun/vitest-toolkit)
|
|
6
|
+
[](#requirements)
|
|
7
|
+
[](#requirements)
|
|
8
|
+
[](https://ko-fi.com/daiyam)
|
|
9
|
+
[](https://liberapay.com/daiyam/donate)
|
|
10
|
+
[](https://paypal.me/daiyam99)
|
|
5
11
|
|
|
6
|
-
This
|
|
12
|
+
> This toolkit provides utilities for vitest
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
Features
|
|
15
|
+
--------
|
|
16
|
+
|
|
17
|
+
- **YAML Fixtures**: Generate tests automatically from external configuration files.
|
|
18
|
+
- **Virtual Filesystem**: Use in-memory storage to avoid slow disk I/O.
|
|
19
|
+
- **Output Validation**: Compare resulting file content against expected values.
|
|
20
|
+
- **Error Testing**: Verify that specific error messages are thrown as defined.
|
|
21
|
+
|
|
22
|
+
Installation
|
|
23
|
+
------------
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm add @zokugun/vitest-toolkit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Requirements
|
|
30
|
+
------------
|
|
31
|
+
|
|
32
|
+
- **Node.js**: `v18.20` or higher
|
|
33
|
+
- **Modules**: ECMAScript Modules (`ESM`)
|
|
34
|
+
|
|
35
|
+
Quick Start
|
|
36
|
+
-----------
|
|
37
|
+
|
|
38
|
+
API Reference
|
|
39
|
+
-------------
|
|
40
|
+
|
|
41
|
+
### Functions
|
|
42
|
+
|
|
43
|
+
#### buildCliFileTests
|
|
44
|
+
|
|
45
|
+
Generates Vitest tests from YAML fixture files in a directory. Each file maps to one test case.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
function buildCliFileTests(
|
|
49
|
+
action: (manifest: Record<string, unknown>) => unknown,
|
|
50
|
+
options?: Options
|
|
51
|
+
): void;
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Options:**
|
|
55
|
+
|
|
56
|
+
| Property | Type | Default | Description |
|
|
57
|
+
|---|---|---|---|
|
|
58
|
+
| `fixture` | `string` | `''` | Fixture directory name under `test/fixtures/` |
|
|
59
|
+
| `input` | `string` | `'input'` | Key prefix for input files in YAML |
|
|
60
|
+
| `output` | `string` | `'output'` | Key prefix for expected output files in YAML |
|
|
61
|
+
| `additionals` | `string[]` | `[]` | Extra key prefixes to treat as input files |
|
|
62
|
+
| `transformFile` | `(type, path, content) => string` | identity | Transform file content before loading into the mock FS |
|
|
63
|
+
|
|
64
|
+
**YAML manifest format:**
|
|
10
65
|
|
|
11
|
-
|
|
66
|
+
```yaml
|
|
67
|
+
# Test name is derived from the .yml filename (first segment only)
|
|
68
|
+
input/some-file.txt: "file contents"
|
|
69
|
+
output/result.txt: "expected output"
|
|
70
|
+
error: "expected error message" # optional, if present the test expects a throw
|
|
71
|
+
```
|
|
12
72
|
|
|
13
|
-
|
|
14
|
-
2. Enable secure, token-less publishing from CI/CD workflows
|
|
15
|
-
3. Establish provenance for packages published under this name
|
|
73
|
+
Paths starting with `/` are treated as virtual paths. The `input` and `additional` keys are loaded into an in-memory filesystem at `/working/<path>`. Output keys are checked after `action()` runs.
|
|
16
74
|
|
|
17
|
-
|
|
18
|
-
--------------------------------
|
|
75
|
+
If the manifest contains a top-level `error` string, the test expects `action(manifest)` to reject with that message. Otherwise it checks output files exist and match expected content.
|
|
19
76
|
|
|
20
|
-
|
|
77
|
+
Set `DEBUG=1` or `DEBUG=vol` in your environment to log filesystem state before/after the action runs.
|
|
21
78
|
|
|
22
|
-
|
|
23
|
-
------------------
|
|
79
|
+
---
|
|
24
80
|
|
|
25
|
-
|
|
81
|
+
#### mockCliFileTests / unmockCliFileTests
|
|
26
82
|
|
|
27
|
-
|
|
28
|
-
2. Configure the trusted publisher (e.g., GitHub Actions)
|
|
29
|
-
3. Specify the repository and workflow that should be allowed to publish
|
|
30
|
-
4. Use the configured workflow to publish your actual package
|
|
83
|
+
Replaces real file system and process modules with an in-memory mock for testing CLI tools.
|
|
31
84
|
|
|
32
|
-
|
|
33
|
-
|
|
85
|
+
```typescript
|
|
86
|
+
function mockCliFileTests(): void;
|
|
87
|
+
function unmockCliFileTests(): void;
|
|
88
|
+
```
|
|
34
89
|
|
|
35
|
-
|
|
90
|
+
`mockCliFileTests()` swaps:
|
|
91
|
+
- `node:fs` / `node:fs/promises` → memfs-backed mock
|
|
92
|
+
- `node:process` → fake process with `cwd() === '/working'` and empty `env`
|
|
93
|
+
- `@zokugun/cli-utils` → stripped logger that swallows output, throws on `fatal`, logs to console when `DEBUG` is set
|
|
36
94
|
|
|
37
|
-
|
|
38
|
-
- Provides no functionality
|
|
39
|
-
- Should not be installed as a dependency
|
|
40
|
-
- Exists only for administrative purposes
|
|
95
|
+
Call `mockCliFileTests()` before your test suite and `unmockCliFileTests()` after. Use them alongside `buildCliFileTests` for file-based CLI tests.
|
|
41
96
|
|
|
42
|
-
|
|
43
|
-
----------------
|
|
97
|
+
**Caveat:** These use `vi.doMock` / `vi.doUnmock`, which only affect modules loaded *after* the mock is set. If a module was already imported before calling `mockCliFileTests()`, it won't be affected. Call these at the top of your test file or in `beforeEach`.
|
|
44
98
|
|
|
45
|
-
|
|
99
|
+
---
|
|
46
100
|
|
|
47
|
-
|
|
48
|
-
|
|
101
|
+
#### withTemp
|
|
102
|
+
|
|
103
|
+
Runs a callback inside a temporary directory, then cleans up regardless of success or failure.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
function withTemp(
|
|
107
|
+
prefix: string,
|
|
108
|
+
run: (root: string) => Promise<void>
|
|
109
|
+
): Promise<void>;
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Creates a temp dir with the given prefix, changes into it, runs `run(root)`, then changes back to the original working directory and removes the temp dir. Works even if `run()` throws — cleanup always happens.
|
|
113
|
+
|
|
114
|
+
**Example:**
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
await withTemp('my-test-', async (root) => {
|
|
118
|
+
// root is the path to the temp dir
|
|
119
|
+
// process.chdir(root) was already called
|
|
120
|
+
});
|
|
121
|
+
// temp dir is gone now
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### mocks.memfs.fs
|
|
125
|
+
|
|
126
|
+
A drop-in replacement for Node's standard `fs` module, backed entirely by memory. You can use this directly if you need manual control over the virtual filesystem without using the CLI test generators.
|
|
127
|
+
|
|
128
|
+
Contributions
|
|
129
|
+
-------------
|
|
130
|
+
|
|
131
|
+
Contributions are most welcome. Please:
|
|
132
|
+
|
|
133
|
+
- Open issues and feature requests under the repository discussions.
|
|
134
|
+
- Follow the [`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
|
135
|
+
|
|
136
|
+
Donations
|
|
137
|
+
---------
|
|
138
|
+
|
|
139
|
+
Support this project by becoming a financial contributor.
|
|
140
|
+
|
|
141
|
+
<table>
|
|
142
|
+
<tr>
|
|
143
|
+
<td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_kofi.png" alt="Ko-fi" width="80px" height="80px"></td>
|
|
144
|
+
<td><a href="https://ko-fi.com/daiyam" target="_blank">ko-fi.com/daiyam</a></td>
|
|
145
|
+
</tr>
|
|
146
|
+
<tr>
|
|
147
|
+
<td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_liberapay.png" alt="Liberapay" width="80px" height="80px"></td>
|
|
148
|
+
<td><a href="https://liberapay.com/daiyam/donate" target="_blank">liberapay.com/daiyam/donate</a></td>
|
|
149
|
+
</tr>
|
|
150
|
+
<tr>
|
|
151
|
+
<td><img src="https://raw.githubusercontent.com/daiyam/assets/master/icons/256/funding_paypal.png" alt="PayPal" width="80px" height="80px"></td>
|
|
152
|
+
<td><a href="https://paypal.me/daiyam99" target="_blank">paypal.me/daiyam99</a></td>
|
|
153
|
+
</tr>
|
|
154
|
+
</table>
|
|
155
|
+
|
|
156
|
+
License
|
|
157
|
+
-------
|
|
49
158
|
|
|
50
|
-
|
|
159
|
+
Copyright © 2026-present Baptiste Augrain
|
|
51
160
|
|
|
52
|
-
|
|
161
|
+
Licensed under the [MIT license](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Options = {
|
|
2
|
+
additionals?: string[];
|
|
3
|
+
fixture?: string;
|
|
4
|
+
input?: string;
|
|
5
|
+
output?: string;
|
|
6
|
+
transformFile?: (type: 'additional' | 'input' | 'output', path: string, content: string) => string;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildCliFileTests(action: (manifest: Record<string, unknown>) => unknown, options?: Options): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import fse from '@zokugun/fs-extra-plus';
|
|
3
|
+
import { isRecord, isString } from '@zokugun/is-it-type';
|
|
4
|
+
import { stringifyError, xtryAsync, xtrySync } from '@zokugun/xtry';
|
|
5
|
+
import { vol } from 'memfs';
|
|
6
|
+
import { expect, it } from 'vitest';
|
|
7
|
+
import YAML from 'yaml';
|
|
8
|
+
const DEBUG = process.env.DEBUG === '1' || process.env.DEBUG === 'true' || process.env.DEBUG === 'on';
|
|
9
|
+
const DEBUG_VOL = process.env.DEBUG === 'vol';
|
|
10
|
+
export function buildCliFileTests(action, options = {}) {
|
|
11
|
+
const fixtureRoot = fse.join('.', 'test', 'fixtures', options.fixture ?? '');
|
|
12
|
+
const files = fse.walkSync(fixtureRoot, {
|
|
13
|
+
absolute: true,
|
|
14
|
+
onlyFiles: true,
|
|
15
|
+
collect: true,
|
|
16
|
+
filter: (item) => item.path.endsWith('.yml'),
|
|
17
|
+
});
|
|
18
|
+
if (files.fails) {
|
|
19
|
+
throw files.error;
|
|
20
|
+
}
|
|
21
|
+
const { additionals = [], input = 'input', output = 'output', transformFile = (_type, _path, content) => content } = options;
|
|
22
|
+
for (const file of files.value) {
|
|
23
|
+
const name = fse.leafName(file.path, 1);
|
|
24
|
+
const readResult = fse.readFileSync(file.path, 'utf8');
|
|
25
|
+
if (readResult.fails) {
|
|
26
|
+
throw readResult.error;
|
|
27
|
+
}
|
|
28
|
+
const manifestResult = xtrySync(() => YAML.parse(readResult.value));
|
|
29
|
+
if (manifestResult.fails) {
|
|
30
|
+
console.error(file.path);
|
|
31
|
+
throw manifestResult.error;
|
|
32
|
+
}
|
|
33
|
+
const manifest = manifestResult.value;
|
|
34
|
+
if (!isRecord(manifest)) {
|
|
35
|
+
throw new Error(`The file "${fse.relative(fixtureRoot, file.path)}" isn't an object.`);
|
|
36
|
+
}
|
|
37
|
+
const fromJSON = {};
|
|
38
|
+
const expectedFiles = {};
|
|
39
|
+
for (const [key, data] of Object.entries(manifest)) {
|
|
40
|
+
if (key.startsWith('/')) {
|
|
41
|
+
const directory = key.slice(1, key.indexOf('/', 1));
|
|
42
|
+
const slicing = directory.length + 2;
|
|
43
|
+
if (directory === input) {
|
|
44
|
+
const path = key.slice(slicing);
|
|
45
|
+
fromJSON[`/working/${path}`] = transformFile('input', path, data);
|
|
46
|
+
}
|
|
47
|
+
else if (directory === output) {
|
|
48
|
+
const path = key.slice(slicing);
|
|
49
|
+
if (isString(data)) {
|
|
50
|
+
expectedFiles[path] = transformFile('output', path, data);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
expectedFiles[path] = data;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
for (const input of additionals) {
|
|
58
|
+
if (directory === input) {
|
|
59
|
+
fromJSON[key] = transformFile('additional', key, data);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (isString(manifest.error)) {
|
|
67
|
+
const { error } = manifest;
|
|
68
|
+
it(name, async () => {
|
|
69
|
+
vol.fromJSON(fromJSON);
|
|
70
|
+
await expect(action(manifest)).rejects.toThrow(error);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
it(name, async () => {
|
|
75
|
+
vol.fromJSON(fromJSON);
|
|
76
|
+
if (DEBUG_VOL) {
|
|
77
|
+
console.log(vol.toJSON());
|
|
78
|
+
}
|
|
79
|
+
await action(manifest);
|
|
80
|
+
if (DEBUG_VOL) {
|
|
81
|
+
console.log(vol.toJSON());
|
|
82
|
+
}
|
|
83
|
+
for (const [file, data] of Object.entries(expectedFiles)) {
|
|
84
|
+
const content = vol.promises.readFile(`/working/${file}`, 'utf8');
|
|
85
|
+
if (isString(data)) {
|
|
86
|
+
const result = await xtryAsync(content, stringifyError);
|
|
87
|
+
if (DEBUG && result.fails) {
|
|
88
|
+
console.log(`Expecting file at "${file}"`);
|
|
89
|
+
}
|
|
90
|
+
if (DEBUG && result.value !== data) {
|
|
91
|
+
console.log(result);
|
|
92
|
+
}
|
|
93
|
+
expect(result.fails).to.be.false;
|
|
94
|
+
expect(result.value).to.eql(data);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
await expect(content).rejects.toThrow(`${data.error}, open '/working/${file}'`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
import { fs } from './mocks/memfs/index.mjs';
|
|
4
|
+
const DEBUG = process.env.DEBUG === '1' || process.env.DEBUG === 'true' || process.env.DEBUG === 'on' || process.env.DEBUG === 'vol';
|
|
5
|
+
export function mockCliFileTests() {
|
|
6
|
+
vi.resetModules();
|
|
7
|
+
vi.doMock('node:fs', () => ({
|
|
8
|
+
...fs,
|
|
9
|
+
default: fs,
|
|
10
|
+
}));
|
|
11
|
+
vi.doMock('node:fs/promises', () => ({ default: fs.promises }));
|
|
12
|
+
vi.doMock('node:process', () => ({
|
|
13
|
+
default: {
|
|
14
|
+
cwd: () => '/working',
|
|
15
|
+
env: {},
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
vi.doMock('@zokugun/cli-utils', async (importOriginal) => {
|
|
19
|
+
const mod = await importOriginal();
|
|
20
|
+
const { logger, unwrapFatal } = mod;
|
|
21
|
+
return {
|
|
22
|
+
c: {
|
|
23
|
+
bgBlue: (value) => value,
|
|
24
|
+
cyan: {
|
|
25
|
+
bold: (value) => value,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
logger: {
|
|
29
|
+
...logger,
|
|
30
|
+
beginTimer: () => { },
|
|
31
|
+
debug: (message) => {
|
|
32
|
+
if (DEBUG) {
|
|
33
|
+
console.log(message);
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
createSpinner: () => ({
|
|
37
|
+
fail: () => { },
|
|
38
|
+
succeed: () => { },
|
|
39
|
+
}),
|
|
40
|
+
fatal: (message) => {
|
|
41
|
+
throw new Error(message);
|
|
42
|
+
},
|
|
43
|
+
finishTimer: () => { },
|
|
44
|
+
info: (message) => {
|
|
45
|
+
if (DEBUG) {
|
|
46
|
+
console.log(message);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
newLine: () => { },
|
|
50
|
+
print: (message) => {
|
|
51
|
+
if (DEBUG) {
|
|
52
|
+
console.log(message);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
unwrapFatal,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function unmockCliFileTests() {
|
|
61
|
+
vi.doUnmock('node:fs');
|
|
62
|
+
vi.doUnmock('node:fs/promises');
|
|
63
|
+
vi.doUnmock('node:process');
|
|
64
|
+
vi.doUnmock('@zokugun/cli-utils');
|
|
65
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as memfs from './memfs/index.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as memfs from './memfs/index.mjs';
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type PathLike, type TDataOut, type IReadStream, type TFlagsCopy, IStats, type TFlags, IFileHandle, IDir, IDirent, type TFileHandle, type TPromisesData } from "@jsonjoy.com/fs-node-utils";
|
|
2
|
+
import { type Stats, Dirent, type IWriteStream } from "@jsonjoy.com/fs-node";
|
|
3
|
+
import { type IMkdirOptions, type IOptions, type IReaddirOptions, type IReadFileOptions, type IRealpathOptions, type IStatOptions, type IOpendirOptions, type IWriteFileOptions } from "@jsonjoy.com/fs-node-utils/lib/types/options.js";
|
|
4
|
+
import { type TMode } from "@jsonjoy.com/fs-node/lib/volume.js";
|
|
5
|
+
import { type TFileId } from "@jsonjoy.com/fs-core";
|
|
6
|
+
export declare const fs: {
|
|
7
|
+
access: (...args: any[]) => Promise<any> | void;
|
|
8
|
+
chmod: (...args: any[]) => Promise<any> | void;
|
|
9
|
+
chown: (...args: any[]) => Promise<any> | void;
|
|
10
|
+
close: (...args: any[]) => Promise<any> | void;
|
|
11
|
+
copyFile: (...args: any[]) => Promise<any> | void;
|
|
12
|
+
exists: (...args: any[]) => Promise<any> | void;
|
|
13
|
+
fchmod: (...args: any[]) => Promise<any> | void;
|
|
14
|
+
fchown: (...args: any[]) => Promise<any> | void;
|
|
15
|
+
fdatasync: (...args: any[]) => Promise<any> | void;
|
|
16
|
+
fstat: (...args: any[]) => Promise<any> | void;
|
|
17
|
+
fsync: (...args: any[]) => Promise<any> | void;
|
|
18
|
+
ftruncate: (...args: any[]) => Promise<any> | void;
|
|
19
|
+
futimes: (...args: any[]) => Promise<any> | void;
|
|
20
|
+
lstat: (...args: any[]) => Promise<any> | void;
|
|
21
|
+
lstatSync: {
|
|
22
|
+
(path: PathLike): Stats<number>;
|
|
23
|
+
(path: PathLike, options: {
|
|
24
|
+
throwIfNoEntry?: true | undefined;
|
|
25
|
+
}): Stats<number>;
|
|
26
|
+
(path: PathLike, options: {
|
|
27
|
+
bigint: false;
|
|
28
|
+
throwIfNoEntry?: true | undefined;
|
|
29
|
+
}): Stats<number>;
|
|
30
|
+
(path: PathLike, options: {
|
|
31
|
+
bigint: true;
|
|
32
|
+
throwIfNoEntry?: true | undefined;
|
|
33
|
+
}): Stats<bigint>;
|
|
34
|
+
(path: PathLike, options: {
|
|
35
|
+
throwIfNoEntry: false;
|
|
36
|
+
}): Stats<number> | undefined;
|
|
37
|
+
(path: PathLike, options: {
|
|
38
|
+
bigint: false;
|
|
39
|
+
throwIfNoEntry: false;
|
|
40
|
+
}): Stats<number> | undefined;
|
|
41
|
+
(path: PathLike, options: {
|
|
42
|
+
bigint: true;
|
|
43
|
+
throwIfNoEntry: false;
|
|
44
|
+
}): Stats<bigint> | undefined;
|
|
45
|
+
};
|
|
46
|
+
mkdir: (...args: any[]) => Promise<any> | void;
|
|
47
|
+
mkdirSync: {
|
|
48
|
+
(path: PathLike, options: IMkdirOptions & {
|
|
49
|
+
recursive: true;
|
|
50
|
+
}): string | undefined;
|
|
51
|
+
(path: PathLike, options?: TMode | (IMkdirOptions & {
|
|
52
|
+
recursive?: false;
|
|
53
|
+
})): void;
|
|
54
|
+
(path: PathLike, options?: TMode | IMkdirOptions): string | undefined;
|
|
55
|
+
};
|
|
56
|
+
mkdtemp: (...args: any[]) => Promise<any> | void;
|
|
57
|
+
mkdtempSync: (prefix: string, options?: IOptions) => TDataOut;
|
|
58
|
+
open: (...args: any[]) => Promise<any> | void;
|
|
59
|
+
opendir: (...args: any[]) => Promise<any> | void;
|
|
60
|
+
read: (...args: any[]) => Promise<any> | void;
|
|
61
|
+
readdir: (...args: any[]) => Promise<any> | void;
|
|
62
|
+
readdirSync: (path: PathLike, options?: IReaddirOptions | string) => TDataOut[] | Dirent[];
|
|
63
|
+
readFile: (...args: any[]) => Promise<any> | void;
|
|
64
|
+
readFileSync: (file: TFileId, options?: IReadFileOptions | string) => TDataOut;
|
|
65
|
+
ReadStream: new (...args: any[]) => IReadStream;
|
|
66
|
+
readv: (...args: any[]) => Promise<any> | void;
|
|
67
|
+
realpathSync: {
|
|
68
|
+
(path: PathLike, options?: IRealpathOptions | string): TDataOut;
|
|
69
|
+
native: (path: PathLike, options?: IRealpathOptions | string) => TDataOut;
|
|
70
|
+
};
|
|
71
|
+
realpath: (...args: any[]) => Promise<any> | void;
|
|
72
|
+
rename: (...args: any[]) => Promise<any> | void;
|
|
73
|
+
stat: (...args: any[]) => Promise<any> | void;
|
|
74
|
+
statSync: {
|
|
75
|
+
(path: PathLike): Stats<number>;
|
|
76
|
+
(path: PathLike, options: {
|
|
77
|
+
throwIfNoEntry?: true;
|
|
78
|
+
}): Stats<number>;
|
|
79
|
+
(path: PathLike, options: {
|
|
80
|
+
throwIfNoEntry: false;
|
|
81
|
+
}): Stats<number> | undefined;
|
|
82
|
+
(path: PathLike, options: {
|
|
83
|
+
bigint: false;
|
|
84
|
+
throwIfNoEntry?: true;
|
|
85
|
+
}): Stats<number>;
|
|
86
|
+
(path: PathLike, options: {
|
|
87
|
+
bigint: true;
|
|
88
|
+
throwIfNoEntry?: true;
|
|
89
|
+
}): Stats<bigint>;
|
|
90
|
+
(path: PathLike, options: {
|
|
91
|
+
bigint: false;
|
|
92
|
+
throwIfNoEntry: false;
|
|
93
|
+
}): Stats<number> | undefined;
|
|
94
|
+
(path: PathLike, options: {
|
|
95
|
+
bigint: true;
|
|
96
|
+
throwIfNoEntry: false;
|
|
97
|
+
}): Stats<bigint> | undefined;
|
|
98
|
+
};
|
|
99
|
+
Stats: new (...args: any[]) => Stats;
|
|
100
|
+
unlink: (...args: any[]) => Promise<any> | void;
|
|
101
|
+
write: (...args: any[]) => Promise<any> | void;
|
|
102
|
+
writeFile: (...args: any[]) => Promise<any> | void;
|
|
103
|
+
WriteStream: new (...args: any[]) => IWriteStream;
|
|
104
|
+
writev: (...args: any[]) => Promise<any> | void;
|
|
105
|
+
promises: {
|
|
106
|
+
access: (path: PathLike, mode?: number) => Promise<void>;
|
|
107
|
+
chmod: (path: PathLike, mode: import("@jsonjoy.com/fs-node-utils").TMode) => Promise<void>;
|
|
108
|
+
chown: (path: PathLike, uid: number, gid: number) => Promise<void>;
|
|
109
|
+
copyFile: (src: PathLike, dest: PathLike, flags?: TFlagsCopy) => Promise<void>;
|
|
110
|
+
lstat: (path: PathLike, options?: IStatOptions) => Promise<IStats>;
|
|
111
|
+
mkdir: (path: PathLike, options?: import("@jsonjoy.com/fs-node-utils").TMode | IMkdirOptions) => Promise<string | undefined>;
|
|
112
|
+
mkdtemp: (prefix: string, options?: IOptions) => Promise<TDataOut>;
|
|
113
|
+
open: (path: PathLike, flags?: TFlags, mode?: import("@jsonjoy.com/fs-node-utils").TMode) => Promise<IFileHandle>;
|
|
114
|
+
opendir: (path: PathLike, options?: IOpendirOptions) => Promise<IDir>;
|
|
115
|
+
read: (arg1: number, arg2: Buffer<ArrayBufferLike> | ArrayBufferView<ArrayBufferLike> | DataView<ArrayBufferLike>, arg3: number, arg4: number, arg5: number | null) => Promise<number | undefined>;
|
|
116
|
+
readdir: (path: PathLike, options?: IReaddirOptions | string) => Promise<TDataOut[] | IDirent[]>;
|
|
117
|
+
readFile: (id: TFileHandle, options?: IReadFileOptions | string) => Promise<TDataOut>;
|
|
118
|
+
realpath: (path: PathLike, options?: IRealpathOptions | string) => Promise<TDataOut>;
|
|
119
|
+
rename: (oldPath: PathLike, newPath: PathLike) => Promise<void>;
|
|
120
|
+
stat: (path: PathLike, options?: IStatOptions) => Promise<IStats>;
|
|
121
|
+
Stats: new (...args: any[]) => Stats;
|
|
122
|
+
unlink: (path: PathLike) => Promise<void>;
|
|
123
|
+
writeFile: (id: TFileHandle, data: TPromisesData, options?: IWriteFileOptions) => Promise<void>;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { promisify } from 'util';
|
|
2
|
+
import { fs as mfs } from 'memfs';
|
|
3
|
+
import { fromCallback as u } from 'universalify';
|
|
4
|
+
export const fs = {
|
|
5
|
+
access: u(mfs.access),
|
|
6
|
+
chmod: u(mfs.chmod),
|
|
7
|
+
chown: u(mfs.chown),
|
|
8
|
+
close: u(mfs.close),
|
|
9
|
+
copyFile: u(mfs.copyFile),
|
|
10
|
+
exists: u(mfs.exists),
|
|
11
|
+
fchmod: u(mfs.fchmod),
|
|
12
|
+
fchown: u(mfs.fchown),
|
|
13
|
+
fdatasync: u(mfs.fdatasync),
|
|
14
|
+
fstat: u(mfs.fstat),
|
|
15
|
+
fsync: u(mfs.fsync),
|
|
16
|
+
ftruncate: u(mfs.ftruncate),
|
|
17
|
+
futimes: u(mfs.futimes),
|
|
18
|
+
lstat: u(mfs.lstat),
|
|
19
|
+
lstatSync: mfs.lstatSync,
|
|
20
|
+
mkdir: u(mfs.mkdir),
|
|
21
|
+
mkdirSync: mfs.mkdirSync,
|
|
22
|
+
mkdtemp: u(mfs.mkdtemp),
|
|
23
|
+
mkdtempSync: mfs.mkdtempSync,
|
|
24
|
+
open: u(mfs.open),
|
|
25
|
+
opendir: u(mfs.opendir),
|
|
26
|
+
read: u(mfs.read),
|
|
27
|
+
readdir: u(mfs.readdir),
|
|
28
|
+
readdirSync: mfs.readdirSync,
|
|
29
|
+
readFile: u(mfs.readFile),
|
|
30
|
+
readFileSync: mfs.readFileSync,
|
|
31
|
+
ReadStream: mfs.ReadStream,
|
|
32
|
+
readv: u(mfs.read),
|
|
33
|
+
realpathSync: mfs.realpathSync,
|
|
34
|
+
realpath: u(mfs.realpath),
|
|
35
|
+
rename: u(mfs.rename),
|
|
36
|
+
stat: u(mfs.stat),
|
|
37
|
+
statSync: mfs.statSync,
|
|
38
|
+
Stats: mfs.Stats,
|
|
39
|
+
unlink: u(mfs.unlink),
|
|
40
|
+
write: u(mfs.write),
|
|
41
|
+
writeFile: u(mfs.writeFile),
|
|
42
|
+
WriteStream: mfs.WriteStream,
|
|
43
|
+
writev: u(mfs.write),
|
|
44
|
+
promises: {
|
|
45
|
+
access: mfs.promises.access,
|
|
46
|
+
chmod: mfs.promises.chmod,
|
|
47
|
+
chown: mfs.promises.chown,
|
|
48
|
+
copyFile: mfs.promises.copyFile,
|
|
49
|
+
lstat: mfs.promises.lstat,
|
|
50
|
+
mkdir: mfs.promises.mkdir,
|
|
51
|
+
mkdtemp: mfs.promises.mkdtemp,
|
|
52
|
+
open: mfs.promises.open,
|
|
53
|
+
opendir: mfs.promises.opendir,
|
|
54
|
+
read: promisify(mfs.read),
|
|
55
|
+
readdir: mfs.promises.readdir,
|
|
56
|
+
readFile: mfs.promises.readFile,
|
|
57
|
+
realpath: mfs.promises.realpath,
|
|
58
|
+
rename: mfs.promises.rename,
|
|
59
|
+
stat: mfs.promises.stat,
|
|
60
|
+
Stats: mfs.Stats,
|
|
61
|
+
unlink: mfs.promises.unlink,
|
|
62
|
+
writeFile: mfs.promises.writeFile,
|
|
63
|
+
},
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withTemp(prefix: string, run: (root: string) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import fse from '@zokugun/fs-extra-plus/async';
|
|
3
|
+
export async function withTemp(prefix, run) {
|
|
4
|
+
const result = await fse.makeTempDir({ prefix });
|
|
5
|
+
if (result.fails) {
|
|
6
|
+
throw result.error;
|
|
7
|
+
}
|
|
8
|
+
const root = result.value;
|
|
9
|
+
const originalCwd = process.cwd();
|
|
10
|
+
try {
|
|
11
|
+
process.chdir(root);
|
|
12
|
+
await run(root);
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
process.chdir(originalCwd);
|
|
16
|
+
await fse.remove(root);
|
|
17
|
+
}
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
"name": "@zokugun/vitest-toolkit",
|
|
3
|
+
"description": "A toolkit for vitest",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Baptiste Augrain",
|
|
7
|
+
"email": "daiyam@zokugun.org"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"homepage": "https://github.com/zokugun/node-vitest-toolkit",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/zokugun/node-vitest-toolkit.git"
|
|
14
|
+
},
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/zokugun/node-vitest-toolkit/discussions/categories/issue-triage"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./lib/esm/index.mjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"module": "lib/esm/index.mjs",
|
|
25
|
+
"scripts": {
|
|
26
|
+
"audit:fix": "npm audit fix --min-release-age=0",
|
|
27
|
+
"build": "npm run clean && npm run build:out",
|
|
28
|
+
"build:out": "tsc-leda generate",
|
|
29
|
+
"build:package": "tsc-leda update-package && npm run lint:package",
|
|
30
|
+
"ci:lint": "zizmor .",
|
|
31
|
+
"ci:lint:fix": "zizmor . --fix=all",
|
|
32
|
+
"clean": "rimraf .src; rimraf lib",
|
|
33
|
+
"compile:src": "tsc -p src",
|
|
34
|
+
"lint": "eslint",
|
|
35
|
+
"lint:all": "npm run lint:package && npm run ci:lint",
|
|
36
|
+
"lint:fix": "eslint --fix",
|
|
37
|
+
"lint:package": "fixpack || true",
|
|
38
|
+
"prepack": "npm run build",
|
|
39
|
+
"prepare": "husky; npm run lint:package",
|
|
40
|
+
"release": "bump-n-ship release --all --pause",
|
|
41
|
+
"update:artifacts": "artifact update",
|
|
42
|
+
"update:ci": "pinact run -min-age 7 -update",
|
|
43
|
+
"update:deps": "taze --all",
|
|
44
|
+
"watch:build": "tsc-watch -p src --onSuccess 'npm run build'",
|
|
45
|
+
"watch:src": "tsc-watch -p src"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@zokugun/fs-extra-plus": "0.7.0",
|
|
49
|
+
"@zokugun/is-it-type": "0.8.1",
|
|
50
|
+
"@zokugun/xtry": "0.12.2",
|
|
51
|
+
"memfs": "4.68.1",
|
|
52
|
+
"universalify": "2.0.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@commitlint/cli": "20.5.3",
|
|
56
|
+
"@commitlint/config-conventional": "20.5.3",
|
|
57
|
+
"@types/node": "20.19.43",
|
|
58
|
+
"@types/universalify": "1.0.3",
|
|
59
|
+
"@zokugun/bump-n-ship": "0.1.1",
|
|
60
|
+
"@zokugun/eslint-config": "0.2.1",
|
|
61
|
+
"@zokugun/eslint-config-data": "0.2.1",
|
|
62
|
+
"@zokugun/eslint-config-glossary": "0.2.0",
|
|
63
|
+
"@zokugun/eslint-config-js": "0.2.1",
|
|
64
|
+
"@zokugun/eslint-config-md": "0.4.1",
|
|
65
|
+
"@zokugun/eslint-config-nodejs": "0.2.0",
|
|
66
|
+
"@zokugun/eslint-config-style": "0.3.1",
|
|
67
|
+
"@zokugun/eslint-config-ts": "0.3.2",
|
|
68
|
+
"@zokugun/tsc-leda": "0.9.5",
|
|
69
|
+
"eslint": "10.13.0",
|
|
70
|
+
"fixpack": "4.0.0",
|
|
71
|
+
"husky": "9.1.7",
|
|
72
|
+
"lint-staged": "16.4.0",
|
|
73
|
+
"rimraf": "6.1.4",
|
|
74
|
+
"taze": "19.17.2",
|
|
75
|
+
"tsc-watch": "7.2.1",
|
|
76
|
+
"typescript": "5.9.3"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"vitest": "*"
|
|
80
|
+
},
|
|
81
|
+
"overrides": {
|
|
82
|
+
"@eslint/config-array": {
|
|
83
|
+
"minimatch": "11.0.1"
|
|
84
|
+
},
|
|
85
|
+
"@typescript-eslint/typescript-estree": {
|
|
86
|
+
"minimatch": "11.0.1"
|
|
87
|
+
},
|
|
88
|
+
"eslint": {
|
|
89
|
+
"minimatch": "11.0.1"
|
|
90
|
+
},
|
|
91
|
+
"eslint-plugin-import-x": {
|
|
92
|
+
"minimatch": "11.0.1"
|
|
93
|
+
},
|
|
94
|
+
"micromark-extension-math": {
|
|
95
|
+
"katex": "0.18.2"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"allowScripts": {},
|
|
99
|
+
"keywords": [
|
|
100
|
+
"fixture",
|
|
101
|
+
"vitest"
|
|
102
|
+
]
|
|
5
103
|
}
|