|
| 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 | +}) |
0 commit comments