@ark/attest 0.9.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 +7 -0
- package/README.md +284 -0
- package/out/assert/assertions.d.ts +28 -0
- package/out/assert/assertions.js +119 -0
- package/out/assert/attest.d.ts +26 -0
- package/out/assert/attest.js +40 -0
- package/out/assert/chainableAssertions.d.ts +68 -0
- package/out/assert/chainableAssertions.js +176 -0
- package/out/bench/await1k.d.ts +1 -0
- package/out/bench/await1k.js +1002 -0
- package/out/bench/baseline.d.ts +5 -0
- package/out/bench/baseline.js +60 -0
- package/out/bench/bench.d.ts +58 -0
- package/out/bench/bench.js +216 -0
- package/out/bench/call1k.d.ts +1 -0
- package/out/bench/call1k.js +1002 -0
- package/out/bench/measure.d.ts +29 -0
- package/out/bench/measure.js +48 -0
- package/out/bench/type.d.ts +16 -0
- package/out/bench/type.js +36 -0
- package/out/cache/getCachedAssertions.d.ts +11 -0
- package/out/cache/getCachedAssertions.js +70 -0
- package/out/cache/snapshots.d.ts +29 -0
- package/out/cache/snapshots.js +153 -0
- package/out/cache/ts.d.ts +45 -0
- package/out/cache/ts.js +127 -0
- package/out/cache/utils.d.ts +9 -0
- package/out/cache/utils.js +114 -0
- package/out/cache/writeAssertionCache.d.ts +42 -0
- package/out/cache/writeAssertionCache.js +141 -0
- package/out/cli/cli.d.ts +2 -0
- package/out/cli/cli.js +25 -0
- package/out/cli/precache.d.ts +1 -0
- package/out/cli/precache.js +7 -0
- package/out/cli/shared.d.ts +1 -0
- package/out/cli/shared.js +1 -0
- package/out/cli/stats.d.ts +1 -0
- package/out/cli/stats.js +54 -0
- package/out/cli/trace.d.ts +1 -0
- package/out/cli/trace.js +37 -0
- package/out/config.d.ts +42 -0
- package/out/config.js +94 -0
- package/out/fixtures.d.ts +6 -0
- package/out/fixtures.js +29 -0
- package/out/index.d.ts +9 -0
- package/out/index.js +8 -0
- package/out/tsVersioning.d.ts +45 -0
- package/out/tsVersioning.js +119 -0
- package/out/utils.d.ts +15 -0
- package/out/utils.js +36 -0
- package/package.json +48 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Digit } from "@ark/util";
|
|
2
|
+
/**
|
|
3
|
+
* Executes a provided function for an installed set of TypeScript versions.
|
|
4
|
+
*
|
|
5
|
+
* Your primary TypeScript version at node_modules/typescript will be
|
|
6
|
+
* temporarily renamed to node_modules/typescript-temp, and reset after each
|
|
7
|
+
* version has been executed, regardless of failures.
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* Throws an error if any version fails when the associated function is executed.
|
|
11
|
+
*
|
|
12
|
+
* @param {TsVersionData[]} versions The set of versions for which to exceute the function
|
|
13
|
+
* @param {function} fn - The function to execute for each TypeScript version.
|
|
14
|
+
* Should spawn a new process so the new symlinked version can be loaded.
|
|
15
|
+
*/
|
|
16
|
+
export declare const forTypeScriptVersions: (versions: TsVersionData[], fn: (version: TsVersionData) => void) => void;
|
|
17
|
+
export type TsVersionData = {
|
|
18
|
+
alias: string;
|
|
19
|
+
version: string;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Find and return the paths of all installed TypeScript versions, including the
|
|
24
|
+
* primary version installed as "typescript" and all dependencies beginning with
|
|
25
|
+
* "typescript-".
|
|
26
|
+
*
|
|
27
|
+
* Starts checking from the current directory and looks for node_modules in parent
|
|
28
|
+
* directories up to the file system root.
|
|
29
|
+
*
|
|
30
|
+
* Alternate versions can be installed using a package.json dependency like:
|
|
31
|
+
*
|
|
32
|
+
* ```json
|
|
33
|
+
* "typescript-latest": "npm:typescript@latest"
|
|
34
|
+
* ```
|
|
35
|
+
* @returns {TsVersionData[]} Each version mapped to data, e.g.:
|
|
36
|
+
* {alias: "typescript-latest", version: "5.3.3", path: "/home/ssalb/arktype/node_modules/typescript-latest" }
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} If a TypeScript version specified in package.json is not
|
|
39
|
+
* installed at the expected location in node_modules.
|
|
40
|
+
*/
|
|
41
|
+
export declare const findAttestTypeScriptVersions: () => TsVersionData[];
|
|
42
|
+
/** Get the TypeScript version being used by attest as as string like "5.0"
|
|
43
|
+
* Does not include alternate versions that may be referenced by cache files
|
|
44
|
+
*/
|
|
45
|
+
export declare const getPrimaryTsVersionUnderTest: () => `${Digit}.${Digit}`;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { findPackageRoot, fsRoot, readJson } from "@ark/fs";
|
|
2
|
+
import { existsSync, renameSync, symlinkSync, unlinkSync } from "fs";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
import { join } from "path/posix";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
/**
|
|
7
|
+
* Executes a provided function for an installed set of TypeScript versions.
|
|
8
|
+
*
|
|
9
|
+
* Your primary TypeScript version at node_modules/typescript will be
|
|
10
|
+
* temporarily renamed to node_modules/typescript-temp, and reset after each
|
|
11
|
+
* version has been executed, regardless of failures.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* Throws an error if any version fails when the associated function is executed.
|
|
15
|
+
*
|
|
16
|
+
* @param {TsVersionData[]} versions The set of versions for which to exceute the function
|
|
17
|
+
* @param {function} fn - The function to execute for each TypeScript version.
|
|
18
|
+
* Should spawn a new process so the new symlinked version can be loaded.
|
|
19
|
+
*/
|
|
20
|
+
export const forTypeScriptVersions = (versions, fn) => {
|
|
21
|
+
const passedVersions = [];
|
|
22
|
+
const failedVersions = [];
|
|
23
|
+
const nodeModules = join(findPackageRoot(process.cwd()), "node_modules");
|
|
24
|
+
const tsPrimaryPath = join(nodeModules, "typescript");
|
|
25
|
+
const tsTemporaryPath = join(nodeModules, "typescript-temp");
|
|
26
|
+
if (existsSync(tsPrimaryPath))
|
|
27
|
+
renameSync(tsPrimaryPath, tsTemporaryPath);
|
|
28
|
+
try {
|
|
29
|
+
for (const version of versions) {
|
|
30
|
+
const targetPath = version.path === tsPrimaryPath ? tsTemporaryPath : version.path;
|
|
31
|
+
const tsPackageJson = readJson(join(targetPath, "package.json"));
|
|
32
|
+
if (tsPackageJson.name !== "typescript") {
|
|
33
|
+
throw new Error(`Expected to find a TypeScript version ${version.version} at ${version.path}`);
|
|
34
|
+
}
|
|
35
|
+
console.log(`⛵ Switching to TypeScript version ${version.alias} (${version.version})...`);
|
|
36
|
+
try {
|
|
37
|
+
if (existsSync(tsPrimaryPath))
|
|
38
|
+
unlinkSync(tsPrimaryPath);
|
|
39
|
+
symlinkSync(targetPath, tsPrimaryPath);
|
|
40
|
+
fn(version);
|
|
41
|
+
passedVersions.push(version);
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
console.error(e);
|
|
45
|
+
failedVersions.push(version);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (failedVersions.length !== 0) {
|
|
49
|
+
throw new Error(`❌ The following TypeScript versions threw: ${failedVersions
|
|
50
|
+
.map(v => `${v.alias} (${v.version})`)
|
|
51
|
+
.join(", ")}`);
|
|
52
|
+
}
|
|
53
|
+
console.log(`✅ Successfully ran TypeScript versions ${passedVersions
|
|
54
|
+
.map(v => `${v.alias} (${v.version})`)
|
|
55
|
+
.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
if (existsSync(tsTemporaryPath)) {
|
|
59
|
+
console.log(`⏮️ Restoring your original TypeScript version...`);
|
|
60
|
+
renameSync(tsTemporaryPath, tsPrimaryPath);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Find and return the paths of all installed TypeScript versions, including the
|
|
66
|
+
* primary version installed as "typescript" and all dependencies beginning with
|
|
67
|
+
* "typescript-".
|
|
68
|
+
*
|
|
69
|
+
* Starts checking from the current directory and looks for node_modules in parent
|
|
70
|
+
* directories up to the file system root.
|
|
71
|
+
*
|
|
72
|
+
* Alternate versions can be installed using a package.json dependency like:
|
|
73
|
+
*
|
|
74
|
+
* ```json
|
|
75
|
+
* "typescript-latest": "npm:typescript@latest"
|
|
76
|
+
* ```
|
|
77
|
+
* @returns {TsVersionData[]} Each version mapped to data, e.g.:
|
|
78
|
+
* {alias: "typescript-latest", version: "5.3.3", path: "/home/ssalb/arktype/node_modules/typescript-latest" }
|
|
79
|
+
*
|
|
80
|
+
* @throws {Error} If a TypeScript version specified in package.json is not
|
|
81
|
+
* installed at the expected location in node_modules.
|
|
82
|
+
*/
|
|
83
|
+
export const findAttestTypeScriptVersions = () => {
|
|
84
|
+
let currentDir = process.cwd();
|
|
85
|
+
const versions = [];
|
|
86
|
+
while (currentDir !== fsRoot) {
|
|
87
|
+
const packageJsonPath = join(currentDir, "package.json");
|
|
88
|
+
if (!existsSync(packageJsonPath)) {
|
|
89
|
+
currentDir = dirname(currentDir);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
const nodeModulesPath = join(currentDir, "node_modules");
|
|
93
|
+
const packageJson = readJson(packageJsonPath);
|
|
94
|
+
const dependencies = {
|
|
95
|
+
...packageJson.dependencies,
|
|
96
|
+
...packageJson.devDependencies
|
|
97
|
+
};
|
|
98
|
+
for (const alias in dependencies) {
|
|
99
|
+
if (!alias.startsWith("typescript"))
|
|
100
|
+
continue;
|
|
101
|
+
const path = join(nodeModulesPath, alias);
|
|
102
|
+
if (!existsSync(path)) {
|
|
103
|
+
throw Error(`TypeScript version ${alias} specified in ${packageJsonPath} must be installed at ${path} `);
|
|
104
|
+
}
|
|
105
|
+
const version = readJson(join(path, "package.json")).version;
|
|
106
|
+
versions.push({
|
|
107
|
+
alias,
|
|
108
|
+
version,
|
|
109
|
+
path
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
currentDir = dirname(currentDir);
|
|
113
|
+
}
|
|
114
|
+
return versions;
|
|
115
|
+
};
|
|
116
|
+
/** Get the TypeScript version being used by attest as as string like "5.0"
|
|
117
|
+
* Does not include alternate versions that may be referenced by cache files
|
|
118
|
+
*/
|
|
119
|
+
export const getPrimaryTsVersionUnderTest = () => ts.versionMajorMinor;
|
package/out/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const getFileKey: (path: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* Can be used to allow arbitrarily chained property access and function calls.
|
|
4
|
+
*/
|
|
5
|
+
export declare const chainableNoOpProxy: any;
|
|
6
|
+
export type ContextualTests<ctx = unknown> = (it: (name: string, test: (ctx: ctx) => void) => void) => void;
|
|
7
|
+
export type ContextualizeRoot = {
|
|
8
|
+
<ctx>(tests: () => void, createCtx?: never): void;
|
|
9
|
+
<ctx>(createCtx: () => ctx, tests: ContextualTests<ctx>): void;
|
|
10
|
+
};
|
|
11
|
+
export type ContextualizeEach = <ctx>(name: string, createCtx: () => ctx, tests: ContextualTests<ctx>) => void;
|
|
12
|
+
export interface Contextualize extends ContextualizeRoot {
|
|
13
|
+
each: ContextualizeEach;
|
|
14
|
+
}
|
|
15
|
+
export declare const contextualize: Contextualize;
|
package/out/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { caller } from "@ark/fs";
|
|
2
|
+
import { throwError } from "@ark/util";
|
|
3
|
+
import { basename, relative } from "node:path";
|
|
4
|
+
export const getFileKey = (path) => relative(".", path);
|
|
5
|
+
/**
|
|
6
|
+
* Can be used to allow arbitrarily chained property access and function calls.
|
|
7
|
+
*/
|
|
8
|
+
export const chainableNoOpProxy = new Proxy(() => chainableNoOpProxy, {
|
|
9
|
+
get: () => chainableNoOpProxy
|
|
10
|
+
});
|
|
11
|
+
const contextualizeRoot = (first, contextualTests) => {
|
|
12
|
+
const describe = globalThis.describe;
|
|
13
|
+
if (!describe) {
|
|
14
|
+
throw new Error(`contextualize cannot be used without a global 'describe' function.`);
|
|
15
|
+
}
|
|
16
|
+
const fileName = basename(caller().file);
|
|
17
|
+
if (contextualTests) {
|
|
18
|
+
describe(fileName, () => contextualTests((name, test) => {
|
|
19
|
+
it(name, () => test(first()));
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
describe(fileName, first);
|
|
24
|
+
};
|
|
25
|
+
const contextualizeEach = (name, createCtx, tests) => {
|
|
26
|
+
const describe = globalThis.describe;
|
|
27
|
+
if (!describe)
|
|
28
|
+
throwNoDescribeError();
|
|
29
|
+
describe(name, () => tests((name, test) => {
|
|
30
|
+
it(name, () => test(createCtx()));
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
export const contextualize = Object.assign(contextualizeRoot, {
|
|
34
|
+
each: contextualizeEach
|
|
35
|
+
});
|
|
36
|
+
const throwNoDescribeError = () => throwError("contextualize cannot be used without a global 'describe' function.");
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ark/attest",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "David Blass",
|
|
6
|
+
"email": "david@arktype.io",
|
|
7
|
+
"url": "https://arktype.io"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/arktypeio/arktype.git",
|
|
12
|
+
"directory": "ark/attest"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./out/index.js",
|
|
16
|
+
"types": "./out/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": "./out/index.js",
|
|
19
|
+
"./internal/*": "./out/*"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"out"
|
|
23
|
+
],
|
|
24
|
+
"bin": {
|
|
25
|
+
"attest": "out/cli/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@typescript/vfs": "1.5.3",
|
|
29
|
+
"@typescript/analyze-trace": "0.10.1",
|
|
30
|
+
"arktype": "2.0.0-beta.0",
|
|
31
|
+
"@ark/fs": "0.1.0",
|
|
32
|
+
"@ark/util": "0.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"typescript": "5.5.3"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"typescript": "*"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsx ../repo/build.ts",
|
|
45
|
+
"test": "tsx ../repo/testPackage.ts",
|
|
46
|
+
"bunTest": "bun test --preload ../repo/bunTestSetup.ts"
|
|
47
|
+
}
|
|
48
|
+
}
|