@ark/attest 0.11.0 → 0.12.1

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,5 +1,5 @@
1
- import type { TypeRelationshipAssertionData } from "../cache/writeAssertionCache.js";
2
- import type { AssertionContext } from "./attest.js";
1
+ import type { TypeRelationshipAssertionData } from "../cache/writeAssertionCache.ts";
2
+ import type { AssertionContext } from "./attest.ts";
3
3
  export type ThrowAssertionErrorContext = {
4
4
  message: string;
5
5
  expected?: unknown;
@@ -12,9 +12,10 @@ export type MappedTypeAssertionResult = {
12
12
  actual: unknown;
13
13
  expected?: unknown;
14
14
  } | null;
15
+ export type TypeAssertionMapper = (data: TypeRelationshipAssertionData, ctx: AssertionContext) => MappedTypeAssertionResult;
15
16
  export declare class TypeAssertionMapping {
16
- fn: (data: TypeRelationshipAssertionData, ctx: AssertionContext) => MappedTypeAssertionResult;
17
- constructor(fn: (data: TypeRelationshipAssertionData, ctx: AssertionContext) => MappedTypeAssertionResult);
17
+ fn: TypeAssertionMapper;
18
+ constructor(fn: TypeAssertionMapper);
18
19
  }
19
20
  export declare const versionableAssertion: (fn: AssertFn) => AssertFn;
20
21
  export declare const assertEquals: AssertFn;
@@ -1,9 +1,9 @@
1
1
  import { type SourcePosition } from "@ark/fs";
2
2
  import type { ErrorMessage } from "@ark/util";
3
- import type { Measure } from "../bench/measure.js";
4
- import { type VersionedTypeAssertion } from "../cache/getCachedAssertions.js";
5
- import { type AttestConfig } from "../config.js";
6
- import { ChainableAssertions, type AssertionKind, type rootAssertions } from "./chainableAssertions.js";
3
+ import type { Measure } from "../bench/measure.ts";
4
+ import { type VersionedTypeAssertion } from "../cache/getCachedAssertions.ts";
5
+ import { type AttestConfig } from "../config.ts";
6
+ import { ChainableAssertions, type AssertionKind, type rootAssertions } from "./chainableAssertions.ts";
7
7
  export type AttestFn = {
8
8
  <expected>(actual: expected): rootAssertions<expected, AssertionKind>;
9
9
  <expected, actual extends expected = never>(...args: actual extends never ? [
@@ -1,7 +1,7 @@
1
1
  import { snapshot, type Constructor } from "@ark/util";
2
2
  import { type validateTypeRoot } from "arktype";
3
- import type { Completions } from "../cache/writeAssertionCache.js";
4
- import type { AssertionContext } from "./attest.js";
3
+ import type { Completions } from "../cache/writeAssertionCache.ts";
4
+ import type { AssertionContext } from "./attest.ts";
5
5
  export type ChainableAssertionOptions = {
6
6
  allowRegex?: boolean;
7
7
  defaultExpected?: unknown;
@@ -1,9 +1,11 @@
1
1
  import { caller } from "@ark/fs";
2
2
  import { printable, snapshot } from "@ark/util";
3
+ import prettier from "@prettier/sync";
3
4
  import { type } from "arktype";
4
5
  import * as assert from "node:assert/strict";
5
6
  import { isDeepStrictEqual } from "node:util";
6
7
  import { getSnapshotByName, queueSnapshotUpdate, updateExternalSnapshot } from "../cache/snapshots.js";
8
+ import { getConfig } from "../config.js";
7
9
  import { chainableNoOpProxy } from "../utils.js";
8
10
  import { TypeAssertionMapping, assertEqualOrMatching, assertEquals, assertSatisfies, callAssertedFunction, getThrownMessage, throwAssertionError } from "./assertions.js";
9
11
  export class ChainableAssertions {
@@ -153,7 +155,7 @@ export class ChainableAssertions {
153
155
  return {
154
156
  get toString() {
155
157
  self.ctx.actual = new TypeAssertionMapping(data => ({
156
- actual: data.args[0].type
158
+ actual: formatTypeString(data.args[0].type)
157
159
  }));
158
160
  self.ctx.allowRegex = true;
159
161
  return self.immediateOrChained();
@@ -175,3 +177,14 @@ const checkCompletionsForErrors = (completions) => {
175
177
  if (typeof completions === "string")
176
178
  throw new Error(completions);
177
179
  };
180
+ const declarationPrefix = "type T = ";
181
+ const formatTypeString = (typeString) => prettier
182
+ .format(`${declarationPrefix}${typeString}`, {
183
+ semi: false,
184
+ printWidth: 60,
185
+ trailingComma: "none",
186
+ parser: "typescript",
187
+ ...getConfig().typeToStringFormat
188
+ })
189
+ .slice(declarationPrefix.length)
190
+ .trimEnd();
@@ -1,5 +1,5 @@
1
- import type { BenchContext } from "./bench.js";
2
- import { type MarkMeasure, type Measure, type MeasureComparison } from "./measure.js";
1
+ import type { BenchContext } from "./bench.ts";
2
+ import { type MarkMeasure, type Measure, type MeasureComparison } from "./measure.ts";
3
3
  export declare const queueBaselineUpdateIfNeeded: (updated: Measure | MarkMeasure, baseline: Measure | MarkMeasure | undefined, ctx: BenchContext) => void;
4
4
  /** Pretty print comparison and set the process.exitCode to 1 if delta threshold is exceeded */
5
5
  export declare const compareToBaseline: (result: MeasureComparison, ctx: BenchContext) => void;
@@ -1,7 +1,7 @@
1
1
  import { type SourcePosition } from "@ark/fs";
2
- import { type ParsedAttestConfig } from "../config.js";
3
- import { type MarkMeasure, type Measure, type TimeUnit } from "./measure.js";
4
- import { type BenchTypeAssertions } from "./type.js";
2
+ import { type ParsedAttestConfig } from "../config.ts";
3
+ import { type MarkMeasure, type Measure, type TimeUnit } from "./measure.ts";
4
+ import { type BenchTypeAssertions } from "./type.ts";
5
5
  export type StatName = keyof typeof stats;
6
6
  export type TimeAssertionName = StatName | "mark";
7
7
  type BenchFn = <fn extends BenchableFunction>(name: string, fn: fn, options?: BenchOptions) => InitialBenchAssertions<fn>;
@@ -14,10 +14,10 @@ export declare const stats: {
14
14
  median: (callTimes: number[]) => number;
15
15
  };
16
16
  export declare class BenchAssertions<Fn extends BenchableFunction, NextAssertions = BenchTypeAssertions, ReturnedAssertions = Fn extends () => Promise<void> ? Promise<NextAssertions> : NextAssertions> {
17
- private fn;
18
- private ctx;
19
17
  private label;
20
18
  private lastCallTimes;
19
+ private fn;
20
+ private ctx;
21
21
  constructor(fn: Fn, ctx: BenchContext);
22
22
  private applyCallTimeHooks;
23
23
  private callTimesSync;
@@ -45,11 +45,11 @@ export const stats = {
45
45
  }
46
46
  };
47
47
  class ResultCollector {
48
- ctx;
49
48
  results = [];
50
49
  benchStart = performance.now();
51
50
  bounds;
52
51
  lastInvocationStart;
52
+ ctx;
53
53
  constructor(ctx) {
54
54
  this.ctx = ctx;
55
55
  // By default, will run for either 5 seconds or 100_000 call sets (of 1000 calls), whichever comes first
@@ -95,10 +95,10 @@ const loopAsyncCalls = async (fn, ctx) => {
95
95
  return collector.results;
96
96
  };
97
97
  export class BenchAssertions {
98
- fn;
99
- ctx;
100
98
  label;
101
99
  lastCallTimes;
100
+ fn;
101
+ ctx;
102
102
  constructor(fn, ctx) {
103
103
  this.fn = fn;
104
104
  this.ctx = ctx;
@@ -1,4 +1,4 @@
1
- import type { StatName } from "./bench.js";
1
+ import type { StatName } from "./bench.ts";
2
2
  type MeasureUnit = TimeUnit | TypeUnit;
3
3
  export type Measure<Unit extends MeasureUnit = MeasureUnit> = [
4
4
  value: number,
@@ -1,5 +1,5 @@
1
- import type { BenchContext } from "./bench.js";
2
- import { type Measure, type TypeUnit } from "./measure.js";
1
+ import type { BenchContext } from "./bench.ts";
2
+ import { type Measure, type TypeUnit } from "./measure.ts";
3
3
  export type BenchTypeAssertions = {
4
4
  types: (instantiations?: Measure<TypeUnit>) => void;
5
5
  };
@@ -1,5 +1,5 @@
1
1
  import { type SourcePosition } from "@ark/fs";
2
- import type { AssertionsByFile, TypeAssertionData, TypeAssertionKind } from "./writeAssertionCache.js";
2
+ import type { AssertionsByFile, TypeAssertionData, TypeAssertionKind } from "./writeAssertionCache.ts";
3
3
  export type VersionedAssertionsByFile = [
4
4
  tsVersion: string,
5
5
  relationshipAssertions: AssertionsByFile,
package/out/cache/ts.d.ts CHANGED
@@ -2,13 +2,13 @@ import { type SourcePosition } from "@ark/fs";
2
2
  import * as tsvfs from "@typescript/vfs";
3
3
  import ts from "typescript";
4
4
  export declare class TsServer {
5
- private tsConfigInfo;
6
5
  rootFiles: string[];
7
6
  virtualEnv: tsvfs.VirtualTypeScriptEnvironment;
8
7
  program: ts.Program;
9
8
  private static _instance;
10
9
  static get instance(): TsServer;
11
- private constructor();
10
+ private tsConfigInfo;
11
+ constructor(tsConfigInfo?: TsconfigInfo);
12
12
  getSourceFileOrThrow(path: string): ts.SourceFile;
13
13
  }
14
14
  export declare const nearestCallExpressionChild: (node: ts.Node, position: number) => ts.CallExpression;
package/out/cache/ts.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { fromCwd } from "@ark/fs";
2
2
  import { throwInternalError } from "@ark/util";
3
- import prettier from "@prettier/sync";
4
3
  import * as tsvfs from "@typescript/vfs";
5
4
  import { readFileSync } from "node:fs";
6
5
  import { dirname, join } from "node:path";
7
6
  import ts from "typescript";
8
7
  import { getConfig } from "../config.js";
9
8
  export class TsServer {
10
- tsConfigInfo;
11
9
  rootFiles;
12
10
  virtualEnv;
13
11
  program;
@@ -15,14 +13,15 @@ export class TsServer {
15
13
  static get instance() {
16
14
  return new TsServer();
17
15
  }
18
- constructor(tsConfigInfo = getTsConfigInfoOrThrow()) {
19
- this.tsConfigInfo = tsConfigInfo;
16
+ tsConfigInfo;
17
+ constructor(tsConfigInfo) {
20
18
  if (TsServer._instance)
21
19
  return TsServer._instance;
22
- const tsLibPaths = getTsLibFiles(tsConfigInfo.parsed.options);
20
+ this.tsConfigInfo = tsConfigInfo ?? getTsConfigInfoOrThrow();
21
+ const tsLibPaths = getTsLibFiles(this.tsConfigInfo.parsed.options);
23
22
  // TS represents windows paths as `C:/Users/ssalb/...`
24
23
  const normalizedCwd = fromCwd().replaceAll(/\\/g, "/");
25
- this.rootFiles = tsConfigInfo.parsed.fileNames.filter(path => path.startsWith(normalizedCwd));
24
+ this.rootFiles = this.tsConfigInfo.parsed.fileNames.filter(path => path.startsWith(normalizedCwd));
26
25
  const system = tsvfs.createFSBackedSystem(tsLibPaths.defaultMapFromNodeModules, dirname(this.tsConfigInfo.path), ts);
27
26
  this.virtualEnv = tsvfs.createVirtualTypeScriptEnvironment(system, this.rootFiles, ts, this.tsConfigInfo.parsed.options);
28
27
  this.program = this.virtualEnv.languageService.getProgram();
@@ -58,10 +57,11 @@ export const getAbsolutePosition = (file, position) => {
58
57
  return pos;
59
58
  };
60
59
  export const getTsConfigInfoOrThrow = () => {
61
- const config = getConfig().tsconfig;
62
- const configFilePath = config ?? ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
60
+ const config = getConfig();
61
+ const tsconfig = config.tsconfig;
62
+ const configFilePath = tsconfig ?? ts.findConfigFile(fromCwd(), ts.sys.fileExists, "tsconfig.json");
63
63
  if (!configFilePath) {
64
- throw new Error(`File ${config ?? join(fromCwd(), "tsconfig.json")} must exist.`);
64
+ throw new Error(`File ${tsconfig ?? join(fromCwd(), "tsconfig.json")} must exist.`);
65
65
  }
66
66
  const configFileText = readFileSync(configFilePath).toString();
67
67
  const result = ts.parseConfigFileTextToJson(configFilePath, configFileText);
@@ -72,8 +72,9 @@ export const getTsConfigInfoOrThrow = () => {
72
72
  getNewLine: () => ts.sys.newLine
73
73
  }));
74
74
  }
75
- const configObject = result.config;
76
- const configParseResult = ts.parseJsonConfigFileContent(configObject, ts.sys, dirname(configFilePath), {}, configFilePath);
75
+ const configJson = result.config;
76
+ configJson.compilerOptions = Object.assign(configJson.compilerOptions ?? {}, config.compilerOptions);
77
+ const configParseResult = ts.parseJsonConfigFileContent(configJson, ts.sys, dirname(configFilePath), {}, configFilePath);
77
78
  if (configParseResult.errors.length > 0) {
78
79
  throw new Error(ts.formatDiagnostics(configParseResult.errors, {
79
80
  getCanonicalFileName: fileName => fileName,
@@ -97,43 +98,16 @@ export const getTsLibFiles = (tsconfigOptions) => {
97
98
  export const getProgram = (env) => env?.languageService.getProgram() ??
98
99
  TsServer.instance.virtualEnv.languageService.getProgram();
99
100
  export const getInternalTypeChecker = (env) => getProgram(env).getTypeChecker();
100
- const declarationPrefix = "type T = ";
101
- const baseTypeFormatOptions = {
102
- semi: false,
103
- printWidth: 60,
104
- trailingComma: "none",
105
- parser: "typescript"
106
- };
107
- const formatTypeString = (typeString) => prettier
108
- .format(`${declarationPrefix}${typeString}`, {
109
- ...baseTypeFormatOptions,
110
- ...getConfig().typeToStringFormat
111
- })
112
- .slice(declarationPrefix.length)
113
- .trimEnd();
114
- const replaceKnownInvalidSyntax = (typeString) => {
115
- // Match '...' and '... x more ...' (known truncated type syntax)
116
- const regex = /\.\.\.\s*(\d+\s*more\s*\.\.\.)?/g;
117
- // replace these with a string literal "..." so that they can still
118
- // form valid expressions, e.g. "..."[]
119
- return typeString.replaceAll(regex, '"..."');
120
- };
121
101
  export const getStringifiableType = (node) => {
122
102
  const typeChecker = getInternalTypeChecker();
123
103
  const nodeType = typeChecker.getTypeAtLocation(node);
124
104
  let stringified = typeChecker.typeToString(nodeType);
125
- try {
126
- stringified = formatTypeString(stringified);
127
- }
128
- catch {
129
- // if formatting fails (e.g. due to custom typeToString syntax like ... X more),
130
- // try to comment out problematic sections
131
- try {
132
- stringified = formatTypeString(replaceKnownInvalidSyntax(stringified));
133
- }
134
- catch {
135
- // if still fails somehow, just swallow the error and use the unformatted type
136
- }
105
+ if (stringified.includes("...")) {
106
+ const nonTruncated = typeChecker.typeToString(nodeType, undefined, ts.TypeFormatFlags.NoTruncation);
107
+ if (nonTruncated.includes(" any") && !stringified.includes(" any"))
108
+ stringified = nonTruncated.replaceAll(" any", " cyclic");
109
+ else
110
+ stringified = nonTruncated;
137
111
  }
138
112
  return Object.assign(nodeType, {
139
113
  toString: () => stringified,
@@ -1,6 +1,6 @@
1
1
  import * as tsvfs from "@typescript/vfs";
2
2
  import ts from "typescript";
3
- import type { AssertionsByFile, LinePositionRange } from "./writeAssertionCache.js";
3
+ import type { AssertionsByFile, LinePositionRange } from "./writeAssertionCache.ts";
4
4
  export declare const getCallLocationFromCallExpression: (callExpression: ts.CallExpression) => LinePositionRange;
5
5
  export declare const gatherInlineInstantiationData: (file: ts.SourceFile, fileAssertions: AssertionsByFile, attestAliasInstantiationMethodCalls: string[]) => void;
6
6
  export declare const getCallExpressionsByName: (startNode: ts.Node, names: string[], isSnapCall?: boolean) => ts.CallExpression[];
@@ -76,9 +76,10 @@ export const getInstantiationsContributedByNode = (file, benchBlock) => {
76
76
  return instantiationsWithNode - instantiationsByPath[fakePath];
77
77
  };
78
78
  export const createOrUpdateFile = (env, fileName, fileText) => {
79
- env.sys.fileExists(fileName) ?
80
- env.updateFile(fileName, fileText)
81
- : env.createFile(fileName, fileText);
79
+ if (env.sys.fileExists(fileName))
80
+ env.updateFile(fileName, fileText);
81
+ else
82
+ env.createFile(fileName, fileText);
82
83
  return env.getSourceFile(fileName);
83
84
  };
84
85
  const getInstantiationsWithFile = (fileText, fileName) => {
@@ -1,6 +1,6 @@
1
1
  import type { LinePosition } from "@ark/fs";
2
2
  import ts from "typescript";
3
- import { type StringifiableType } from "./ts.js";
3
+ import { type StringifiableType } from "./ts.ts";
4
4
  export type AssertionsByFile = Record<string, TypeAssertionData[]>;
5
5
  export declare const analyzeProjectAssertions: () => AssertionsByFile;
6
6
  export declare const getAssertionsInFile: (file: ts.SourceFile, diagnosticsByFile: DiagnosticsByFile, attestAliases: string[]) => TypeAssertionData[];
package/out/config.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { type autocomplete } from "@ark/util";
2
2
  import type * as prettier from "prettier";
3
- import { type TsVersionData } from "./tsVersioning.js";
3
+ import type ts from "typescript";
4
+ import { type TsVersionData } from "./tsVersioning.ts";
4
5
  export type TsVersionAliases = autocomplete<"*"> | string[];
5
6
  type BaseAttestConfig = {
6
7
  tsconfig: string | undefined;
8
+ compilerOptions: ts.CompilerOptions;
7
9
  updateSnapshots: boolean;
8
10
  /** A string or list of strings representing the TypeScript version aliases to run.
9
11
  *
package/out/config.js CHANGED
@@ -5,6 +5,7 @@ import { join, resolve } from "node:path";
5
5
  import { findAttestTypeScriptVersions } from "./tsVersioning.js";
6
6
  export const getDefaultAttestConfig = () => ({
7
7
  tsconfig: existsSync(fromCwd("tsconfig.json")) ? fromCwd("tsconfig.json") : undefined,
8
+ compilerOptions: {},
8
9
  attestAliases: ["attest", "attestInternal"],
9
10
  updateSnapshots: false,
10
11
  skipTypes: false,
@@ -18,11 +19,22 @@ export const getDefaultAttestConfig = () => ({
18
19
  shouldFormat: true,
19
20
  typeToStringFormat: {}
20
21
  });
21
- const hasFlag = (flag) => process.argv.some(arg => arg.includes(flag));
22
+ const flagAliases = {
23
+ updateSnapshots: ["u", "update"]
24
+ };
25
+ const findParamIndex = (flagOrAlias) => process.argv.findIndex(arg => arg === `-${flagOrAlias}` || arg === `--${flagOrAlias}`);
26
+ const hasFlag = (flag) => findParamIndex(flag) !== -1 ||
27
+ flagAliases[flag]?.some(alias => findParamIndex(alias) !== -1);
22
28
  const getParamValue = (param) => {
23
- const paramIndex = process.argv.findIndex(arg => arg.includes(param));
24
- if (paramIndex === -1)
25
- return undefined;
29
+ let paramIndex = findParamIndex(param);
30
+ if (paramIndex === -1) {
31
+ if (!flagAliases[param])
32
+ return;
33
+ for (let i = 0; i < flagAliases[param].length && paramIndex === -1; i++)
34
+ paramIndex = findParamIndex(flagAliases[param][i]);
35
+ if (paramIndex === -1)
36
+ return;
37
+ }
26
38
  const raw = process.argv[paramIndex + 1];
27
39
  if (raw === "true")
28
40
  return true;
@@ -32,7 +44,7 @@ const getParamValue = (param) => {
32
44
  return tryParseNumber(raw, { errorOnFail: true });
33
45
  if (param === "tsVersions" || param === "attestAliases")
34
46
  return raw.split(",");
35
- if (param === "typeToStringFormat")
47
+ if (param === "typeToStringFormat" || param === "compilerOptions")
36
48
  return JSON.parse(raw);
37
49
  return raw;
38
50
  };
@@ -77,7 +89,7 @@ const parseConfig = () => {
77
89
  const isTsVersionAliases = (v) => typeof v === "string" || (isArray(v) && typeof v[0] === "string");
78
90
  const parseTsVersions = (aliases) => {
79
91
  const versions = findAttestTypeScriptVersions();
80
- if (aliases === "*")
92
+ if (aliases === "*" || (isArray(aliases) && aliases[0] === "*"))
81
93
  return versions;
82
94
  return liftArray(aliases).map(alias => {
83
95
  const matching = versions.find(v => v.alias === alias);
package/out/fixtures.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type AttestConfig } from "./config.js";
1
+ import { type AttestConfig } from "./config.ts";
2
2
  export declare const setup: (options?: Partial<AttestConfig>) => typeof teardown;
3
3
  export declare const writeAssertionData: (toPath: string) => void;
4
4
  export declare const cleanup: () => void;
package/out/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.js";
1
+ export { cleanup, setup, teardown, writeAssertionData } from "./fixtures.ts";
2
2
  export { caller, type CallerOfOptions } from "@ark/fs";
3
- export { attest } from "./assert/attest.js";
4
- export { bench } from "./bench/bench.js";
5
- export { getBenchAssertionsAtPosition, getTypeAssertionsAtPosition } from "./cache/getCachedAssertions.js";
6
- export type { ArgAssertionData, LinePositionRange, TypeAssertionData, TypeRelationship } from "./cache/writeAssertionCache.js";
7
- export { getDefaultAttestConfig, type AttestConfig } from "./config.js";
8
- export { findAttestTypeScriptVersions, getPrimaryTsVersionUnderTest } from "./tsVersioning.js";
9
- export { contextualize } from "./utils.js";
3
+ export { attest } from "./assert/attest.ts";
4
+ export { bench } from "./bench/bench.ts";
5
+ export { getBenchAssertionsAtPosition, getTypeAssertionsAtPosition } from "./cache/getCachedAssertions.ts";
6
+ export type { ArgAssertionData, LinePositionRange, TypeAssertionData, TypeRelationship } from "./cache/writeAssertionCache.ts";
7
+ export { getDefaultAttestConfig, type AttestConfig } from "./config.ts";
8
+ export { findAttestTypeScriptVersions, getPrimaryTsVersionUnderTest } from "./tsVersioning.ts";
9
+ export { contextualize } from "./utils.ts";
@@ -102,7 +102,8 @@ export const findAttestTypeScriptVersions = () => {
102
102
  if (!existsSync(path)) {
103
103
  throw Error(`TypeScript version ${alias} specified in ${packageJsonPath} must be installed at ${path} `);
104
104
  }
105
- const version = readJson(join(path, "package.json")).version;
105
+ const version = readJson(join(path, "package.json"))
106
+ .version;
106
107
  versions.push({
107
108
  alias,
108
109
  version,
package/out/utils.js CHANGED
@@ -8,19 +8,26 @@ export const getFileKey = (path) => relative(".", path);
8
8
  export const chainableNoOpProxy = new Proxy(() => chainableNoOpProxy, {
9
9
  get: () => chainableNoOpProxy
10
10
  });
11
+ const testDirName = "__tests__";
12
+ const testSuffix = ".test.ts";
11
13
  const contextualizeRoot = (first, contextualTests) => {
12
14
  const describe = globalThis.describe;
13
15
  if (!describe) {
14
16
  throw new Error(`contextualize cannot be used without a global 'describe' function.`);
15
17
  }
16
- const fileName = basename(caller().file);
18
+ const filePath = caller().file;
19
+ const testsDirChar = filePath.search(testDirName);
20
+ const suiteNamePath = testsDirChar === -1 ?
21
+ basename(filePath)
22
+ : filePath.slice(testsDirChar + testDirName.length);
23
+ const suiteName = suiteNamePath.slice(0, -testSuffix.length);
17
24
  if (contextualTests) {
18
- describe(fileName, () => contextualTests((name, test) => {
25
+ describe(suiteName, () => contextualTests((name, test) => {
19
26
  it(name, () => test(first()));
20
27
  }));
21
28
  }
22
29
  else
23
- describe(fileName, first);
30
+ describe(suiteName, first);
24
31
  };
25
32
  const contextualizeEach = (name, createCtx, tests) => {
26
33
  const describe = globalThis.describe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ark/attest",
3
- "version": "0.11.0",
3
+ "version": "0.12.1",
4
4
  "author": {
5
5
  "name": "David Blass",
6
6
  "email": "david@arktype.io",
@@ -15,8 +15,14 @@
15
15
  "main": "./out/index.js",
16
16
  "types": "./out/index.d.ts",
17
17
  "exports": {
18
- ".": "./out/index.js",
19
- "./internal/*": "./out/*"
18
+ ".": {
19
+ "ark-ts": "./index.ts",
20
+ "default": "./out/index.js"
21
+ },
22
+ "./internal/*": {
23
+ "ark-ts": "./*",
24
+ "default": "./out/*"
25
+ }
20
26
  },
21
27
  "files": [
22
28
  "out"
@@ -25,13 +31,13 @@
25
31
  "attest": "out/cli/cli.js"
26
32
  },
27
33
  "dependencies": {
28
- "@typescript/vfs": "1.5.3",
34
+ "@typescript/vfs": "1.6.0",
29
35
  "@typescript/analyze-trace": "0.10.1",
30
36
  "prettier": "3.3.3",
31
37
  "@prettier/sync": "0.5.2",
32
- "@ark/util": "0.2.0",
33
- "@ark/fs": "0.2.0",
34
- "arktype": "2.0.0-beta.3"
38
+ "arktype": "2.0.0-beta.6",
39
+ "@ark/util": "0.2.2",
40
+ "@ark/fs": "0.2.2"
35
41
  },
36
42
  "devDependencies": {
37
43
  "typescript": "5.5.4"
@@ -43,8 +49,7 @@
43
49
  "access": "public"
44
50
  },
45
51
  "scripts": {
46
- "build": "tsx ../repo/build.ts",
47
- "test": "tsx ../repo/testPackage.ts",
48
- "bunTest": "bun test --preload ../repo/bunTestSetup.ts"
52
+ "build": "ts ../repo/build.ts",
53
+ "test": "ts ../repo/testPackage.ts"
49
54
  }
50
55
  }