Degradation v0.18.0: Terminal no longer reloads on save
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
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 x2updates
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
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Related PR: https://github.com/vitest-dev/vitest/pull/1166
Related comment: https://github.com/vitest-dev/vitest/pull/1166#issuecomment-1103607998
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.
It’s better to discuss first, since the change is intentional.
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 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(),
],
});
The team likes how the terminal behaves at the moment.