2024-04-19 08:48:19 +00:00
|
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import type { Nuxt, NuxtOptions } from '@nuxt/schema'
|
|
|
|
import { isIgnored, resolveGroupSyntax, resolveIgnorePatterns } from './ignore.js'
|
|
|
|
import * as context from './context.js'
|
|
|
|
|
|
|
|
describe('isIgnored', () => {
|
|
|
|
it('should populate _ignore', () => {
|
|
|
|
const mockNuxt = { options: { ignore: ['my-dir'] } as NuxtOptions } as Nuxt
|
|
|
|
vi.spyOn(context, 'tryUseNuxt').mockReturnValue(mockNuxt)
|
|
|
|
|
|
|
|
expect(isIgnored('my-dir/my-file.ts')).toBe(true)
|
|
|
|
expect(resolveIgnorePatterns()?.includes('my-dir')).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
2023-01-20 16:23:16 +00:00
|
|
|
|
|
|
|
describe('resolveGroupSyntax', () => {
|
|
|
|
it('should resolve single group syntax', () => {
|
|
|
|
expect(resolveGroupSyntax('**/*.{spec}.{js,ts}')).toStrictEqual([
|
|
|
|
'**/*.spec.js',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.spec.ts',
|
2023-01-20 16:23:16 +00:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should resolve multi-group syntax', () => {
|
|
|
|
expect(resolveGroupSyntax('**/*.{spec,test}.{js,ts}')).toStrictEqual([
|
|
|
|
'**/*.spec.js',
|
|
|
|
'**/*.spec.ts',
|
|
|
|
'**/*.test.js',
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.test.ts',
|
2023-01-20 16:23:16 +00:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should do nothing with normal globs', () => {
|
|
|
|
expect(resolveGroupSyntax('**/*.spec.js')).toStrictEqual([
|
2024-04-05 18:08:32 +00:00
|
|
|
'**/*.spec.js',
|
2023-01-20 16:23:16 +00:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|