vitest icon indicating copy to clipboard operation
vitest copied to clipboard

Degradation v0.18.0: Terminal no longer reloads on save

Open gkiely opened this issue 3 years ago • 4 comments

Describe the bug

0.17.1: reloads the terminal on save, this is helpful for developer feedback. 0.18.0: doesn't reload the terminal, shows a blue indicator

The original 0.17.1 version had this right, it's a much better dev experience seeing the full reload. The new version is much harder to discern if the test updated.

In the case that the maintainers decide v0.18.0 is the ideal experience, a fallback proposal would be to allow an option to reload on save.

Reproduction

Repo

v0.17.1

npm i
npm test
  • Make any update to App.test.tsx
  • See terminal reload

v0.18.0

npm i vitest@latest
npm test
  • Make any update to App.test.tsx
  • Terminal does not reload, only rerun x2 updates

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 438.05 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 18.4.0 - ~/.volta/tools/image/node/18.4.0/bin/node
    Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
    npm: 8.12.1 - ~/.volta/tools/image/node/18.4.0/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 103.0.5060.114
    Firefox: 101.0.1
    Safari: 15.3
  npmPackages:
    @vitejs/plugin-react: ^1.3.0 => 1.3.2 
    vite: ^2.9.9 => 2.9.14

Used Package Manager

npm

Validations

gkiely avatar Jul 09 '22 16:07 gkiely

Related PR: https://github.com/vitest-dev/vitest/pull/1166

Related comment: https://github.com/vitest-dev/vitest/pull/1166#issuecomment-1103607998

gkiely avatar Jul 09 '22 16:07 gkiely

I can open a PR for a config/cli flag if there's interest. It would basically behave like jest in that in clears on start and between each run.

gkiely avatar Jul 12 '22 17:07 gkiely

It’s better to discuss first, since the change is intentional.

sheremet-va avatar Jul 13 '22 04:07 sheremet-va

Whats the best workaround? I'm using vite-node directly. Best workaround I can think of is involves nodemon, but there's gotta be a better way.

FossPrime avatar Sep 06 '22 20:09 FossPrime

@FossPrime This is the plugin I use

vite-plugin-clear-vitest.ts

import pc from 'picocolors';
import type { Plugin } from 'vite';

let hasResolved = false;
const clear = () => {
  process.stdout.write('\x1B[2J\x1B[3J\x1B[H\x1Bc\n');
};

// Clear terminal on initial and subsequent loads for vitest
const plugin = (): Plugin => ({
  name: 'clear-vitest',
  config: () => clear(),
  resolveId: () => ((hasResolved = true), null),
  load: (path) => {
    if (hasResolved && /\.test\.(?:t|j)sx?/.test(path)) {
      clear();
      const pwd = process.env.PWD ? `${process.env.PWD}/` : '';
      console.log(pc.black(pc.bgBlue(' RERUN ')), pc.gray(path.replace(pwd, '')), '\n');
    }
  },
});

export default plugin;

vitest.config.ts

import { defineConfig } from 'vitest/config';
import clearVitest from './vite-plugin-clear-vitest';

export default defineConfig({
  plugins: [
    clearVitest(),
  ],
});

gkiely avatar Jan 04 '23 22:01 gkiely

The team likes how the terminal behaves at the moment.

sheremet-va avatar Feb 16 '24 14:02 sheremet-va