-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathshared.test.ts
More file actions
136 lines (115 loc) · 4.85 KB
/
Copy pathshared.test.ts
File metadata and controls
136 lines (115 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { describe, expect, it } from 'bun:test'
import {
createNodeModulesExcludeRegex,
type DevupUIBasePluginOptions,
getFileNumByFilename,
} from '../shared'
describe('getFileNumByFilename', () => {
it('should return null for devup-ui.css', () => {
expect(getFileNumByFilename('devup-ui.css')).toBeNull()
})
it('should return file number for devup-ui-5.css', () => {
expect(getFileNumByFilename('devup-ui-5.css')).toBe(5)
})
it('should return file number for devup-ui-123.css', () => {
expect(getFileNumByFilename('devup-ui-123.css')).toBe(123)
})
it('should handle query params: devup-ui.css?fileNum=79', () => {
expect(getFileNumByFilename('devup-ui.css?fileNum=79')).toBe(79)
})
it('should handle path with query: /path/to/devup-ui.css?fileNum=42', () => {
expect(getFileNumByFilename('/path/to/devup-ui.css?fileNum=42')).toBe(42)
})
it('should return null for path/to/devup-ui.css (no number, no query)', () => {
expect(getFileNumByFilename('path/to/devup-ui.css')).toBeNull()
})
// Regression: when Next.js `assetPrefix` is set, Turbopack appends extra
// query parameters (e.g. `?dpl=DEPLOYMENT_ID`) to module URLs. The base
// CSS file must still be detected correctly, otherwise `@layer b` styles
// are dropped from the build output.
it('should return null for devup-ui.css with non-fileNum query (?dpl=...)', () => {
expect(getFileNumByFilename('devup-ui.css?dpl=abc')).toBeNull()
})
it('should return null for devup-ui.css with version query (?v=...)', () => {
expect(getFileNumByFilename('devup-ui.css?v=12345')).toBeNull()
})
it('should return null for path/to/devup-ui.css with deployment query', () => {
expect(getFileNumByFilename('/path/to/devup-ui.css?dpl=abc')).toBeNull()
})
it('should still extract fileNum when extra queries follow it', () => {
expect(getFileNumByFilename('devup-ui.css?fileNum=5&dpl=abc')).toBe(5)
})
it('should still extract fileNum when extra queries precede it', () => {
expect(getFileNumByFilename('devup-ui.css?dpl=abc&fileNum=7')).toBe(7)
})
it('should extract file number from devup-ui-5.css with query', () => {
expect(getFileNumByFilename('devup-ui-5.css?dpl=abc')).toBe(5)
})
it('should return null for unrelated css filename', () => {
expect(getFileNumByFilename('something-else.css')).toBeNull()
})
})
describe('createNodeModulesExcludeRegex', () => {
it('should match node_modules paths that should be excluded', () => {
const regex = createNodeModulesExcludeRegex([])
expect(regex.test('node_modules/some-package/index.js')).toBe(true)
expect(regex.test('/path/to/node_modules/lodash/index.js')).toBe(true)
})
it('should NOT match @devup-ui paths', () => {
const regex = createNodeModulesExcludeRegex([])
expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false)
expect(regex.test('node_modules/@devup-ui/components/index.js')).toBe(false)
expect(regex.test('node_modules/@devup-editor/react/index.js')).toBe(false)
})
it('should NOT match included packages', () => {
const regex = createNodeModulesExcludeRegex(['my-company/design-system'])
expect(regex.test('node_modules/my-company/design-system/index.js')).toBe(
false,
)
})
it('should handle extra excludes parameter', () => {
const regex = createNodeModulesExcludeRegex([], '.mdx.[tj]sx?$')
// Should match node_modules
expect(regex.test('node_modules/some-package/index.js')).toBe(true)
// Should also match .mdx.tsx files
expect(regex.test('src/page.mdx.tsx')).toBe(true)
expect(regex.test('src/page.mdx.jsx')).toBe(true)
expect(regex.test('src/page.mdx.ts')).toBe(true)
// Should NOT match @devup-ui
expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false)
})
it('should handle empty include array', () => {
const regex = createNodeModulesExcludeRegex([])
expect(regex.test('node_modules/some-package/index.js')).toBe(true)
expect(regex.test('node_modules/@devup-ui/react/index.js')).toBe(false)
})
})
describe('DevupUIBasePluginOptions', () => {
it('should be usable as a type', () => {
const options: DevupUIBasePluginOptions = {
package: '@devup-ui/react',
cssDir: 'df/devup-ui',
devupFile: 'devup.json',
distDir: 'df',
debug: false,
include: [],
singleCss: false,
}
expect(options.package).toBe('@devup-ui/react')
})
it('should accept optional fields', () => {
const options: DevupUIBasePluginOptions = {
package: '@devup-ui/react',
cssDir: 'df/devup-ui',
devupFile: 'devup.json',
distDir: 'df',
debug: false,
include: [],
singleCss: false,
prefix: 'my-prefix',
importAliases: { '@emotion/styled': 'styled' },
}
expect(options.prefix).toBe('my-prefix')
expect(options.importAliases).toEqual({ '@emotion/styled': 'styled' })
})
})