diff --git a/context/skip-patterns.yaml b/context/skip-patterns.yaml index 6a28b1f4..873f5c83 100644 --- a/context/skip-patterns.yaml +++ b/context/skip-patterns.yaml @@ -149,6 +149,11 @@ global: regex: # Skip .env files but allow .env.example - ^.env(?!\.example$) + # Skip a root-level test/ or tests/ dir. The `/test/` substring above only + # catches nested ones, because shouldSkip is given a path relative to the + # example root, so the root dir has no leading slash to match on. The + # separator class also covers path.relative output on Windows. + - ^tests?[/\\] # Example-specific overrides # Add patterns here to skip files only for specific examples diff --git a/scripts/lib/tests/skip-patterns.test.js b/scripts/lib/tests/skip-patterns.test.js index 55a02869..5c776782 100644 --- a/scripts/lib/tests/skip-patterns.test.js +++ b/scripts/lib/tests/skip-patterns.test.js @@ -20,6 +20,18 @@ describe('shouldSkip', () => { expect(shouldSkip('.env.example', patterns)).toBe(false); }); + it('skips a root-level test dir, not only nested ones', () => { + const patterns = mergeSkipPatterns({ + includes: ['/test/'], + regex: [new RegExp('^tests?[/\\\\]')], + allow: [], + }); + expect(shouldSkip('app/test/helpers.py', patterns)).toBe(true); + expect(shouldSkip('test/test_api.py', patterns)).toBe(true); + expect(shouldSkip('tests/example.spec.ts', patterns)).toBe(true); + expect(shouldSkip('testing/settings.py', patterns)).toBe(false); + }); + it('keeps files matching no pattern', () => { const patterns = mergeSkipPatterns(globalPatterns); expect(shouldSkip('Sources/App.swift', patterns)).toBe(false);