Skip to content

Commit e6b069f

Browse files
committed
test: cover preprocessor tailwind source in demo
1 parent 99cd433 commit e6b069f

21 files changed

Lines changed: 173 additions & 20 deletions

File tree

.changeset/preprocessor-tailwind-source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"weapp-tailwindcss": patch
33
---
44

5-
增强 Sass/Less 等预处理器样式入口的 Tailwind 指令识别与改写能力,避免将预处理器私有语法直接交给 Tailwind 解析。
5+
增强 Sass/Less 等预处理器样式入口的 Tailwind 指令识别与改写能力,避免将预处理器私有语法直接交给 Tailwind 解析,并补充真实 demo 与 CI 回归覆盖

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
- name: E2E Static
5959
run: pnpm e2e:static
6060

61+
- name: E2E Preprocessor Source
62+
run: pnpm e2e:preprocessor
63+
6164
- name: E2E Framework Support
6265
run: pnpm exec cross-env E2E_FRAMEWORK_SUPPORT=1 vitest run -c ./e2e/vitest.e2e.config.ts e2e/framework-ci-support.test.ts
6366

@@ -71,6 +74,7 @@ jobs:
7174
echo "## CI 状态说明"
7275
echo "- 本工作流负责:lint、build、unit/integration tests、coverage 上传。"
7376
echo "- 现在额外包含:\`pnpm e2e:static\`,用于保证 v5 生成示例和静态快照与 CI 一致。"
77+
echo "- 现在额外包含:\`pnpm e2e:preprocessor\`,用于保证 Sass/Less 等预处理器 Tailwind 入口在真实 demo 中可构建。"
7478
echo "- 现在额外包含:跨框架支持矩阵 e2e,用于保证 demo 构建入口与模板静态输出一致。"
7579
echo "- \`pnpm e2e:ci\` 仍保留本地/专项使用,其中 hot-update/watch 覆盖由独立工作流承载。"
7680
echo "- \`Compatibility Gate\` 负责跨系统/多 Node 的核心回归,避免把全仓 lint/build 在每个矩阵里重复执行。"

demo/weapp-vite-tailwindcss-v4/app.css

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Tailwind root entry intentionally lives in SCSS to cover preprocessor source handling.
2+
@import "tailwindcss";
3+
@config "./tailwind.config.js";
4+
5+
page {
6+
--preprocessor-entry-marker: #1d4ed8;
7+
}

e2e/__snapshots__/apps-generator-mode/compare/report.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9169,7 +9169,7 @@
91699169
],
91709170
"status": "passed",
91719171
"generator": {
9172-
"bytes": 20551,
9172+
"bytes": 20591,
91739173
"selectors": [
91749174
".before_ccontent-_b_aindependent_subpackage_weapp-vite-tailwindcss-v4_a_B:before",
91759175
".before_ccontent-_b_anormal_subpackage_weapp-vite-tailwindcss-v4_a_B:before",

e2e/__snapshots__/apps-generator-mode/compare/report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This report is generated by `pnpm e2e:apps-generator`. It builds each retained d
2121
| uni-app-vite-tailwindcss-v3 | demo | passed | `uni-app-vite-tailwindcss-v3/dist/build/mp-weixin/app.wxss` (+12) | 493749 | 2838 | no | no | no | no | yes |
2222
| uni-app-vite-tailwindcss-v4 | demo | passed | `uni-app-vite-tailwindcss-v4/dist/build/mp-weixin/app.wxss` (+4) | 140805 | 240 | no | no | no | no | yes |
2323
| weapp-vite-tailwindcss-v3 | demo | passed | `weapp-vite-tailwindcss-v3/dist/app.wxss` (+5) | 33934 | 144 | no | no | no | no | yes |
24-
| weapp-vite-tailwindcss-v4 | demo | passed | `weapp-vite-tailwindcss-v4/dist/app.wxss` (+4) | 20551 | 59 | no | no | no | no | yes |
24+
| weapp-vite-tailwindcss-v4 | demo | passed | `weapp-vite-tailwindcss-v4/dist/app.wxss` (+4) | 20591 | 59 | no | no | no | no | yes |
2525

2626
## Notes
2727

e2e/__snapshots__/apps-generator-mode/compare/report.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
| uni-app-vite-tailwindcss-v3 | demo | 通过 | `uni-app-vite-tailwindcss-v3/dist/build/mp-weixin/app.wxss` (+12) | 493749 | 2838 ||||||
2222
| uni-app-vite-tailwindcss-v4 | demo | 通过 | `uni-app-vite-tailwindcss-v4/dist/build/mp-weixin/app.wxss` (+4) | 140805 | 240 ||||||
2323
| weapp-vite-tailwindcss-v3 | demo | 通过 | `weapp-vite-tailwindcss-v3/dist/app.wxss` (+5) | 33934 | 144 ||||||
24-
| weapp-vite-tailwindcss-v4 | demo | 通过 | `weapp-vite-tailwindcss-v4/dist/app.wxss` (+4) | 20551 | 59 ||||||
24+
| weapp-vite-tailwindcss-v4 | demo | 通过 | `weapp-vite-tailwindcss-v4/dist/app.wxss` (+4) | 20591 | 59 ||||||
2525

2626
## 说明
2727

e2e/__snapshots__/apps-generator-mode/css-output/weapp-vite-tailwindcss-v4.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Generator CSS files: app.wxss, apple.wxss, index.wxss, index.wxss, index.wxss
66

77
| Bytes | Selectors | @supports | :hover | Tailwind banner | Raw arbitrary selector | Weapp escaped arbitrary selector |
88
| ---: | ---: | --- | --- | --- | --- | --- |
9-
| 20551 | 59 | false | false | false | false | true |
9+
| 20591 | 59 | false | false | false | false | true |
1010

1111
## Generator CSS
1212

@@ -65,6 +65,7 @@ wx-root-portal-content {
6565
--default-transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
6666
--default-font-family: var(--font-sans);
6767
--default-mono-font-family: var(--font-mono);
68+
--preprocessor-entry-marker: #1d4ed8;
6869
}
6970
.flex {
7071
display: -webkit-flex;

e2e/preprocessor-source.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import fs from 'node:fs/promises'
2+
import process from 'node:process'
3+
import { execa } from 'execa'
4+
import fg from 'fast-glob'
5+
import path from 'pathe'
6+
import { describe, expect, it } from 'vitest'
7+
8+
const demoRoot = path.resolve(__dirname, '../demo/weapp-vite-tailwindcss-v4')
9+
10+
async function readAllWxssFiles(root: string) {
11+
const files = await fg('dist/**/*.wxss', {
12+
absolute: true,
13+
cwd: root,
14+
onlyFiles: true,
15+
})
16+
return Promise.all(files.sort().map(async (file) => {
17+
return {
18+
file,
19+
content: await fs.readFile(file, 'utf8'),
20+
}
21+
}))
22+
}
23+
24+
describe('preprocessor Tailwind source demo', () => {
25+
it('builds Tailwind v4 from a real SCSS root entry without leaking preprocessor syntax', async () => {
26+
const appScss = await fs.readFile(path.join(demoRoot, 'app.scss'), 'utf8')
27+
expect(appScss).toContain('@import "tailwindcss";')
28+
expect(appScss).toContain('// Tailwind root entry intentionally lives in SCSS')
29+
30+
await fs.rm(path.join(demoRoot, 'dist'), { recursive: true, force: true })
31+
await execa('pnpm', ['--filter', '@weapp-tailwindcss-demo/weapp-vite-tailwindcss-v4', 'build'], {
32+
cwd: path.resolve(__dirname, '..'),
33+
stdio: process.env.E2E_DEBUG_BUILD === '1' ? 'inherit' : 'pipe',
34+
env: {
35+
...process.env,
36+
NODE_ENV: 'production',
37+
BROWSERSLIST_ENV: 'production',
38+
npm_package_json: path.join(demoRoot, 'package.json'),
39+
INIT_CWD: demoRoot,
40+
},
41+
})
42+
43+
const wxssFiles = await readAllWxssFiles(demoRoot)
44+
const appWxss = await fs.readFile(path.join(demoRoot, 'dist/app.wxss'), 'utf8')
45+
const joined = wxssFiles.map(item => item.content).join('\n')
46+
47+
expect(appWxss).toContain('--preprocessor-entry-marker: #1d4ed8;')
48+
expect(appWxss).toContain('.flex')
49+
expect(joined).not.toContain('@import "tailwindcss"')
50+
expect(joined).not.toContain('@config "./tailwind.config.js"')
51+
expect(joined).not.toContain('// Tailwind root entry intentionally lives in SCSS')
52+
expect(joined).not.toContain('$preprocessor')
53+
expect(joined).not.toContain('#{$')
54+
}, 120_000)
55+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"e2e:ide:skip-build": "cross-env E2E_IDE=1 E2E_IDE_BUILD=0 vitest run --bail=1 -c ./e2e/vitest.e2e.config.ts e2e/framework-ide-support.test.ts",
8686
"e2e:ide:case": "cross-env E2E_IDE=1 E2E_IDE_BUILD=1 E2E_IDE_PROBE_RETRIES=0 vitest run --bail=1 -c ./e2e/vitest.e2e.config.ts e2e/framework-ide-support.test.ts",
8787
"e2e:ide:case:skip-build": "cross-env E2E_IDE=1 E2E_IDE_BUILD=0 E2E_IDE_PROBE_RETRIES=0 vitest run --bail=1 -c ./e2e/vitest.e2e.config.ts e2e/framework-ide-support.test.ts",
88+
"e2e:preprocessor": "vitest run -c ./e2e/vitest.e2e.config.ts e2e/preprocessor-source.test.ts",
8889
"e2e:apps-generator": "vitest run -c ./e2e/vitest.e2e.config.ts e2e/apps-generator-mode-compare.test.ts",
8990
"e2e:apps-generator:u": "vitest run -u -c ./e2e/vitest.e2e.config.ts e2e/apps-generator-mode-compare.test.ts",
9091
"e2e:generator-parity": "vitest run -c ./e2e/vitest.e2e.config.ts e2e/generator-tailwind-parity.test.ts",

0 commit comments

Comments
 (0)