|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { shouldSkipFile } from '../should-skip-file'; |
| 4 | + |
| 5 | +describe('shouldSkipFile', () => { |
| 6 | + it('should return false when skipPatterns is empty', () => { |
| 7 | + expect(shouldSkipFile('src/file.ts', [])).toBe(false); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should return false when no patterns match', () => { |
| 11 | + const patterns = ['test/*.ts', 'lib/*.js']; |
| 12 | + expect(shouldSkipFile('src/file.ts', patterns)).toBe(false); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should return true when file matches a pattern', () => { |
| 16 | + const patterns = ['src/*.ts', 'lib/*.js']; |
| 17 | + expect(shouldSkipFile('src/file.ts', patterns)).toBe(true); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should handle glob patterns correctly', () => { |
| 21 | + const patterns = ['*.test.ts', 'generated/**']; |
| 22 | + expect(shouldSkipFile('Button.test.ts', patterns)).toBe(true); |
| 23 | + expect(shouldSkipFile('generated/types.ts', patterns)).toBe(true); |
| 24 | + expect(shouldSkipFile('src/Button.ts', patterns)).toBe(false); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should match filename-only patterns against basename', () => { |
| 28 | + const patterns = ['*.js', 'example.ts']; |
| 29 | + expect(shouldSkipFile('/long/path/to/file.js', patterns)).toBe(true); |
| 30 | + expect(shouldSkipFile('/different/path/example.ts', patterns)).toBe( |
| 31 | + true, |
| 32 | + ); |
| 33 | + expect(shouldSkipFile('/path/to/file.ts', patterns)).toBe(false); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should handle special characters in filenames', () => { |
| 37 | + const patterns = ['*.spec.ts', '*test*.js']; |
| 38 | + expect(shouldSkipFile('my-component.spec.ts', patterns)).toBe(true); |
| 39 | + expect(shouldSkipFile('my.test.js', patterns)).toBe(true); |
| 40 | + expect(shouldSkipFile('test.jsx', patterns)).toBe(false); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should handle multiple patterns with mixed path separators', () => { |
| 44 | + const patterns = ['src/*.ts', 'test/*.js', '*.test.tsx']; |
| 45 | + expect(shouldSkipFile('src/file.ts', patterns)).toBe(true); |
| 46 | + expect(shouldSkipFile('test/file.js', patterns)).toBe(true); |
| 47 | + expect(shouldSkipFile('component.test.tsx', patterns)).toBe(true); |
| 48 | + expect(shouldSkipFile('src/sub/file.ts', patterns)).toBe(false); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should handle exact filename matches', () => { |
| 52 | + const patterns = ['example.js', 'tsconfig.json']; |
| 53 | + expect(shouldSkipFile('/any/path/example.js', patterns)).toBe(true); |
| 54 | + expect(shouldSkipFile('/root/tsconfig.json', patterns)).toBe(true); |
| 55 | + expect(shouldSkipFile('/path/to/example.test.js', patterns)).toBe( |
| 56 | + false, |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should handle directory patterns', () => { |
| 61 | + const patterns = ['test/**/*.*', 'generated/**/*.*']; |
| 62 | + expect(shouldSkipFile('test/file.ts', patterns)).toBe(true); |
| 63 | + expect(shouldSkipFile('test/unit/component.js', patterns)).toBe(true); |
| 64 | + expect(shouldSkipFile('generated/types.ts', patterns)).toBe(true); |
| 65 | + expect(shouldSkipFile('src/components/button.ts', patterns)).toBe( |
| 66 | + false, |
| 67 | + ); |
| 68 | + }); |
| 69 | +}); |
0 commit comments