hypotes 0.0.0-stage → 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 +21 -0
- package/README.md +407 -2
- package/dist/equals.d.ts +9 -0
- package/dist/expect.d.ts +14 -0
- package/dist/fast-check.d.ts +26 -0
- package/dist/fast-check.js +32 -0
- package/dist/hoist.d.ts +6 -0
- package/dist/hooks.d.ts +16 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +274 -0
- package/dist/mocks-ciQvBYVw.js +281 -0
- package/dist/mocks.d.ts +83 -0
- package/dist/oxlint/index.d.ts +9 -0
- package/dist/oxlint/index.js +831 -0
- package/dist/oxlint/rules.d.ts +16 -0
- package/dist/oxlint/types.d.ts +8 -0
- package/dist/register.d.ts +1 -0
- package/dist/register.js +309 -0
- package/dist/site.d.ts +20 -0
- package/dist/table.d.ts +5 -0
- package/dist/tests-D4v1ZaoR.js +266 -0
- package/dist/tests.d.ts +113 -0
- package/dist/title.d.ts +8 -0
- package/package.json +125 -3
package/dist/tests.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as nodeTest from 'node:test';
|
|
2
|
+
import { type Site } from './site.ts';
|
|
3
|
+
type Awaitable<T> = PromiseLike<T> | T;
|
|
4
|
+
/** The options of a test or a suite, which node:test takes */
|
|
5
|
+
export interface TestOptions {
|
|
6
|
+
/** Milliseconds after which the test fails */
|
|
7
|
+
readonly timeout?: number;
|
|
8
|
+
/** Skips it, with the reason if a string */
|
|
9
|
+
readonly skip?: boolean | string;
|
|
10
|
+
/**
|
|
11
|
+
* Marks it as to do: it runs, and its failure is reported but doesn't
|
|
12
|
+
* fail the run
|
|
13
|
+
*/
|
|
14
|
+
readonly todo?: boolean | string;
|
|
15
|
+
/**
|
|
16
|
+
* Runs it, and the others marked only, rather than every test, when
|
|
17
|
+
* `--test-only` is passed or tests run in one process
|
|
18
|
+
*/
|
|
19
|
+
readonly only?: boolean;
|
|
20
|
+
/** How many of its subtests run at once, or all at once if true */
|
|
21
|
+
readonly concurrency?: boolean | number;
|
|
22
|
+
}
|
|
23
|
+
export type TestContext = nodeTest.TestContext;
|
|
24
|
+
export type SuiteContext = nodeTest.SuiteContext;
|
|
25
|
+
export type TestFunction = (context: TestContext) => Awaitable<unknown>;
|
|
26
|
+
export type SuiteFunction = (context: SuiteContext) => Awaitable<unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Declares a test or a suite, with its options before its function, as
|
|
29
|
+
* Vitest and node:test take them, or a timeout alone after it. As in Vitest
|
|
30
|
+
* 4, options after the function throw a TypeError. Without a function, it's
|
|
31
|
+
* to do.
|
|
32
|
+
*/
|
|
33
|
+
export interface Declare<Fn> {
|
|
34
|
+
(name: string, fn?: Fn, timeout?: number): void;
|
|
35
|
+
(name: string, options: TestOptions, fn?: Fn): void;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A row of a table in a template literal, whose columns only the template's
|
|
39
|
+
* text names. Its values are typed as any, as Vitest types them, so that a
|
|
40
|
+
* function can destructure them, or declare their types.
|
|
41
|
+
*/
|
|
42
|
+
export type TableRow = any;
|
|
43
|
+
/**
|
|
44
|
+
* Declares a test or a suite for each row, which `formatTitle` names. Its
|
|
45
|
+
* function takes the row's values, if every row is an array, and otherwise
|
|
46
|
+
* the row. A readonly row's values are spread into parameters, which can't be
|
|
47
|
+
* readonly. The rows of a table in a template literal are objects.
|
|
48
|
+
*/
|
|
49
|
+
export interface Each<Result> {
|
|
50
|
+
<Row extends readonly unknown[] | [unknown]>(rows: readonly Row[]): Declare<(...values: [...Row]) => Result>;
|
|
51
|
+
<Row>(rows: readonly Row[]): Declare<(row: Row) => Result>;
|
|
52
|
+
(strings: TemplateStringsArray, ...values: unknown[]): Declare<(row: TableRow) => Result>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Declares a test or a suite for each row, which `formatTitle` names. Its
|
|
56
|
+
* function takes the row, whether or not it's an array, and a test's
|
|
57
|
+
* context. The rows of a table in a template literal are objects.
|
|
58
|
+
*/
|
|
59
|
+
export interface For<Context extends unknown[]> {
|
|
60
|
+
<Row>(rows: readonly Row[]): Declare<(row: Row, ...context: Context) => Awaitable<unknown>>;
|
|
61
|
+
(strings: TemplateStringsArray, ...values: unknown[]): Declare<(row: TableRow, ...context: Context) => Awaitable<unknown>>;
|
|
62
|
+
}
|
|
63
|
+
/** The variants of a test or a suite, which apply to any combination */
|
|
64
|
+
export interface Modifiers<API> {
|
|
65
|
+
/** Skips it */
|
|
66
|
+
readonly skip: API;
|
|
67
|
+
/** Runs it, and the others marked only, rather than every test */
|
|
68
|
+
readonly only: API;
|
|
69
|
+
/** Marks it as to do */
|
|
70
|
+
readonly todo: API;
|
|
71
|
+
/** Skips it if the condition holds */
|
|
72
|
+
skipIf(condition: unknown): API;
|
|
73
|
+
/** Skips it unless the condition holds */
|
|
74
|
+
runIf(condition: unknown): API;
|
|
75
|
+
}
|
|
76
|
+
/** `it` and `test`, with members that a subpath, such as fast-check's, adds */
|
|
77
|
+
export interface TestAPI<Extra = unknown> extends Declare<TestFunction>, Modifiers<TestAPI<Extra> & Extra> {
|
|
78
|
+
readonly each: Each<Awaitable<unknown>>;
|
|
79
|
+
readonly for: For<[context: TestContext]>;
|
|
80
|
+
}
|
|
81
|
+
/** `describe` and `suite` */
|
|
82
|
+
export interface SuiteAPI extends Declare<SuiteFunction>, Modifiers<SuiteAPI> {
|
|
83
|
+
readonly each: Each<Awaitable<unknown>>;
|
|
84
|
+
readonly for: For<[]>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Declares a test or a suite with the options that its modifiers set, from
|
|
88
|
+
* the site where a test file declared it
|
|
89
|
+
*/
|
|
90
|
+
export type Define<Fn> = (name: string, options: TestOptions, fn: Fn | undefined, site: Site | undefined) => void;
|
|
91
|
+
type Argument<Fn> = Fn | TestOptions | number | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The function and options of a declaration, as Vitest 4 reads them: its
|
|
94
|
+
* options before its function, or a timeout after it. It throws a TypeError,
|
|
95
|
+
* with Vitest's message, for options after the function, which Vitest took
|
|
96
|
+
* until 4, and for two functions.
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseArguments<Fn>(first: Argument<Fn>, second: Argument<Fn>): {
|
|
99
|
+
fn: Fn | undefined;
|
|
100
|
+
options: TestOptions;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The API of `it` and `test`, with the members that `extend` adds at each
|
|
104
|
+
* modifier, such as fast-check's `prop`
|
|
105
|
+
*/
|
|
106
|
+
export declare function createTestAPI<Extra extends object>(extend: (define: Define<TestFunction>) => Extra): TestAPI<Extra> & Extra;
|
|
107
|
+
/** Declares a test, which passes unless its function throws or rejects */
|
|
108
|
+
export declare const it: TestAPI;
|
|
109
|
+
export declare const test: TestAPI;
|
|
110
|
+
/** Declares a suite, whose function declares tests and other suites */
|
|
111
|
+
export declare const describe: SuiteAPI;
|
|
112
|
+
export declare const suite: SuiteAPI;
|
|
113
|
+
export {};
|
package/dist/title.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a title of `.each` or `.for` with the row's values: `%s`, `%d`,
|
|
3
|
+
* `%i`, `%f`, `%j`, `%o` and `%O` print them in order, as `util.format`
|
|
4
|
+
* does, `%#` and `%$` print the row's index from 0 and from 1, and `$name`
|
|
5
|
+
* prints a property of the row, if it's an object, or of an array's element,
|
|
6
|
+
* as `$0.name`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatTitle(template: string, items: readonly unknown[], index: number): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,128 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypotes",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1-0",
|
|
4
|
+
"description": "Vitest's API on node:test. Same tests, no Vite.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"expect",
|
|
7
|
+
"fast-check",
|
|
8
|
+
"mock",
|
|
9
|
+
"node:test",
|
|
10
|
+
"property-based-testing",
|
|
11
|
+
"test",
|
|
12
|
+
"vitest"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "snovader",
|
|
16
|
+
"homepage": "https://github.com/snovader/hypotes#readme",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/snovader/hypotes/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/snovader/hypotes.git"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=24.13.1"
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./fast-check": {
|
|
37
|
+
"types": "./dist/fast-check.d.ts",
|
|
38
|
+
"default": "./dist/fast-check.js"
|
|
39
|
+
},
|
|
40
|
+
"./oxlint": {
|
|
41
|
+
"types": "./dist/oxlint/index.d.ts",
|
|
42
|
+
"default": "./dist/oxlint/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./register": {
|
|
45
|
+
"types": "./dist/register.d.ts",
|
|
46
|
+
"default": "./dist/register.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"imports": {
|
|
50
|
+
"#source/*": {
|
|
51
|
+
"types": "./dist/*.d.ts"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"default": "./dist/index.js"
|
|
59
|
+
},
|
|
60
|
+
"./fast-check": {
|
|
61
|
+
"types": "./dist/fast-check.d.ts",
|
|
62
|
+
"default": "./dist/fast-check.js"
|
|
63
|
+
},
|
|
64
|
+
"./oxlint": {
|
|
65
|
+
"types": "./dist/oxlint/index.d.ts",
|
|
66
|
+
"default": "./dist/oxlint/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./register": {
|
|
69
|
+
"types": "./dist/register.d.ts",
|
|
70
|
+
"default": "./dist/register.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"imports": {
|
|
74
|
+
"#source/*": {
|
|
75
|
+
"types": "./dist/*.d.ts"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"scripts": {
|
|
80
|
+
"build": "rolldown -c && tsc -p tsconfig.dist.json",
|
|
81
|
+
"format:check": "oxfmt --check",
|
|
82
|
+
"format:write": "oxfmt",
|
|
83
|
+
"lint:check": "oxlint",
|
|
84
|
+
"lint:write": "oxlint --fix",
|
|
85
|
+
"prepack": "node scripts/require-yarn.ts && yarn build",
|
|
86
|
+
"test": "node --import hypotes/register --test 'test/**/*.test.ts' 'lint/*.test.ts'",
|
|
87
|
+
"test:dist": "yarn build && NODE_OPTIONS=--conditions=hypotes-dist yarn test",
|
|
88
|
+
"test:watch": "node --import hypotes/register --test --watch 'test/**/*.test.ts' 'lint/*.test.ts'",
|
|
89
|
+
"typecheck": "tsc -p ."
|
|
90
|
+
},
|
|
91
|
+
"dependencies": {
|
|
92
|
+
"@vitest/expect": "^5.1.0",
|
|
93
|
+
"@vitest/spy": "^5.1.0",
|
|
94
|
+
"@vitest/utils": "^5.1.0",
|
|
95
|
+
"tinyrainbow": "^3.2.0"
|
|
96
|
+
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"fast-check": "^4.10.2",
|
|
99
|
+
"magic-string": "^1.4.5",
|
|
100
|
+
"oxc-parser": ">=0.159.0 <1",
|
|
101
|
+
"oxlint": "^1.94.0"
|
|
102
|
+
},
|
|
103
|
+
"peerDependenciesMeta": {
|
|
104
|
+
"fast-check": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"magic-string": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"oxc-parser": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"oxlint": {
|
|
114
|
+
"optional": true
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"devDependencies": {
|
|
118
|
+
"@types/node": "^26.6.6",
|
|
119
|
+
"fast-check": "^4.10.2",
|
|
120
|
+
"magic-string": "^1.4.5",
|
|
121
|
+
"oxc-parser": "^0.159.0",
|
|
122
|
+
"oxfmt": "^0.79.0",
|
|
123
|
+
"oxlint": "^1.94.0",
|
|
124
|
+
"oxlint-tsgolint": "^7.0.2007",
|
|
125
|
+
"rolldown": "^1.3.2",
|
|
126
|
+
"typescript": "^7.0.2"
|
|
127
|
+
}
|
|
6
128
|
}
|