@flakiness/vitest 1.0.0 → 1.2.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/README.md CHANGED
@@ -20,7 +20,6 @@ A custom Vitest reporter that generates Flakiness Reports from your Vitest test
20
20
  - [`token?: string`](#token-string)
21
21
  - [`outputFolder?: string`](#outputfolder-string)
22
22
  - [`duplicates?: 'fail' | 'rename'`](#duplicates-fail--rename)
23
- - [`open?: 'always' | 'never' | 'on-failure'`](#open-always--never--on-failure)
24
23
  - [`disableUpload?: boolean`](#disableupload-boolean)
25
24
  - [Environment Variables](#environment-variables)
26
25
  - [Example Configuration](#example-configuration)
@@ -220,20 +219,6 @@ reporters: [
220
219
  ```
221
220
 
222
221
 
223
- ### `open?: 'always' | 'never' | 'on-failure'`
224
-
225
- Controls when the report viewer should automatically open in your browser after test completion.
226
-
227
- - **`'on-failure'`** (default): Opens the report only if tests failed and running in an interactive terminal (not in CI)
228
- - **`'always'`**: Always opens the report after test completion (when running in an interactive terminal)
229
- - **`'never'`**: Never automatically opens the report
230
-
231
- ```typescript
232
- reporters: [
233
- ['@flakiness/vitest', { open: 'always' }]
234
- ]
235
- ```
236
-
237
222
  ### `disableUpload?: boolean`
238
223
 
239
224
  When set to `true`, prevents uploading the report to Flakiness.io. The report is still generated locally. Can also be controlled via the `FLAKINESS_DISABLE_UPLOAD` environment variable.
@@ -271,7 +256,6 @@ export default defineConfig({
271
256
  token: process.env.FLAKINESS_ACCESS_TOKEN,
272
257
  outputFolder: './flakiness-report',
273
258
  duplicates: 'fail',
274
- open: 'on-failure',
275
259
  disableUpload: false,
276
260
  }]
277
261
  ],
package/lib/reporter.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FlakinessReport as FK } from "@flakiness/flakiness-report";
2
- import { CIUtils, CPUUtilization, GitWorktree, RAMUtilization, ReportUtils, showReport, uploadReport, writeReport } from "@flakiness/sdk";
2
+ import { CIUtils, CPUUtilization, GitWorktree, RAMUtilization, ReportUtils, uploadReport, writeReport } from "@flakiness/sdk";
3
3
  import chalk from "chalk";
4
4
  import crypto from "crypto";
5
5
  import assert from "node:assert";
@@ -26,7 +26,7 @@ class FKVitestReporter {
26
26
  }
27
27
  onTestRunStart() {
28
28
  assert(this._vitest, "onInit must be called before onTestRunStart");
29
- this._impl = ReporterImpl.create(this._vitest.config.root, this._options, this._logger, this._vitest.config.config);
29
+ this._impl = ReporterImpl.create(this._vitest.config.root, this._vitest.projects, this._options, this._logger, this._vitest.config.config);
30
30
  }
31
31
  async onTestRunEnd(testModules, unhandledErrors, reason) {
32
32
  await this._impl?.onTestRunEnd(testModules, unhandledErrors, reason);
@@ -35,12 +35,15 @@ class FKVitestReporter {
35
35
  }
36
36
  const gTestToTestCaseId = /* @__PURE__ */ new WeakMap();
37
37
  class ReporterImpl {
38
- constructor(_worktree, _commitId, _options, _logger, _configPath) {
38
+ constructor(_worktree, projects, _commitId, _options, _logger, _configPath) {
39
39
  this._worktree = _worktree;
40
40
  this._commitId = _commitId;
41
41
  this._options = _options;
42
42
  this._logger = _logger;
43
43
  this._configPath = _configPath;
44
+ this._environments = projects.map((project) => ReportUtils.createEnvironment({
45
+ name: this._envName(project)
46
+ }));
44
47
  this._sampleSystem = this._sampleSystem.bind(this);
45
48
  this._sampleSystem();
46
49
  }
@@ -49,16 +52,14 @@ class ReporterImpl {
49
52
  _ramUtilization = new RAMUtilization({ precision: 10 });
50
53
  _startTimestamp = Date.now();
51
54
  _stdio = /* @__PURE__ */ new Map();
52
- // In Vitest, all projects MUST HAVE UNIQUE NAMES.
53
- // So we create environments per project name.
54
55
  _environments = [];
55
- static create(rootPath, options, logger, config) {
56
+ static create(rootPath, projects, options, logger, config) {
56
57
  let commitId;
57
58
  let worktree;
58
59
  try {
59
60
  worktree = GitWorktree.create(rootPath);
60
61
  commitId = worktree.headCommitId();
61
- return new ReporterImpl(worktree, commitId, options, logger, config);
62
+ return new ReporterImpl(worktree, projects, commitId, options, logger, config);
62
63
  } catch (e) {
63
64
  logger.warn(`[flakiness.io] Failed to fetch commit info - is this a git repo?`);
64
65
  logger.error(`[flakiness.io] Report is NOT generated.`);
@@ -80,16 +81,8 @@ class ReporterImpl {
80
81
  }
81
82
  entries.push(log);
82
83
  }
83
- _ensureEnvironmentIdx(testCase) {
84
- const projectName = testCase.project.name || "vitest";
85
- let idx = this._environments.findIndex((env) => env.name === projectName);
86
- if (idx === -1) {
87
- idx = this._environments.length;
88
- this._environments.push(ReportUtils.createEnvironment({
89
- name: projectName
90
- }));
91
- }
92
- return idx;
84
+ _envName(project) {
85
+ return project.name || "vitest";
93
86
  }
94
87
  _errorLocation(stacks, testFile) {
95
88
  const frame = stacks?.find((frame2) => this._worktree.gitPath(frame2.file) === testFile) ?? stacks?.find((frame2) => !frame2.file.includes("node_modules"));
@@ -117,7 +110,8 @@ class ReporterImpl {
117
110
  this._collectTest(fkSuite, t);
118
111
  }
119
112
  async _collectTest(fkParent, testCase) {
120
- const environmentIdx = this._ensureEnvironmentIdx(testCase);
113
+ const environmentIdx = this._environments.findIndex((env) => env.name === this._envName(testCase.project));
114
+ assert(environmentIdx !== -1, `Failed to find environment for test ${testCase.fullName}`);
121
115
  const fkTest = {
122
116
  attempts: [],
123
117
  title: testCase.name,
@@ -336,7 +330,10 @@ class ReporterImpl {
336
330
  startTimestamp: this._startTimestamp,
337
331
  duration,
338
332
  suites: fileSuites,
339
- unattributedErrors: unhandledErrors.map((error) => ({
333
+ unattributedErrors: [
334
+ unhandledErrors,
335
+ testModules.map((t) => t.errors()).flat()
336
+ ].flat().map((error) => ({
340
337
  message: error.message,
341
338
  stack: error.stack,
342
339
  location: this._errorLocation(error.stacks)
@@ -358,19 +355,13 @@ class ReporterImpl {
358
355
  logger: this._logger
359
356
  });
360
357
  }
361
- const openMode = this._options.open ?? "on-failure";
362
- const shouldOpen = process.stdin.isTTY && !process.env.CI && (openMode === "always" || openMode === "on-failure" && reason === "failed");
363
- if (shouldOpen) {
364
- await showReport(outputFolder);
365
- } else {
366
- const defaultOutputFolder = path.join(process.cwd(), "flakiness-report");
367
- const folder = defaultOutputFolder === outputFolder ? "" : path.relative(process.cwd(), outputFolder);
368
- this._logger.log(`
358
+ const defaultOutputFolder = path.join(process.cwd(), "flakiness-report");
359
+ const folder = defaultOutputFolder === outputFolder ? "" : path.relative(process.cwd(), outputFolder);
360
+ this._logger.log(`
369
361
  To open last Flakiness report, run:
370
362
 
371
363
  ${chalk.cyan(`npx flakiness show ${folder}`)}
372
- `);
373
- }
364
+ `);
374
365
  }
375
366
  }
376
367
  function dupeSuffix(dupeIndex) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flakiness/vitest",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "main": "lib/reporter.js",
6
6
  "keywords": [],
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "type": "module",
14
14
  "devDependencies": {
15
- "@flakiness/vitest": "0.1.0-alpha.2",
15
+ "@flakiness/vitest": "1.1.0",
16
16
  "@types/node": "^25.3.3",
17
17
  "@vitest/utils": "^4.0.18",
18
18
  "esbuild": "^0.27.3",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@flakiness/flakiness-report": "^0.27.0",
26
- "@flakiness/sdk": "^2.2.0",
26
+ "@flakiness/sdk": "^2.2.1",
27
27
  "chalk": "^5.6.2"
28
28
  },
29
29
  "scripts": {
@@ -9,7 +9,6 @@ interface UserConsoleLog {
9
9
  time: number;
10
10
  size: number;
11
11
  }
12
- export type OpenMode = 'always' | 'never' | 'on-failure';
13
12
  export type FKVitestReporterOptions = {
14
13
  disableUpload?: boolean;
15
14
  flakinessProject?: string;
@@ -17,7 +16,6 @@ export type FKVitestReporterOptions = {
17
16
  token?: string;
18
17
  outputFolder?: string;
19
18
  duplicates?: 'fail' | 'rename';
20
- open?: OpenMode;
21
19
  };
22
20
  export interface FKVitestLogger {
23
21
  log(txt: string): void;
@@ -1 +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