Skip to content

Commit 68540fb

Browse files
authored
Merge pull request #457 from dev-five-git/turbo-files-issue
Refactor turbo
2 parents 7636708 + bac9016 commit 68540fb

File tree

11 files changed

+576
-10
lines changed

11 files changed

+576
-10
lines changed

.changeset/tough-lizards-train.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@devup-ui/next-plugin': patch
3+
---
4+
5+
Create Theme type file

.changeset/young-poets-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@devup-ui/next-plugin': patch
3+
---
4+
5+
Using next-turbo loader

packages/next-plugin/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
".": {
3535
"import": "./dist/index.js",
3636
"require": "./dist/index.cjs"
37+
},
38+
"./css-loader": {
39+
"import": "./dist/css-loader.js",
40+
"require": "./dist/css-loader.cjs"
41+
},
42+
"./loader": {
43+
"import": "./dist/loader.js",
44+
"require": "./dist/loader.cjs"
3745
}
3846
},
3947
"files": [
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { resolve } from 'node:path'
2+
3+
import { getCss } from '@devup-ui/wasm'
4+
5+
import devupUICssLoader from '../css-loader'
6+
7+
vi.mock('node:path')
8+
vi.mock('@devup-ui/wasm', () => ({
9+
registerTheme: vi.fn(),
10+
getCss: vi.fn(),
11+
}))
12+
13+
beforeEach(() => {
14+
vi.resetAllMocks()
15+
})
16+
17+
describe('devupUICssLoader', () => {
18+
it('should return css on no watch', () => {
19+
const callback = vi.fn()
20+
const addContextDependency = vi.fn()
21+
vi.mocked(resolve).mockReturnValue('resolved')
22+
vi.mocked(getCss).mockReturnValue('get css')
23+
devupUICssLoader.bind({
24+
callback,
25+
addContextDependency,
26+
resourcePath: 'devup-ui.css',
27+
getOptions: () => ({ watch: false }),
28+
} as any)(Buffer.from('data'), '')
29+
expect(callback).toBeCalledWith(null, 'get css', '', undefined)
30+
})
31+
32+
it('should return _compiler hit css on watch', () => {
33+
const callback = vi.fn()
34+
const addContextDependency = vi.fn()
35+
vi.mocked(resolve).mockReturnValue('resolved')
36+
vi.mocked(getCss).mockReturnValue('get css')
37+
devupUICssLoader.bind({
38+
callback,
39+
addContextDependency,
40+
getOptions: () => ({ watch: true }),
41+
resourcePath: 'devup-ui.css',
42+
} as any)(Buffer.from('data'), '')
43+
expect(callback).toBeCalledWith(null, 'get css', '', undefined)
44+
expect(getCss).toBeCalledTimes(1)
45+
vi.mocked(getCss).mockReset()
46+
devupUICssLoader.bind({
47+
callback,
48+
addContextDependency,
49+
getOptions: () => ({ watch: true }),
50+
resourcePath: 'devup-ui.css',
51+
} as any)(Buffer.from('data'), '')
52+
53+
expect(getCss).toBeCalledTimes(1)
54+
55+
vi.mocked(getCss).mockReset()
56+
57+
devupUICssLoader.bind({
58+
callback,
59+
addContextDependency,
60+
getOptions: () => ({ watch: true }),
61+
resourcePath: 'devup-ui-10.css',
62+
} as any)(Buffer.from(''), '')
63+
64+
expect(getCss).toBeCalledTimes(1)
65+
})
66+
})

0 commit comments

Comments
 (0)