nx/packages/vite/src/migrations/update-20-0-4/add-vite-temp-files-to-git-ignore.spec.ts
Colum Ferry ba1641d7fd
fix(bundling): ensure vitest timestamp files are ignored (#29418)
## Current Behavior
Vitest TS config files produce timestamp temp files during project graph
creation which are cleaned up.
However, the creation and deletion of these files triggers the daemon to
recalculate graph.
It ends up in a loop.
The vite timestamp files were already added to the gitignore to prevent
this.

## Expected Behavior
Add vitest timestamp files to gitignore
2024-12-19 16:04:04 +00:00

57 lines
1.5 KiB
TypeScript

import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import addViteTempFilesToGitIgnore from './add-vite-temp-files-to-git-ignore';
describe('addViteTempFilesToGitIgnore', () => {
it('should update an existing .gitignore file to add the glob correctly', () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
tree.write('.gitignore', '.idea');
// ACT
addViteTempFilesToGitIgnore(tree);
// ASSERT
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(`
".idea
vite.config.*.timestamp*
vitest.config.*.timestamp*"
`);
});
it('should update an existing .gitignore file and remove incorrect glob and add the glob correctly', () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
tree.write(
'.gitignore',
`.idea
**/vite.config.{js,ts,mjs,mts,cjs,cts}.timestamp*`
);
// ACT
addViteTempFilesToGitIgnore(tree);
// ASSERT
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(`
".idea
vite.config.*.timestamp*
vitest.config.*.timestamp*"
`);
});
it('should write a new .gitignore file to add the glob correctly', () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();
tree.delete('.gitignore');
// ACT
addViteTempFilesToGitIgnore(tree);
// ASSERT
expect(tree.read('.gitignore', 'utf-8')).toMatchInlineSnapshot(`
"vite.config.*.timestamp*
vitest.config.*.timestamp*"
`);
});
});