@ark/attest 0.59.0-beta.1 → 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.
@@ -1,4 +1,4 @@
1
- import { constructorNameOf, expressionOf, printable, throwInternalError } from "@ark/util";
1
+ import { constructorNameOf, expressionOf, printable, throwInternalError } from "arktype/util";
2
2
  import * as assert from "node:assert/strict";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  export const throwAssertionError = ({ stack, ...errorArgs }) => {
@@ -125,10 +125,7 @@ const unversionedAssertEquals = (expected, actual, ctx) => {
125
125
  throwUnequal("Expected values to be strictly deep-equal:", expected, actual);
126
126
  }
127
127
  }
128
- else if (typeof expected === "object" ||
129
- typeof expected === "function" ||
130
- typeof actual === "function" ||
131
- typeof actual === "function") {
128
+ else if (isReference(expected) || isReference(actual)) {
132
129
  throwUnequal("Assertion including at least one function or object was not between reference equal items", expected, actual);
133
130
  // guaranteed to be two primitives at this point
134
131
  }
@@ -1,5 +1,5 @@
1
1
  import { type SourcePosition } from "@ark/fs";
2
- import type { ErrorMessage } from "@ark/util";
2
+ import type { ErrorMessage } from "arktype/util";
3
3
  import type { Measure } from "../bench/measure.ts";
4
4
  import { type TypeAssertionData } from "../cache/getCachedAssertions.ts";
5
5
  import { type AttestConfig } from "../config.ts";
@@ -1,4 +1,4 @@
1
- import { snapshot, type Constructor, type ErrorType, type isDisjoint } from "@ark/util";
1
+ import { snapshot, type Constructor, type ErrorType, type isDisjoint } from "arktype/util";
2
2
  import { type } from "arktype";
3
3
  import type { Completions } from "../cache/getCachedAssertions.ts";
4
4
  import type { AssertionContext } from "./attest.ts";
@@ -1,5 +1,5 @@
1
1
  import { caller, positionToString } from "@ark/fs";
2
- import { printable, snapshot } from "@ark/util";
2
+ import { printable, snapshot } from "arktype/util";
3
3
  import prettier from "@prettier/sync";
4
4
  import { type } from "arktype";
5
5
  import { isDeepStrictEqual } from "node:util";
@@ -51,13 +51,13 @@ export class ChainableAssertions {
51
51
  return this;
52
52
  }
53
53
  instanceOf(expected) {
54
- if (!(this.versionableActual instanceof expected)) {
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 ${(typeof this.versionableActual === "object" &&
58
- this.versionableActual !== null) ?
59
- this.versionableActual.constructor.name
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 (!expectedSnapshot || this.ctx.cfg.updateSnapshots) {
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: caller(),
104
+ position,
101
105
  name: id,
102
106
  customPath: opts?.path
103
107
  });
@@ -1,4 +1,4 @@
1
- import { snapshot, throwInternalError } from "@ark/util";
1
+ import { snapshot, throwInternalError } from "arktype/util";
2
2
  import process from "node:process";
3
3
  import { throwAssertionError } from "../assert/assertions.js";
4
4
  import { queueSnapshotUpdate, writeSnapshotUpdatesOnExit } from "../cache/snapshots.js";
package/out/bench/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { caller } from "@ark/fs";
2
- import { throwInternalError } from "@ark/util";
2
+ import { throwInternalError } from "arktype/util";
3
3
  import ts from "typescript";
4
4
  import { getBenchAssertionAtPosition } from "../cache/getCachedAssertions.js";
5
5
  import { TsServer, getAbsolutePosition, getAncestors, getDescendants, nearestCallExpressionChild } from "../cache/ts.js";
@@ -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) => object;
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.
@@ -1,5 +1,5 @@
1
1
  import { filePath, positionToString, readFile, readJson, shell, writeFile, writeJson } from "@ark/fs";
2
- import { throwInternalError } from "@ark/util";
2
+ import { throwInternalError } from "arktype/util";
3
3
  import { existsSync } from "node:fs";
4
4
  import { basename, dirname, isAbsolute, join } from "node:path";
5
5
  import { getConfig } from "../config.js";
package/out/cache/ts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { fromCwd, readFile } from "@ark/fs";
2
- import { printable, throwError, throwInternalError } from "@ark/util";
2
+ import { printable, throwError, throwInternalError } from "arktype/util";
3
3
  import * as tsvfs from "@typescript/vfs";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { resolve, dirname, join } from "node:path";
@@ -1,5 +1,5 @@
1
1
  import { filePath } from "@ark/fs";
2
- import { throwInternalError } from "@ark/util";
2
+ import { throwInternalError } from "arktype/util";
3
3
  import * as tsvfs from "@typescript/vfs";
4
4
  import ts from "typescript";
5
5
  import { getConfig } from "../config.js";
@@ -1,4 +1,4 @@
1
- import { flatMorph } from "@ark/util";
1
+ import { flatMorph } from "arktype/util";
2
2
  import ts from "typescript";
3
3
  import { getConfig } from "../config.js";
4
4
  import { getFileKey } from "../utils.js";
@@ -0,0 +1,3 @@
1
+ import { type Checker } from "./config.ts";
2
+ /** the checker from attest's config, or the best one installed */
3
+ export declare const getChecker: () => Checker;
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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type JsonObject } from "@ark/util";
1
+ import { type JsonObject } from "arktype/util";
2
2
  import type * as prettier from "prettier";
3
3
  /** tsjs is TypeScript's JS API, tsgo its native port and tsrs a Rust port */
4
4
  export type Checker = "tsjs" | "tsgo" | "tsrs";
package/out/config.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ensureDir, fromCwd } from "@ark/fs";
2
- import { tryParseNumber } from "@ark/util";
2
+ import { tryParseNumber } from "arktype/util";
3
3
  import { existsSync } from "node:fs";
4
4
  import { join, resolve } from "node:path";
5
5
  export const getDefaultAttestConfig = () => ({
@@ -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 "./ts7/server.js";
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 "./ts7/server.ts";
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 "./ts7/server.js";
8
+ export { getChecker } from "./checker.js";
9
9
  export { contextualize } from "./utils.js";
@@ -1,4 +1,4 @@
1
- import { flatMorph, throwInternalError } from "@ark/util";
1
+ import { flatMorph, throwInternalError } from "arktype/util";
2
2
  import { getConfig } from "../config.js";
3
3
  import { getFileKey } from "../utils.js";
4
4
  import { getInstantiationsContributedByNodes } from "./instantiations.js";
@@ -1,4 +1,4 @@
1
- import { throwError } from "@ark/util";
1
+ import { throwError } from "arktype/util";
2
2
  import { execFileSync } from "node:child_process";
3
3
  import { basename, dirname, extname, join } from "node:path";
4
4
  import { fileURLToPath } from "node:url";
@@ -1,10 +1,7 @@
1
- import { type JsonObject } from "@ark/util";
1
+ 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
@@ -1,50 +1,15 @@
1
1
  import { fromCwd } from "@ark/fs";
2
- import { throwError, throwInternalError } from "@ark/util";
2
+ import { throwError, throwInternalError } from "arktype/util";
3
3
  import { existsSync } from "node:fs";
4
4
  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 { isTs7, narrowToNamedTestFiles } from "../utils.js";
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 = {};
@@ -1,5 +1,5 @@
1
1
  import { positionToString } from "@ark/fs";
2
- import { throwInternalError } from "@ark/util";
2
+ import { throwInternalError } from "arktype/util";
3
3
  import { TsgoServer, ast, getDescendants } from "./server.js";
4
4
  export const getSnapCallArgs = (position, functionName) => {
5
5
  const file = TsgoServer.instance.getSourceFileOrThrow(position.file);
package/out/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { caller } from "@ark/fs";
2
- import { throwError } from "@ark/util";
2
+ import { throwError } from "arktype/util";
3
3
  import { existsSync } from "node:fs";
4
4
  import { basename, relative, resolve } from "node:path";
5
5
  import ts from "typescript";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.59.0-beta.1",
3
+ "version": "0.59.0-rc.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "David Blass",
@@ -40,20 +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-beta.1",
44
- "@ark/schema": "0.57.0-beta.1",
45
- "@ark/util": "0.57.0-beta.1",
46
- "arktype": "3.0.0-beta.1"
43
+ "@ark/fs": "0.57.0-rc.0"
47
44
  },
48
45
  "devDependencies": {
49
46
  "tsrs": "0.18.0-ts7.1.0-dev.20260929",
50
47
  "typescript": "7.1.0-beta",
51
48
  "typescript-6": "npm:typescript@6.0.3",
52
- "typescript-7": "npm:typescript@7.1.0-beta"
49
+ "typescript-7": "npm:typescript@7.1.0-beta",
50
+ "arktype": "3.0.0-rc.0"
53
51
  },
54
52
  "peerDependencies": {
55
53
  "typescript": "*",
56
- "tsrs": "*"
54
+ "tsrs": "*",
55
+ "arktype": "3.0.0-rc.0"
57
56
  },
58
57
  "peerDependenciesMeta": {
59
58
  "tsrs": {