|
| 1 | +import { describe, expect, it } from 'bun:test' |
| 2 | + |
| 3 | +import { |
| 4 | + createNodeModulesExcludeRegex, |
| 5 | + type DevupUIBasePluginOptions, |
| 6 | + getFileNumByFilename, |
| 7 | +} from '../shared' |
| 8 | + |
| 9 | +describe('getFileNumByFilename', () => { |
| 10 | + it('should return null for devup-ui.css', () => { |
| 11 | + expect(getFileNumByFilename('devup-ui.css')).toBeNull() |
| 12 | + }) |
| 13 | + |
| 14 | + it('should return file number for devup-ui-5.css', () => { |
| 15 | + expect(getFileNumByFilename('devup-ui-5.css')).toBe(5) |
| 16 | + }) |
| 17 | + |
| 18 | + it('should return file number for devup-ui-123.css', () => { |
| 19 | + expect(getFileNumByFilename('devup-ui-123.css')).toBe(123) |
| 20 | + }) |
| 21 | + |
| 22 | + it('should handle query params: devup-ui.css?fileNum=79', () => { |
| 23 | + expect(getFileNumByFilename('devup-ui.css?fileNum=79')).toBe(79) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should handle path with query: /path/to/devup-ui.css?fileNum=42', () => { |
| 27 | + expect(getFileNumByFilename('/path/to/devup-ui.css?fileNum=42')).toBe(42) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should return null for path/to/devup-ui.css (no number, no query)', () => { |
| 31 | + expect(getFileNumByFilename('path/to/devup-ui.css')).toBeNull() |
| 32 | + }) |
| 33 | +}) |
| 34 | + |
| 35 | +describe('createNodeModulesExcludeRegex', () => { |
| 36 | + it('should match node_modules paths that should be excluded', () => { |
| 37 | + const regex = createNodeModulesExcludeRegex([]) |
| 38 | + expect(regex.test('node_modules/some-package/index.js')).toBe(true) |
| 39 | + expect(regex.test('/path/to/node_modules/lodash/index.js')).toBe(true) |
| 40 | + }) |
| 41 | + |
| 42 | + it('should NOT match @devup-ui paths', () => { |
| 43 | + const regex = createNodeModulesExcludeRegex([]) |
| 44 | + expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false) |
| 45 | + expect(regex.test('node_modules/@devup-ui/components/index.js')).toBe(false) |
| 46 | + }) |
| 47 | + |
| 48 | + it('should NOT match included packages', () => { |
| 49 | + const regex = createNodeModulesExcludeRegex(['my-company/design-system']) |
| 50 | + expect(regex.test('node_modules/my-company/design-system/index.js')).toBe( |
| 51 | + false, |
| 52 | + ) |
| 53 | + }) |
| 54 | + |
| 55 | + it('should handle extra excludes parameter', () => { |
| 56 | + const regex = createNodeModulesExcludeRegex([], '.mdx.[tj]sx?$') |
| 57 | + // Should match node_modules |
| 58 | + expect(regex.test('node_modules/some-package/index.js')).toBe(true) |
| 59 | + // Should also match .mdx.tsx files |
| 60 | + expect(regex.test('src/page.mdx.tsx')).toBe(true) |
| 61 | + expect(regex.test('src/page.mdx.jsx')).toBe(true) |
| 62 | + expect(regex.test('src/page.mdx.ts')).toBe(true) |
| 63 | + // Should NOT match @devup-ui |
| 64 | + expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false) |
| 65 | + }) |
| 66 | + |
| 67 | + it('should handle empty include array', () => { |
| 68 | + const regex = createNodeModulesExcludeRegex([]) |
| 69 | + expect(regex.test('node_modules/some-package/index.js')).toBe(true) |
| 70 | + expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false) |
| 71 | + }) |
| 72 | +}) |
| 73 | + |
| 74 | +describe('DevupUIBasePluginOptions', () => { |
| 75 | + it('should be usable as a type', () => { |
| 76 | + const options: DevupUIBasePluginOptions = { |
| 77 | + package: '@devup-ui/react', |
| 78 | + cssDir: 'df/devup-ui', |
| 79 | + devupFile: 'devup.json', |
| 80 | + distDir: 'df', |
| 81 | + debug: false, |
| 82 | + include: [], |
| 83 | + singleCss: false, |
| 84 | + } |
| 85 | + expect(options.package).toBe('@devup-ui/react') |
| 86 | + }) |
| 87 | + |
| 88 | + it('should accept optional fields', () => { |
| 89 | + const options: DevupUIBasePluginOptions = { |
| 90 | + package: '@devup-ui/react', |
| 91 | + cssDir: 'df/devup-ui', |
| 92 | + devupFile: 'devup.json', |
| 93 | + distDir: 'df', |
| 94 | + debug: false, |
| 95 | + include: [], |
| 96 | + singleCss: false, |
| 97 | + prefix: 'my-prefix', |
| 98 | + importAliases: { '@emotion/styled': 'styled' }, |
| 99 | + } |
| 100 | + expect(options.prefix).toBe('my-prefix') |
| 101 | + expect(options.importAliases).toEqual({ '@emotion/styled': 'styled' }) |
| 102 | + }) |
| 103 | +}) |
0 commit comments