Skip to content

Commit

Permalink
Merge pull request #22 from raegen/develop
Browse files Browse the repository at this point in the history
drop unreliable test file globbing in favour of vitest own implementation
  • Loading branch information
raegen authored Dec 18, 2024
2 parents 022145f + 0bc1784 commit 8287492
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@raegen/vite-plugin-vitest-cache",
"version": "0.3.2",
"version": "0.3.3",
"description": "Run Vitest with test result caching.",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions src/files.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createVitest, GlobalSetupContext } from 'vitest/node';

const convertToUserConfig = ({ shard, ...config }: GlobalSetupContext['config']) => ({
...config,
shard: shard ? `${shard.index}/${shard.count}` : undefined,
});

export const getFiles = async (config: GlobalSetupContext['config']): Promise<string[]> => createVitest('test', convertToUserConfig(config)).then((vitest) => vitest.getTestFilepaths().finally(() => vitest.close()));
9 changes: 5 additions & 4 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { GlobalSetupContext } from 'vitest/node';
import { dirname, resolve } from 'node:path';
import { dirname } from 'node:path';
import fs from 'node:fs/promises';
import fg from 'fast-glob';
import { format, formatDim, version } from './util.js';
import { applyStrategy } from './strategy.js';
import { CacheEntry } from './cache.js';
import { CacheOptions } from './options.js';
import { load } from './load.js';
import { getFiles } from './files.js';

declare module 'vitest/node' {
export interface ResolvedConfig {
Expand All @@ -22,7 +23,7 @@ const createMeasurement = (action: string, silent?: boolean) => {
return {
log: (extra: string = '', flag = format('[vCache]')) => {
if (!silent) {
console.log(flag, formatDim(`${action}${extra} ${duration}s`))
console.log(flag, formatDim(`${action}${extra} ${duration}s`));
}
},
};
Expand All @@ -34,8 +35,8 @@ export default async ({ config, provide }: GlobalSetupContext) => {
if (!config.vCache.silent) {
console.log(format('[vCache]'), formatDim(await version));
}
const include = config.include.map((pattern) => resolve(config.root, pattern));
const files = await fg(include, { ignore: ['**/node_modules/**', resolve(config.root, config.vCache.dir, '**')] });

const files = await getFiles(config);

const building = createMeasurement('built hashes in', config.vCache.silent);
const output = await load(files, config.vCache.dir);
Expand Down

0 comments on commit 8287492

Please sign in to comment.