vitest-tiny-reporter 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kevin Brey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # vitest-tiny-reporter
2
+
3
+ [![npm](https://img.shields.io/npm/v/vitest-tiny-reporter?style=flat-square)](https://www.npmjs.com/package/vitest-tiny-reporter?activeTab=versions)
4
+ [![npm bundle size](https://img.shields.io/bundlephobia/minzip/vitest-tiny-reporter?style=flat-square)](https://bundlephobia.com/package/vitest-tiny-reporter)
5
+ [![NPM](https://img.shields.io/npm/l/vitest-tiny-reporter?style=flat-square)](https://raw.githubusercontent.com/manbearwiz/vitest-tiny-reporter/master/LICENSE)
6
+ [![npm](https://img.shields.io/npm/dt/vitest-tiny-reporter?style=flat-square)](https://www.npmjs.com/package/vitest-tiny-reporter)
7
+ [![GitHub issues](https://img.shields.io/github/issues/manbearwiz/vitest-tiny-reporter?style=flat-square)](https://github.com/manbearwiz/vitest-tiny-reporter/issues)
8
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release&style=flat-square)](https://github.com/semantic-release/semantic-release)
9
+
10
+ `vitest-tiny-reporter` is a minimal reporter for [Vitest](https://github.com/vitest-dev/vitest) that provides the most essential information about the test run. This is very useful with tools like lefthook that run several checks in parallel, where you want to see the test results without scrolling through a lot of output.
11
+
12
+ ## Installation
13
+
14
+ ```sh
15
+ npm install --save vitest-tiny-reporter
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ You can specify the reporter in your `vitest.config.ts`:
21
+
22
+ ```ts
23
+ import type { UserConfig } from 'vitest/config';
24
+ import TinyReporter from 'vite-tiny-reporter';
25
+
26
+ export default {
27
+ test: {
28
+ reporters: [new TinyReporter()],
29
+ },
30
+ } satisfies UserConfig;
31
+ ```
32
+
33
+ Or you can use the reporter from the command line:
34
+
35
+ ```sh
36
+ vitest --reporter vitest-tiny-reporter
37
+ ```
38
+
39
+ ## Output
40
+
41
+ The output will look like this:
42
+
43
+ ```sh
44
+ $ vitest
45
+ ✖ FAIL 1 test failed
46
+ Test Files 1 failed (1)
47
+ Tests 1 failed | 10 passed (11)
48
+ ```
@@ -0,0 +1,10 @@
1
+ import type { Task, Vitest } from 'vitest';
2
+ import type { Reporter } from 'vitest/reporters';
3
+ export declare class TinyReporter implements Reporter {
4
+ ctx: Vitest;
5
+ protected verbose: boolean;
6
+ onInit(ctx: Vitest): void;
7
+ onFinished(files?: import("vitest").File[], errors?: unknown[]): void;
8
+ padTitle: (str: string) => string;
9
+ getStateString(tasks: Task[], name?: string): string;
10
+ }
package/dist/index.js ADDED
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TinyReporter = void 0;
7
+ const utils_1 = require("@vitest/runner/utils");
8
+ const tinyrainbow_1 = __importDefault(require("tinyrainbow"));
9
+ class TinyReporter {
10
+ constructor() {
11
+ // biome-ignore lint/style/noNonNullAssertion: Non-null assertion is allowed here because the onInit method is called before any other method
12
+ this.ctx = undefined;
13
+ this.verbose = false;
14
+ this.padTitle = (str) => tinyrainbow_1.default.dim(`${str.padStart(11)} `);
15
+ }
16
+ onInit(ctx) {
17
+ this.ctx = ctx;
18
+ }
19
+ onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
20
+ const { logger } = this.ctx;
21
+ const tests = (0, utils_1.getTests)(files);
22
+ const failedTests = tests.filter((i) => { var _a; return ((_a = i.result) === null || _a === void 0 ? void 0 : _a.state) === 'fail'; }).length;
23
+ const passed = !(failedTests + errors.length);
24
+ const status = passed ? '\u2714 PASS' : '\u2716 FAIL';
25
+ const statusColor = passed ? tinyrainbow_1.default.green : tinyrainbow_1.default.red;
26
+ logger.log(`${statusColor(tinyrainbow_1.default.bold(tinyrainbow_1.default.inverse(` ${status} `)))} ${statusColor(passed
27
+ ? 'All tests passed'
28
+ : `${failedTests} test${failedTests > 1 ? 's' : ''} failed`)}`);
29
+ logger.log(this.padTitle('Test Files'), this.getStateString(files));
30
+ logger.log(this.padTitle('Tests'), this.getStateString(tests));
31
+ if (errors.length) {
32
+ logger.log(this.padTitle('Errors'), tinyrainbow_1.default.bold(tinyrainbow_1.default.red(`${errors.length} error${errors.length > 1 ? 's' : ''}`)));
33
+ }
34
+ if (!passed) {
35
+ process.exitCode = 1;
36
+ }
37
+ }
38
+ getStateString(tasks, name = 'tests') {
39
+ if (!tasks.length) {
40
+ return tinyrainbow_1.default.dim(`no ${name}`);
41
+ }
42
+ const passed = tasks.filter((i) => { var _a; return ((_a = i.result) === null || _a === void 0 ? void 0 : _a.state) === 'pass'; }).length;
43
+ const failed = tasks.filter((i) => { var _a; return ((_a = i.result) === null || _a === void 0 ? void 0 : _a.state) === 'fail'; }).length;
44
+ const skipped = tasks.filter((i) => i.mode === 'skip').length;
45
+ const todo = tasks.filter((i) => i.mode === 'todo').length;
46
+ return ([
47
+ failed && tinyrainbow_1.default.bold(tinyrainbow_1.default.red(`${failed} failed`)),
48
+ passed && tinyrainbow_1.default.bold(tinyrainbow_1.default.green(`${passed} passed`)),
49
+ skipped && tinyrainbow_1.default.yellow(`${skipped} skipped`),
50
+ todo && tinyrainbow_1.default.gray(`${todo} todo`),
51
+ ]
52
+ .filter(Boolean)
53
+ .join(tinyrainbow_1.default.dim(' | ')) + tinyrainbow_1.default.gray(` (${tasks.length})`));
54
+ }
55
+ }
56
+ exports.TinyReporter = TinyReporter;
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "vitest-tiny-reporter",
3
+ "version": "1.0.0",
4
+ "description": "Tiny reporter for vitest",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "/dist"
9
+ ],
10
+ "keywords": [
11
+ "vitest",
12
+ "reporter",
13
+ "lefthook"
14
+ ],
15
+ "scripts": {
16
+ "build": "tsc",
17
+ "test": "vitest run",
18
+ "coverage": "vitest run --coverage",
19
+ "test:watch": "vitest --watch --coverage --ui",
20
+ "prepublish": "npm run build",
21
+ "semantic-release": "semantic-release",
22
+ "lint": "npx @biomejs/biome check",
23
+ "lint:fix": "npx @biomejs/biome check --write"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/manbearwiz/vitest-tiny-reporter.git"
28
+ },
29
+ "author": "Kevin Brey",
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/manbearwiz/vitest-tiny-reporter/issues"
33
+ },
34
+ "homepage": "https://github.com/manbearwiz/vitest-tiny-reporter#readme",
35
+ "devDependencies": {
36
+ "@biomejs/biome": "1.8.3",
37
+ "@commitlint/cli": "^19.3.0",
38
+ "@commitlint/config-angular": "^19.3.0",
39
+ "@tsconfig/recommended": "^1.0.3",
40
+ "@tsconfig/strictest": "^2.0.2",
41
+ "@types/node": "^20.12.12",
42
+ "@vitest/coverage-v8": "^2.0.3",
43
+ "@vitest/ui": "^2.0.3",
44
+ "happy-dom": "^14.12.3",
45
+ "semantic-release": "^22.0.0",
46
+ "typescript": "^5.2.2"
47
+ },
48
+ "dependencies": {
49
+ "@vitest/runner": "^2.0.3",
50
+ "tinyrainbow": "^1.2.0",
51
+ "vitest": "^2.0.3"
52
+ },
53
+ "release": {
54
+ "branches": [
55
+ "main"
56
+ ]
57
+ }
58
+ }