Skip to content

Commit 3ae6e15

Browse files
authored
Merge pull request #127 from dev-five-git/test-coverage-issue
Fix test coverage issue
2 parents edc172a + ff4494c commit 3ae6e15

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.changeset/spotty-beds-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/vite-plugin": patch
3+
---
4+
5+
Fix test coverage

packages/vite-plugin/src/__tests__/plugin.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,53 @@ describe('devupUIPlugin', () => {
117117
;(plugin as any).transform('code', 'correct.ts')
118118
expect(writeFileSync).toBeCalledTimes(1)
119119
})
120+
it('should transform code', () => {
121+
const devupPath = 'devup.json'
122+
const interfacePath = '.df'
123+
const cssFile = join(_dirname, 'devup-ui.css')
124+
const libPackage = '@devup-ui/react'
125+
vi.mocked(existsSync).mockReturnValueOnce(true).mockReturnValueOnce(false)
126+
vi.mocked(getThemeInterface).mockReturnValue('interface code')
127+
vi.mocked(readFileSync).mockReturnValueOnce('{"theme": {}}')
128+
const options = {
129+
package: libPackage,
130+
cssFile,
131+
devupPath,
132+
interfacePath,
133+
}
134+
const plugin = DevupUI(options)
135+
expect(plugin).toEqual({
136+
name: 'devup-ui',
137+
config: expect.any(Function),
138+
watchChange: expect.any(Function),
139+
enforce: 'pre',
140+
transform: expect.any(Function),
141+
apply: expect.any(Function),
142+
})
143+
expect(existsSync).toHaveBeenCalledWith(devupPath)
144+
expect(getThemeInterface).toHaveBeenCalledWith(
145+
libPackage,
146+
'DevupThemeColors',
147+
'DevupThemeTypography',
148+
'DevupTheme',
149+
)
150+
expect(readFileSync).toHaveBeenCalledWith(devupPath, 'utf-8')
151+
expect(existsSync).toHaveBeenCalledWith(interfacePath)
152+
vi.clearAllMocks()
153+
vi.mocked(codeExtract).mockReturnValueOnce({
154+
css: 'css code',
155+
code: 'code',
156+
} as any)
157+
// eslint-disable-next-line prefer-spread
158+
;(plugin as any).apply(null, {
159+
command: 'serve',
160+
})
161+
vi.stubEnv('NODE_ENV', 'development')
162+
expect((plugin as any).transform('code', 'correct.ts').code).toContain(
163+
'document.head.appendChild',
164+
)
165+
expect(writeFileSync).toBeCalledTimes(1)
166+
})
120167
it('should not extract code', () => {
121168
const devupPath = 'devup.json'
122169
const interfacePath = '.df'

packages/vite-plugin/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function DevupUI({
109109
writeFileSync(cssFile, css, {
110110
encoding: 'utf-8',
111111
})
112-
if (command === 'serve')
112+
if (command === 'serve' && process.env.NODE_ENV !== 'test')
113113
return {
114114
code: `${retCode}
115115
if(typeof window !== 'undefined'){

0 commit comments

Comments
 (0)