vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.55k stars 1.12k forks source link

No console logs/debugs/errors in tests or component #5887

Closed MarcoPasta closed 2 months ago

MarcoPasta commented 2 months ago

Describe the bug

When i use console.log/debug/error in either the component or the tests itself i get no logs printed to the console, the terminal or in the ui. The project runs on Angular 17, i migrated to vitest using this guide: https://analogjs.org/docs/features/testing/vitest

My config:

/// <reference types="vitest" />

import angular from '@analogjs/vite-plugin-angular';

import { defineConfig } from 'vite';

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  return {
    plugins: [
      angular(),
    ],
    test: {
      globals: true,
      environment: 'happy-dom',
      setupFiles: ['./src/test-setup.ts'],
      include: ['**/*.spec.ts'],
      reporters: ['default'],
    },
    define: {
      'import.meta.vitest': mode !== 'production',
    },
  };
});

I tried several methods using --silent=false, --disableConsoleIntercept, ----inspect-brk etc but non of them seemed to work. I installed jest alongside and console.logs are working here..

image image

Reproduction

System Info

System:
    OS: macOS 14.5
    CPU: (12) arm64 Apple M3 Pro
    Memory: 350.92 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
  IDEs:
    IntelliJ: 2024.1.2
  Browsers:
    Chrome: 126.0.6478.57
  npmPackages:
    @analogjs/platform: ^1.4.0 => 1.4.0 
    @analogjs/vite-plugin-angular: ^1.2.0 => 1.4.0 
    @nx/vite: ~18.0.0 => 18.0.8 
    @vitest/ui: ^1.6.0 => 1.6.0 
    happy-dom: ^14.12.0 => 14.12.0 
    jsdom: ^22.0.0 => 22.1.0 
    vite-tsconfig-paths: ^4.2.0 => 4.3.2 
    vitest: ^1.3.1 => 1.6.0

Used Package Manager

npm

Validations

dulimarta commented 2 months ago

I am facing a similar issue (but for a Vue3 project, not an Angular). To show console output from the test, I had to use

vitest --disableConsoleIntercept=false

the following option (without false did not work)

vitest --disableConsoleIntercept

However, disabling this option only shows console output in my test, but not console output from my Vue components

github-actions[bot] commented 2 months ago

Hello @MarcoPasta. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

sheremet-va commented 2 months ago

I don't think this is related to Vitest. I need an actual reproduction (a repository) that I can run without additional packages on top of it (like nx).

MarcoPasta commented 2 months ago

I tried to create a minimal reproduction project with only installing the @analogjs/platform package and running ng g @analogjs/platform:setup-vitest --project [your-project-name] and it threw me the error that the @nx/devkit package is missing. After installing the missing package i was able to run the tests with this result:

image

I tried setting it up in another minimal way but unfortunately i can't get it to run - can anyone help me out here?