Skip to content

Commit

Permalink
chore: add pattern to include Svelte page files in Vitest configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
spences10 committed Dec 20, 2024
1 parent 5bc1c3d commit 758a459
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib/reject-patterns.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest'
import {
rejected_extensions,
rejected_paths,
} from './reject-patterns'

describe('reject patterns', () => {
describe('rejected_extensions', () => {
it('should contain common unsafe file extensions', () => {
expect(rejected_extensions).toContain('.php')
expect(rejected_extensions).toContain('.exe')
expect(rejected_extensions).toContain('.env')
})

it('should not allow empty extensions', () => {
expect(rejected_extensions.includes('')).toBe(false)
})

it('should all start with a dot', () => {
rejected_extensions.forEach(ext => {
expect(ext.startsWith('.')).toBe(true)
})
})
})

describe('rejected_paths', () => {
it('should contain common unsafe paths', () => {
expect(rejected_paths).toContain('/wp-admin')
expect(rejected_paths).toContain('/phpmyadmin')
expect(rejected_paths).toContain('/admin')
})

it('should all start with a forward slash', () => {
rejected_paths.forEach(path => {
expect(path.startsWith('/')).toBe(true)
})
})

it('should not contain trailing slashes', () => {
rejected_paths.forEach(path => {
expect(path.endsWith('/')).toBe(false)
})
})
})
})
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default mergeConfig(
'**/*.config.{js,ts,cjs}',
'**/config.{js,ts,cjs}',
'**/*.config.{js,ts,cjs}',
'**/+page.svelte',
'.svelte-kit/**',
'posts/**',
'build/**',
Expand Down

0 comments on commit 758a459

Please sign in to comment.