@ark/attest 0.59.0-beta.2 → 0.59.0-rc.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/out/assert/chainableAssertions.js +11 -7
- package/out/cache/snapshots.d.ts +1 -1
- package/out/checker.d.ts +3 -0
- package/out/checker.js +43 -0
- package/out/config.js +5 -2
- package/out/fixtures.js +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/ts7/server.d.ts +0 -3
- package/out/ts7/server.js +2 -37
- package/package.json +4 -4
|
@@ -51,13 +51,13 @@ export class ChainableAssertions {
|
|
|
51
51
|
return this;
|
|
52
52
|
}
|
|
53
53
|
instanceOf(expected) {
|
|
54
|
-
|
|
54
|
+
const actual = this.unversionedActual;
|
|
55
|
+
if (!(actual instanceof expected)) {
|
|
55
56
|
throwAssertionError({
|
|
56
57
|
stack: this.ctx.assertionStack,
|
|
57
|
-
message: `Expected an instance of ${expected.name} (was ${
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
: this.serializedActual})`
|
|
58
|
+
message: `Expected an instance of ${expected.name} (was ${typeof actual === "object" && actual !== null ?
|
|
59
|
+
(actual.constructor?.name ?? printable(actual))
|
|
60
|
+
: printable(actual)})`
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
return this;
|
|
@@ -93,11 +93,15 @@ export class ChainableAssertions {
|
|
|
93
93
|
};
|
|
94
94
|
const toFile = (id, opts) => {
|
|
95
95
|
const expectedSnapshot = getSnapshotByName(this.ctx.position.file, id, opts?.path);
|
|
96
|
-
if (
|
|
96
|
+
if (expectedSnapshot === undefined || this.ctx.cfg.updateSnapshots) {
|
|
97
|
+
const position = caller();
|
|
98
|
+
if (this.ctx.cfg.failOnMissingSnapshots) {
|
|
99
|
+
throw new MissingSnapshotError(`.snap.toFile("${id}") at ${positionToString(position)} must be populated.`);
|
|
100
|
+
}
|
|
97
101
|
if (this.snapRequiresUpdate(expectedSnapshot)) {
|
|
98
102
|
updateExternalSnapshot({
|
|
99
103
|
serializedValue: this.serializedActual,
|
|
100
|
-
position
|
|
104
|
+
position,
|
|
101
105
|
name: id,
|
|
102
106
|
customPath: opts?.path
|
|
103
107
|
});
|
package/out/cache/snapshots.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type SnapshotArgs = {
|
|
|
6
6
|
baselinePath?: string[];
|
|
7
7
|
};
|
|
8
8
|
export declare const resolveSnapshotPath: (testFile: string, customPath: string | undefined) => string;
|
|
9
|
-
export declare const getSnapshotByName: (file: string, name: string, customPath: string | undefined) =>
|
|
9
|
+
export declare const getSnapshotByName: (file: string, name: string, customPath: string | undefined) => unknown;
|
|
10
10
|
/**
|
|
11
11
|
* Writes the update and position to cacheDir, which will eventually be read and copied to the source
|
|
12
12
|
* file by a cleanup process after all tests have completed.
|
package/out/checker.d.ts
ADDED
package/out/checker.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { throwError } from "arktype/util";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { getConfig } from "./config.js";
|
|
5
|
+
import { isTs7 } from "./utils.js";
|
|
6
|
+
// resolved relative to attest so the API matches the installed typescript
|
|
7
|
+
const requireTypeScript = createRequire(import.meta.url);
|
|
8
|
+
const isResolvable = (require, specifier) => {
|
|
9
|
+
try {
|
|
10
|
+
require.resolve(specifier);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
// tsrs's binary ships in a per-platform optional dependency, so it installs
|
|
18
|
+
// without one on unsupported platforms like Windows
|
|
19
|
+
const hasTsrsBinary = () => {
|
|
20
|
+
if (!isResolvable(requireTypeScript, "tsrs/package.json"))
|
|
21
|
+
return false;
|
|
22
|
+
if (process.env.TSRS_BINARY)
|
|
23
|
+
return true;
|
|
24
|
+
const packagePath = requireTypeScript.resolve("tsrs/package.json");
|
|
25
|
+
const requireTsrs = createRequire(packagePath);
|
|
26
|
+
const { optionalDependencies = {} } = requireTsrs(packagePath);
|
|
27
|
+
return Object.keys(optionalDependencies).some(name => isResolvable(requireTsrs, `${name}/package.json`));
|
|
28
|
+
};
|
|
29
|
+
/** the checker from attest's config, or the best one installed */
|
|
30
|
+
export const getChecker = () => {
|
|
31
|
+
const { checker } = getConfig();
|
|
32
|
+
if (checker === undefined) {
|
|
33
|
+
return (!isTs7 ? "tsjs"
|
|
34
|
+
: hasTsrsBinary() ? "tsrs"
|
|
35
|
+
: "tsgo");
|
|
36
|
+
}
|
|
37
|
+
if (checker !== "tsjs" && checker !== "tsgo" && checker !== "tsrs")
|
|
38
|
+
throwError(`checker must be "tsjs", "tsgo" or "tsrs" (was "${checker}")`);
|
|
39
|
+
if ((checker === "tsjs") === isTs7) {
|
|
40
|
+
throwError(`checker "${checker}" requires TypeScript ${checker === "tsjs" ? "<7" : "7+"} (found ${ts.version})`);
|
|
41
|
+
}
|
|
42
|
+
return checker;
|
|
43
|
+
};
|
package/out/config.js
CHANGED
|
@@ -55,7 +55,7 @@ export const attestEnvPrefix = "ATTEST_";
|
|
|
55
55
|
const addEnvConfig = (config) => {
|
|
56
56
|
// the config setup() passes to child processes comes first, so an option
|
|
57
57
|
// set on its own overrides it wherever the platform orders the environment
|
|
58
|
-
const { ATTEST_CONFIG, ...env } = process.env;
|
|
58
|
+
const { ATTEST_CONFIG, ATTEST_CACHE_DIR, ...env } = process.env;
|
|
59
59
|
if (ATTEST_CONFIG)
|
|
60
60
|
Object.assign(config, JSON.parse(ATTEST_CONFIG));
|
|
61
61
|
for (const [k, v] of Object.entries(env)) {
|
|
@@ -74,8 +74,11 @@ const addEnvConfig = (config) => {
|
|
|
74
74
|
}
|
|
75
75
|
return config;
|
|
76
76
|
};
|
|
77
|
+
// .attest in the working directory unless ATTEST_CACHE_DIR names another, as
|
|
78
|
+
// for processes testing at once from the same directory, each of which clears
|
|
79
|
+
// its cache as it starts
|
|
77
80
|
const parseConfig = () => {
|
|
78
|
-
const cacheDir = resolve(".attest");
|
|
81
|
+
const cacheDir = resolve(process.env.ATTEST_CACHE_DIR ?? ".attest");
|
|
79
82
|
return Object.assign(addEnvConfig(getDefaultAttestConfig()), {
|
|
80
83
|
cacheDir,
|
|
81
84
|
assertionCachePath: join(cacheDir, "assertions.json")
|
package/out/fixtures.js
CHANGED
|
@@ -4,7 +4,7 @@ import { writeSnapshotUpdatesOnExit } from "./cache/snapshots.js";
|
|
|
4
4
|
import { analyzeProjectAssertions } from "./cache/writeAssertionCache.js";
|
|
5
5
|
import { ensureCacheDirs, getConfig } from "./config.js";
|
|
6
6
|
import { analyzeProjectAssertions as analyzeProjectAssertionsTs7 } from "./ts7/analyze.js";
|
|
7
|
-
import { getChecker } from "./
|
|
7
|
+
import { getChecker } from "./checker.js";
|
|
8
8
|
export const setup = (options) => {
|
|
9
9
|
const { ...config } = getConfig();
|
|
10
10
|
if (options)
|
package/out/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { attest } from "./assert/attest.ts";
|
|
|
4
4
|
export { bench } from "./bench/bench.ts";
|
|
5
5
|
export { getBenchAssertionAtPosition, getTypeAssertionAtPosition, type ArgAssertionData, type LinePositionRange, type TypeAssertionData, type TypeRelationship } from "./cache/getCachedAssertions.ts";
|
|
6
6
|
export { getDefaultAttestConfig, type AttestConfig, type Checker } from "./config.ts";
|
|
7
|
-
export { getChecker } from "./
|
|
7
|
+
export { getChecker } from "./checker.ts";
|
|
8
8
|
export { contextualize } from "./utils.ts";
|
package/out/index.js
CHANGED
|
@@ -5,5 +5,5 @@ export { attest } from "./assert/attest.js";
|
|
|
5
5
|
export { bench } from "./bench/bench.js";
|
|
6
6
|
export { getBenchAssertionAtPosition, getTypeAssertionAtPosition } from "./cache/getCachedAssertions.js";
|
|
7
7
|
export { getDefaultAttestConfig } from "./config.js";
|
|
8
|
-
export { getChecker } from "./
|
|
8
|
+
export { getChecker } from "./checker.js";
|
|
9
9
|
export { contextualize } from "./utils.js";
|
package/out/ts7/server.d.ts
CHANGED
|
@@ -2,9 +2,6 @@ import { type JsonObject } from "arktype/util";
|
|
|
2
2
|
import type * as tsgoAst from "typescript/ast";
|
|
3
3
|
import type * as tsgoApi from "typescript/sync";
|
|
4
4
|
import type { LinePositionRange } from "../cache/getCachedAssertions.ts";
|
|
5
|
-
import { type Checker } from "../config.ts";
|
|
6
|
-
/** the checker from attest's config, or the best one installed */
|
|
7
|
-
export declare const getChecker: () => Checker;
|
|
8
5
|
/** populated on first use, after setup() has written attest's config */
|
|
9
6
|
export declare const ast: typeof tsgoAst;
|
|
10
7
|
export declare const getNoTruncation: () => number;
|
package/out/ts7/server.js
CHANGED
|
@@ -5,46 +5,11 @@ import { createRequire } from "node:module";
|
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { threadId } from "node:worker_threads";
|
|
7
7
|
import ts from "typescript";
|
|
8
|
+
import { getChecker } from "../checker.js";
|
|
8
9
|
import { getConfig } from "../config.js";
|
|
9
|
-
import {
|
|
10
|
+
import { narrowToNamedTestFiles } from "../utils.js";
|
|
10
11
|
// resolved relative to attest so the API matches the installed typescript
|
|
11
12
|
const requireTypeScript = createRequire(import.meta.url);
|
|
12
|
-
const isResolvable = (require, specifier) => {
|
|
13
|
-
try {
|
|
14
|
-
require.resolve(specifier);
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
// tsrs's binary ships in a per-platform optional dependency, so it installs
|
|
22
|
-
// without one on unsupported platforms like Windows
|
|
23
|
-
const hasTsrsBinary = () => {
|
|
24
|
-
if (!isResolvable(requireTypeScript, "tsrs/package.json"))
|
|
25
|
-
return false;
|
|
26
|
-
if (process.env.TSRS_BINARY)
|
|
27
|
-
return true;
|
|
28
|
-
const packagePath = requireTypeScript.resolve("tsrs/package.json");
|
|
29
|
-
const requireTsrs = createRequire(packagePath);
|
|
30
|
-
const { optionalDependencies = {} } = requireTsrs(packagePath);
|
|
31
|
-
return Object.keys(optionalDependencies).some(name => isResolvable(requireTsrs, `${name}/package.json`));
|
|
32
|
-
};
|
|
33
|
-
/** the checker from attest's config, or the best one installed */
|
|
34
|
-
export const getChecker = () => {
|
|
35
|
-
const { checker } = getConfig();
|
|
36
|
-
if (checker === undefined) {
|
|
37
|
-
return (!isTs7 ? "tsjs"
|
|
38
|
-
: hasTsrsBinary() ? "tsrs"
|
|
39
|
-
: "tsgo");
|
|
40
|
-
}
|
|
41
|
-
if (checker !== "tsjs" && checker !== "tsgo" && checker !== "tsrs")
|
|
42
|
-
throwError(`checker must be "tsjs", "tsgo" or "tsrs" (was "${checker}")`);
|
|
43
|
-
if ((checker === "tsjs") === isTs7) {
|
|
44
|
-
throwError(`checker "${checker}" requires TypeScript ${checker === "tsjs" ? "<7" : "7+"} (found ${ts.version})`);
|
|
45
|
-
}
|
|
46
|
-
return checker;
|
|
47
|
-
};
|
|
48
13
|
let compiler;
|
|
49
14
|
/** populated on first use, after setup() has written attest's config */
|
|
50
15
|
export const ast = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ark/attest",
|
|
3
|
-
"version": "0.59.0-
|
|
3
|
+
"version": "0.59.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Blass",
|
|
@@ -40,19 +40,19 @@
|
|
|
40
40
|
"@typescript/analyze-trace": "0.10.1",
|
|
41
41
|
"@typescript/vfs": "1.6.1",
|
|
42
42
|
"prettier": "3.6.2",
|
|
43
|
-
"@ark/fs": "0.57.0-
|
|
43
|
+
"@ark/fs": "0.57.0-rc.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"tsrs": "0.18.0-ts7.1.0-dev.20260929",
|
|
47
47
|
"typescript": "7.1.0-beta",
|
|
48
48
|
"typescript-6": "npm:typescript@6.0.3",
|
|
49
49
|
"typescript-7": "npm:typescript@7.1.0-beta",
|
|
50
|
-
"arktype": "3.0.0-
|
|
50
|
+
"arktype": "3.0.0-rc.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"typescript": "*",
|
|
54
54
|
"tsrs": "*",
|
|
55
|
-
"arktype": "
|
|
55
|
+
"arktype": "3.0.0-rc.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependenciesMeta": {
|
|
58
58
|
"tsrs": {
|