Skip to content

Commit

Permalink
fix(#17): Cannot find module 'vitest-fail-on-console'
Browse files Browse the repository at this point in the history
* fix TypeScript type declaration (TS7016-TS2307)
* export types
* remove vitest import in index.ts
  • Loading branch information
thomasbrodusch committed Feb 29, 2024
1 parent 6095818 commit 9a60253
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { beforeEach, afterEach, expect } from "vitest";

This comment has been minimized.

Copy link
@nilzona

nilzona Mar 4, 2024

Contributor

This change cause my tests to fail after updating vitest-fail-on-console

ReferenceError: beforeEach is not defined
 ❯ y node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest-fail-on-console/src/index.ts:128:50
 ❯ node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest-fail-on-console/src/index.ts:158:1
 ❯ Module.k node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vitest-fail-on-console/src/index.ts:157:6
 ❯ test/unit-test-setup.ts:5:1
      1| import { vi } from "vitest";
      2| import failOnConsole from "vitest-fail-on-console";
      3| import createFetchMock from "vitest-fetch-mock";
      4| 
      5| failOnConsole();
       | ^
      6| 
      7| createFetchMock(vi).enableMocks();

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

This comment has been minimized.

Copy link
@nilzona

nilzona Mar 4, 2024

Contributor

Also I think that the source maps should not be used in the production build so that I can go to the real code that's executing based on the stack trace.

This comment has been minimized.

Copy link
@thomasbrodusch

thomasbrodusch Mar 4, 2024

Author Owner

Hi @nilzona is the value of test.globals in your vitest.config.ts or vite.config.ts set to true ?

This comment has been minimized.

Copy link
@nilzona

nilzona Mar 4, 2024

Contributor

no, I usually like to import the things I use from vitest instead of relying on globals. like so

import { beforeEach, describe, test, vi } from `vitest`

There's no doc for this library that tells me I have to add the vitest globals and I wouldn't like to be forced to do so.

This comment has been minimized.

Copy link
@thomasbrodusch

thomasbrodusch Mar 5, 2024

Author Owner

Can you set globals: true and tell me if you still have the error, just to check if in this case everything works as expected 😃

This comment has been minimized.

Copy link
@nilzona

nilzona Mar 5, 2024

Contributor

Yes, if I add globals:true it works. But why was this line removed in the first place? Keeping the line above will work both when globals: is set to true and false.

import * as util from 'util';
import chalk from 'chalk';
import {
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"baseUrl": ".",
"baseUrl": "src",
"lib": ["es2021", "dom"],
"module": "esnext",
"target": "es6",
"sourceMap": true,
"types": ["vitest/globals"],
"types": ["vitest/globals", "src/types"],
"paths": {
"*": ["src/*"],
},
Expand Down
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default defineConfig({
},
},
},
plugins: [dts()],
plugins: [dts({insertTypesEntry: true,})],
test: {
environment: 'node',
globals: true,
Expand Down

0 comments on commit 9a60253

Please sign in to comment.