|
| 1 | +/** |
| 2 | + * Tests for scan utilities |
| 3 | + */ |
| 4 | +const fs = require('fs'); |
| 5 | +const path = require('path'); |
| 6 | +const { |
| 7 | + loadIgnorePatterns, |
| 8 | + shouldIgnorePath, |
| 9 | +} = require('../scan'); |
| 10 | + |
| 11 | +describe('loadIgnorePatterns', () => { |
| 12 | + const tempDir = path.join(__dirname, 'temp-ignore-test'); |
| 13 | + const ignorePath = path.join(tempDir, '.mustacheignore'); |
| 14 | + |
| 15 | + beforeEach(() => { |
| 16 | + if (!fs.existsSync(tempDir)) { |
| 17 | + fs.mkdirSync(tempDir, { recursive: true }); |
| 18 | + } |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(() => { |
| 22 | + if (fs.existsSync(ignorePath)) { |
| 23 | + fs.unlinkSync(ignorePath); |
| 24 | + } |
| 25 | + if (fs.existsSync(tempDir)) { |
| 26 | + fs.rmdirSync(tempDir); |
| 27 | + } |
| 28 | + }); |
| 29 | + |
| 30 | + test('returns empty array when .mustacheignore does not exist', () => { |
| 31 | + const patterns = loadIgnorePatterns(tempDir); |
| 32 | + expect(patterns).toEqual([]); |
| 33 | + }); |
| 34 | + |
| 35 | + test('loads patterns from .mustacheignore file', () => { |
| 36 | + fs.writeFileSync(ignorePath, 'node_modules/\nbuild/\n# comment\n\ndocs/'); |
| 37 | + const patterns = loadIgnorePatterns(tempDir); |
| 38 | + expect(patterns).toEqual(['node_modules/', 'build/', 'docs/']); |
| 39 | + }); |
| 40 | + |
| 41 | + test('shouldIgnorePath matches simple patterns', () => { |
| 42 | + const patterns = ['node_modules/', 'build/']; |
| 43 | + expect(shouldIgnorePath('node_modules/package', patterns)).toBe(true); |
| 44 | + expect(shouldIgnorePath('src/index.js', patterns)).toBe(false); |
| 45 | + }); |
| 46 | + |
| 47 | + test('shouldIgnorePath matches glob patterns', () => { |
| 48 | + const patterns = ['**/*.test.js', 'src/experimental/**']; |
| 49 | + expect(shouldIgnorePath('src/utils/scan.test.js', patterns)).toBe(true); |
| 50 | + expect(shouldIgnorePath('src/experimental/feature.js', patterns)).toBe(true); |
| 51 | + expect(shouldIgnorePath('src/utils/scan.js', patterns)).toBe(false); |
| 52 | + }); |
| 53 | +}); |
0 commit comments