Skip to content

Commit 869868d

Browse files
committed
test: make watch hmr path assertions portable
1 parent d8bf29d commit 869868d

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

packages/weapp-tailwindcss/test/watch-hmr-coverage-matrix.unit.test.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ const matrixProjects = [
5151
'demo/weapp-vite-tailwindcss-v4',
5252
]
5353

54+
function toSlashPath(filePath: string) {
55+
return filePath.replace(/\\/g, '/')
56+
}
57+
58+
function expectDemoSourceFile(sourceFile: string, message: string) {
59+
const normalizedSourceFile = toSlashPath(sourceFile)
60+
61+
expect(normalizedSourceFile, `${message} should edit demo source files`).toContain('/repo/demo/')
62+
expect(normalizedSourceFile, `${message} should not edit generated dist files`).not.toContain('/dist/')
63+
}
64+
5465
describe('watch-hmr coverage matrix', () => {
5566
it('covers every retained demo matrix project through watch regression cases', () => {
5667
for (const project of matrixProjects) {
@@ -98,18 +109,24 @@ describe('watch-hmr coverage matrix', () => {
98109
]
99110

100111
for (const mutationConfig of mutationConfigs) {
101-
expect(mutationConfig.sourceFile, `${watchCase.project} should edit demo source files`).toContain('/repo/demo/')
102-
expect(mutationConfig.sourceFile, `${watchCase.project} should not edit generated dist files`).not.toContain('/dist/')
112+
expectDemoSourceFile(mutationConfig.sourceFile, watchCase.project)
103113
}
104114

105115
if (watchCase.contentMutation) {
106-
expect(watchCase.contentMutation.sourceFile, `${watchCase.project} content mutation should edit demo source files`).toContain('/repo/demo/')
107-
expect(watchCase.contentMutation.sourceFile, `${watchCase.project} content mutation should not edit generated dist files`).not.toContain('/dist/')
116+
expectDemoSourceFile(watchCase.contentMutation.sourceFile, `${watchCase.project} content mutation`)
108117
expect(watchCase.contentMutation.verifyClassLiteralIn, `${watchCase.project} content mutation should verify JS-visible literals`).toContain('js')
109118
}
110119
}
111120
})
112121

122+
it('keeps demo source boundary checks portable on Windows paths', () => {
123+
expectDemoSourceFile('D:\\repo\\demo\\gulp-tailwindcss-v3\\src\\pages\\index\\index.wxml', 'windows demo path')
124+
125+
expect(() => {
126+
expectDemoSourceFile('D:\\repo\\demo\\gulp-tailwindcss-v3\\dist\\pages\\index\\index.wxml', 'windows dist path')
127+
}).toThrow()
128+
})
129+
113130
it('keeps style @apply and Tailwind function validation policy explicit', () => {
114131
for (const watchCase of automatedWatchCases) {
115132
const payload = createStyleMutationPayload(watchCase)

0 commit comments

Comments
 (0)