@useblacksmith/vitest 0.3.0 → 0.4.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/dist/affected.d.ts +3 -1
- package/dist/affected.js +14 -3
- package/dist/cache.d.ts +2 -0
- package/dist/cache.js +2 -2
- package/package.json +3 -2
package/dist/affected.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { BloomFilter } from './bloom.js';
|
|
|
2
2
|
import type { Reporter, TestModule, TestRunEndReason, TestSpecification, VCSProvider, VCSProviderOptions, Vitest } from 'vitest/node';
|
|
3
3
|
import { type Tree } from './git.js';
|
|
4
4
|
export declare const SNAPSHOT_FILE = "blacksmith.json";
|
|
5
|
-
declare const SNAPSHOT_VERSION =
|
|
5
|
+
declare const SNAPSHOT_VERSION = 5;
|
|
6
6
|
/** A `dependencies` entry, compiled: test files matching `tests` depend on files matching `deps`; both root-relative. */
|
|
7
7
|
export interface DependencyRule {
|
|
8
8
|
tests: (file: string) => boolean;
|
|
@@ -20,6 +20,8 @@ export interface Shard {
|
|
|
20
20
|
export interface Snapshot {
|
|
21
21
|
version: typeof SNAPSHOT_VERSION;
|
|
22
22
|
head: string;
|
|
23
|
+
/** Vitest's root relative to the repository, so one package's snapshot never vouches for another's. */
|
|
24
|
+
root: string;
|
|
23
25
|
shard: Shard | null;
|
|
24
26
|
/** Names of the projects the run covered (`--project` narrows them). */
|
|
25
27
|
projects: string[];
|
package/dist/affected.js
CHANGED
|
@@ -11,7 +11,7 @@ import { shardOwner } from './sequencer.js';
|
|
|
11
11
|
export const SNAPSHOT_FILE = 'blacksmith.json';
|
|
12
12
|
// Bumped whenever the snapshot's shape changes or the records an anchor
|
|
13
13
|
// vouches for gain a kind of dependency, so an older snapshot is not trusted.
|
|
14
|
-
const SNAPSHOT_VERSION =
|
|
14
|
+
const SNAPSHOT_VERSION = 5;
|
|
15
15
|
export function compileDependencies(dependencies) {
|
|
16
16
|
return Object.entries(dependencies ?? {}).map(([tests, deps]) => ({
|
|
17
17
|
tests: picomatch(tests, { dot: true }),
|
|
@@ -138,10 +138,11 @@ async function readSnapshot(file) {
|
|
|
138
138
|
}
|
|
139
139
|
if (typeof parsed !== 'object' || parsed === null)
|
|
140
140
|
return null;
|
|
141
|
-
const { version, head, shard, projects, tree, tests } = parsed;
|
|
141
|
+
const { version, head, root, shard, projects, tree, tests } = parsed;
|
|
142
142
|
const covered = BloomFilter.parse(tests);
|
|
143
143
|
if (version !== SNAPSHOT_VERSION ||
|
|
144
144
|
typeof head !== 'string' ||
|
|
145
|
+
typeof root !== 'string' ||
|
|
145
146
|
!isShard(shard) ||
|
|
146
147
|
!Array.isArray(projects) ||
|
|
147
148
|
!projects.every((name) => typeof name === 'string') ||
|
|
@@ -152,6 +153,7 @@ async function readSnapshot(file) {
|
|
|
152
153
|
return {
|
|
153
154
|
version: SNAPSHOT_VERSION,
|
|
154
155
|
head,
|
|
156
|
+
root,
|
|
155
157
|
shard,
|
|
156
158
|
projects: projects,
|
|
157
159
|
tree,
|
|
@@ -213,6 +215,12 @@ export class TreeSnapshotProvider {
|
|
|
213
215
|
log(`no dependency snapshot, running every test of the ${describeShard(shard)}`);
|
|
214
216
|
return null;
|
|
215
217
|
}
|
|
218
|
+
const repo = await repoRoot(root);
|
|
219
|
+
const here = repoRelative(repo, this.vitest.config.root);
|
|
220
|
+
if (snapshot.root !== here) {
|
|
221
|
+
log(`dependency snapshot is for ${snapshot.root || 'the repository root'}, this run is for ${here || 'the repository root'}, running every test of the ${describeShard(shard)}`);
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
216
224
|
if (!sameShard(snapshot.shard, shard)) {
|
|
217
225
|
log(`dependency snapshot is for ${describeShard(snapshot.shard)}, running every test of the ${describeShard(shard)}`);
|
|
218
226
|
return null;
|
|
@@ -222,7 +230,6 @@ export class TreeSnapshotProvider {
|
|
|
222
230
|
log(`dependency snapshot covers projects [${snapshot.projects.join(', ')}], this run covers [${projects.join(', ')}], running every test of the ${describeShard(shard)}`);
|
|
223
231
|
return null;
|
|
224
232
|
}
|
|
225
|
-
const repo = await repoRoot(root);
|
|
226
233
|
const tree = await anchorTree(repo, await anchoredPaths(this.vitest, repo, dir, this.dependencies));
|
|
227
234
|
const changedPaths = diffTrees(snapshot.tree, tree);
|
|
228
235
|
const owns = await shardOwner(this.vitest);
|
|
@@ -307,6 +314,7 @@ export class ShadowAnalysis {
|
|
|
307
314
|
const repo = await repoRoot(vitest.config.root);
|
|
308
315
|
const key = cacheKey({
|
|
309
316
|
snapshotVersion: SNAPSHOT_VERSION,
|
|
317
|
+
root: repoRelative(repo, vitest.config.root),
|
|
310
318
|
projects: projectNames(vitest),
|
|
311
319
|
shard: vitest.config.shard ?? null,
|
|
312
320
|
head: process.env.GITHUB_SHA || (await headSha(repo)),
|
|
@@ -480,6 +488,7 @@ export class SnapshotRecorder {
|
|
|
480
488
|
const snapshot = {
|
|
481
489
|
version: SNAPSHOT_VERSION,
|
|
482
490
|
head: await headSha(repo),
|
|
491
|
+
root: repoRelative(repo, root),
|
|
483
492
|
shard: shard ?? null,
|
|
484
493
|
projects: projectNames(this.vitest),
|
|
485
494
|
tree: await anchorTree(repo, await anchoredPaths(this.vitest, repo, cacheDir, this.provider.dependencies)),
|
|
@@ -499,6 +508,7 @@ export class SnapshotRecorder {
|
|
|
499
508
|
return;
|
|
500
509
|
const key = cacheKey({
|
|
501
510
|
snapshotVersion: snapshot.version,
|
|
511
|
+
root: snapshot.root,
|
|
502
512
|
projects: snapshot.projects,
|
|
503
513
|
shard: snapshot.shard,
|
|
504
514
|
head: snapshot.head,
|
|
@@ -554,6 +564,7 @@ export async function restoreDependencyCache(vitest) {
|
|
|
554
564
|
const repo = await repoRoot(vitest.config.root);
|
|
555
565
|
const key = cacheKey({
|
|
556
566
|
snapshotVersion: SNAPSHOT_VERSION,
|
|
567
|
+
root: repoRelative(repo, vitest.config.root),
|
|
557
568
|
projects: projectNames(vitest),
|
|
558
569
|
shard: vitest.config.shard ?? null,
|
|
559
570
|
head: process.env.GITHUB_SHA || (await headSha(repo)),
|
package/dist/cache.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface CacheKey {
|
|
|
21
21
|
export declare const DEFAULT_CACHE_PREFIX = "blacksmith-vitest";
|
|
22
22
|
export declare function cacheKey(input: {
|
|
23
23
|
snapshotVersion: number;
|
|
24
|
+
/** Vitest's root relative to the repository: each package of a monorepo keeps its own entries. */
|
|
25
|
+
root: string;
|
|
24
26
|
projects: string[];
|
|
25
27
|
shard: {
|
|
26
28
|
index: number;
|
package/dist/cache.js
CHANGED
|
@@ -21,9 +21,9 @@ export const DEFAULT_CACHE_PREFIX = 'blacksmith-vitest';
|
|
|
21
21
|
export function cacheKey(input) {
|
|
22
22
|
const scope = [
|
|
23
23
|
`v${input.snapshotVersion}`,
|
|
24
|
-
input.projects.some(Boolean)
|
|
24
|
+
input.root !== '' || input.projects.some(Boolean)
|
|
25
25
|
? createHash('sha1')
|
|
26
|
-
.update(input.projects.join('\n'))
|
|
26
|
+
.update([input.root, ...input.projects].join('\n'))
|
|
27
27
|
.digest('hex')
|
|
28
28
|
.slice(0, 12)
|
|
29
29
|
: 'all',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useblacksmith/vitest",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Runs only the Vitest tests affected since the last successful run, with Blacksmith-backed caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"build": "tsc -p tsconfig.build.json",
|
|
22
22
|
"prepack": "npm run build",
|
|
23
23
|
"check:types": "tsc --noEmit",
|
|
24
|
-
"test": "vitest run"
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"release": "scripts/release.sh"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"vitest": ">=5.1.0"
|