Skip to content

Commit

Permalink
test: add ignores tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davestewart committed Apr 19, 2023
1 parent eaea7c7 commit 1f3fc27
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/content/4.api/3.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default defineNuxtConfig({
ignores: [
'hidden', // any file or folder prefixed with the word "hidden"
'hidden:', // any folder that exactly matches the word "hidden"
':path:to:file', // any file path matching "path/to/file"
'path:to:file', // any file path matching "/path/to/file"
'.+\\.bak$', // any file with the extension ".bak"
]
}
Expand All @@ -154,7 +154,7 @@ export default defineNuxtConfig({
ignores: [
'hidden', // any file or folder that contains the word "hidden"
'/hidden/', // any folder that exactly matches the word "hidden"
'/path/to/file', // any file path matching "path/to/file"
'/path/to/file', // any file path matching "/path/to/file"
'\\.bak$', // any file with the extension ".bak"
]
}
Expand Down
3 changes: 3 additions & 0 deletions test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { testMarkdownRenderer } from './features/renderer-markdown'
import { testParserOptions } from './features/parser-options'
import { testComponents } from './features/components'
import { testLocales } from './features/locales'
import { testIgnores } from './features/ignores'

// const spyConsoleWarn = vi.spyOn(global.console, 'warn')

Expand Down Expand Up @@ -86,4 +87,6 @@ describe('Basic usage', async () => {
testHighlighter()

testParserOptions()

testIgnores()
})
64 changes: 64 additions & 0 deletions test/features/ignores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { describe, test, expect } from 'vitest'
import { makeIgnored } from '../../src/runtime/utils/config'

function run (key: string, pattern: string, result: boolean, experimental: boolean) {
const predicate = makeIgnored([pattern], experimental)
const label: string = experimental ? 'new format' : 'old format'
test(label, () => {
expect(predicate(key)).toBe(result)
})
}

function runOld (pattern: string, key: string, result: boolean) {
return run(key, pattern, result, false)
}

function runNew (pattern: string, key: string, result: boolean) {
return run(key, pattern, result, true)
}

export const testIgnores = () => {
describe('Ignores Options', () => {
describe('any file or folder that contains the word "hidden"', () => {
const key = 'source:content:my-hidden-folder:index.md'
runOld('.+hidden', key, true)
runNew('hidden', key, true)
})

describe('any file or folder prefixed with the word "hidden"', () => {
const key = 'source:content:hidden-folder:index.md'
runOld('hidden', key, true)
runNew('/hidden', key, true)
})

describe('any folder that exactly matches the word "hidden"', () => {
const key = 'source:content:hidden:index.md'
runOld('hidden:', key, true)
runNew('/hidden/', key, true)
})

describe('any file path matching "/path/to/file"', () => {
const key = 'source:content:path:to:file.md'
runOld('path:to:file', key, true)
runNew('/path/to/file', key, true)
})

describe('any file with the extension ".bak"', () => {
const key = 'source:content:path:to:ignored.bak'
runOld('.+\\.bak$', key, true)
runNew('\\.bak$', key, true)
})

describe('any file with a leading dash', () => {
const key = 'source:content:path:to:-dash.txt'
runOld('', key, true)
runNew('', key, true)
})

describe('any file with a leading dot', () => {
const key = 'source:content:path:to:.dot.txt'
runOld('', key, true)
runNew('', key, true)
})
})
}

0 comments on commit 1f3fc27

Please sign in to comment.