Socket
Socket
Sign inDemoInstall

vitest

Package Overview
Dependencies
15
Maintainers
1
Versions
357
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.21 to 0.0.22

dist/node/index.d.ts

6

dist/cli.js

@@ -1,2 +0,1 @@

var _a;
import minimist from 'minimist';

@@ -22,4 +21,5 @@ import c from 'picocolors';

});
// @ts-expect-error
const server = (_a = process === null || process === void 0 ? void 0 : process.__vite_node__) === null || _a === void 0 ? void 0 : _a.server;
if (!process.__vite_node__)
throw new Error('Vite can only run in Vite environment, please use the CLI to start the process');
const server = process.__vite_node__.server;
const viteConfig = (server === null || server === void 0 ? void 0 : server.config) || {};

@@ -26,0 +26,0 @@ const testOptions = viteConfig.test || {};

@@ -5,3 +5,3 @@ import { fileURLToPath } from 'url';

import { findUp } from 'find-up';
import { run } from './node.js';
import { run } from './node/index.js';
process.env.VITEST = 'true';

@@ -8,0 +8,0 @@ const argv = minimist(process.argv.slice(2), {

import Listr from 'listr';
import { Reporter, RunnerContext, Task } from '../types';
import { File, Reporter, RunnerContext, Task } from '../types';
interface TaskPromise {

@@ -9,3 +9,2 @@ promise: Promise<void>;

export declare class DefaultReporter implements Reporter {
indent: number;
start: number;

@@ -16,11 +15,9 @@ end: number;

taskMap: Map<Task, TaskPromise>;
onStart(): void;
onCollected(ctx: RunnerContext): void;
onCollected(files: File[]): void;
onTaskEnd(task: Task): void;
onFinished({ files }: RunnerContext): Promise<void>;
private getIndent;
private log;
private error;
onFinished(ctx: RunnerContext): Promise<void>;
onWatcherStart(ctx: RunnerContext): Promise<void>;
onWatcherRerun(files: string[], trigger: string): Promise<void>;
onSnapshotUpdate(): void;
}
export {};

@@ -0,1 +1,2 @@

/* eslint-disable no-console */
import { performance } from 'perf_hooks';

@@ -8,3 +9,2 @@ import { relative } from 'path';

constructor() {
this.indent = 0;
this.start = 0;

@@ -16,9 +16,6 @@ this.end = 0;

}
onStart() {
this.indent = 0;
}
onCollected(ctx) {
onCollected(files) {
this.start = performance.now();
this.taskMap = new Map();
const tasks = ctx.files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
const tasks = files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
tasks.forEach((t) => {

@@ -47,3 +44,3 @@ const obj = {};

};
this.listr = new Listr(ctx.files.map((file) => {
this.listr = new Listr(files.map((file) => {
return {

@@ -73,8 +70,7 @@ title: relative(process.cwd(), file.filepath),

}
async onFinished({ files }) {
async onFinished(ctx) {
await this.listrPromise;
this.log();
this.end = performance.now();
const suites = files.reduce((acc, file) => acc.concat(file.suites), []);
const tasks = files.reduce((acc, file) => acc.concat(file.suites.flatMap(i => i.tasks)), []);
console.log();
const { tasks, suites, files } = ctx;
const failedFiles = files.filter(i => i.error);

@@ -87,51 +83,52 @@ const failedSuites = suites.filter(i => i.error);

const todo = tasks.filter(i => i.state === 'todo');
this.indent = 0;
if (failedFiles.length) {
this.error(c.bold(`\nFailed to parse ${failedFiles.length} files:`));
console.error(c.bold(`\nFailed to parse ${failedFiles.length} files:`));
failedFiles.forEach((i) => {
this.error(`\n- ${i.filepath}`);
console.error(c.red(`\n- ${i.filepath}`));
console.error(i.error || 'Unknown error');
this.log();
console.log();
});
}
if (failedSuites.length) {
this.error(c.bold(`\nFailed to run ${failedSuites.length} suites:`));
console.error(c.bold(`\nFailed to run ${failedSuites.length} suites:`));
failedSuites.forEach((i) => {
var _a;
this.error(`\n- ${(_a = i.file) === null || _a === void 0 ? void 0 : _a.filepath} > ${i.name}`);
console.error(c.red(`\n- ${(_a = i.file) === null || _a === void 0 ? void 0 : _a.filepath} > ${i.name}`));
console.error(i.error || 'Unknown error');
this.log();
console.log();
});
}
if (failed.length) {
this.error(c.bold(`\nFailed Tests (${failed.length})`));
console.error(c.bold(`\nFailed Tests (${failed.length})`));
failed.forEach((task) => {
var _a;
this.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(c.dim(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`))}`);
console.error(`\n${CROSS + c.inverse(c.red(' FAIL '))} ${[task.suite.name, task.name].filter(Boolean).join(' > ')} ${c.gray(c.dim(`${(_a = task.file) === null || _a === void 0 ? void 0 : _a.filepath}`))}`);
console.error(task.error || 'Unknown error');
this.log();
console.log();
});
}
this.log(c.bold(c.green(`Passed ${passed.length} / ${runable.length}`)));
console.log(c.bold(c.green(`Passed ${passed.length} / ${runable.length}`)));
if (failed.length)
this.log(c.bold(c.red(`Failed ${failed.length} / ${runable.length}`)));
console.log(c.bold(c.red(`Failed ${failed.length} / ${runable.length}`)));
if (skipped.length)
this.log(c.yellow(`Skipped ${skipped.length}`));
console.log(c.yellow(`Skipped ${skipped.length}`));
if (todo.length)
this.log(c.dim(`Todo ${todo.length}`));
this.log(`Time ${(this.end - this.start).toFixed(2)}ms`);
console.log(c.dim(`Todo ${todo.length}`));
console.log(`Time ${(this.end - this.start).toFixed(2)}ms`);
}
getIndent(offest = 0) {
return ' '.repeat((this.indent + offest) * 2);
async onWatcherStart(ctx) {
await this.listrPromise;
const failed = ctx.tasks.some(i => i.state === 'fail');
if (failed)
console.log(c.red('\nTests failed. Watching for file changes...'));
else
console.log(c.green('\nWatching for file changes...'));
}
log(msg = '', indentOffset = 0) {
// eslint-disable-next-line no-console
console.log(`${this.getIndent(indentOffset)}${msg}`);
async onWatcherRerun(files, trigger) {
await this.listrPromise;
console.log(c.blue(`File ${relative(process.cwd(), trigger)} changed, re-running tests...`));
}
error(msg = '', indentOffset = 0) {
// eslint-disable-next-line no-console
console.error(c.red(`${this.getIndent(indentOffset)}${msg}`));
}
// TODO:
onSnapshotUpdate() {
}
}

@@ -81,3 +81,6 @@ import { ViteDevServer } from 'vite';

export interface RunnerContext {
filesMap: Record<string, File>;
files: File[];
suites: Suite[];
tasks: Task[];
config: Config;

@@ -92,3 +95,3 @@ reporter: Reporter;

onStart?: (userOptions: Config) => Awaitable<void>;
onCollected?: (ctx: RunnerContext) => Awaitable<void>;
onCollected?: (files: File[], ctx: RunnerContext) => Awaitable<void>;
onFinished?: (ctx: RunnerContext) => Awaitable<void>;

@@ -101,3 +104,5 @@ onSuiteBegin?: (suite: Suite, ctx: RunnerContext) => Awaitable<void>;

onTaskEnd?: (task: Task, ctx: RunnerContext) => Awaitable<void>;
onWatcherStart?: (ctx: RunnerContext) => Awaitable<void>;
onWatcherRerun?: (files: string[], trigger: string, ctx: RunnerContext) => Awaitable<void>;
onSnapshotUpdate?: () => Awaitable<void>;
}
{
"name": "vitest",
"version": "0.0.21",
"version": "0.0.22",
"description": "",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -161,3 +161,3 @@ # vitest

- [x] JSDom
- [ ] Watch
- [x] Watch
- [ ] Source Map

@@ -164,0 +164,0 @@ - [ ] Coverage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc