|
| 1 | +import { mkdtempSync, rmSync } from 'node:fs'; |
| 2 | +import { tmpdir } from 'node:os'; |
| 3 | +import { execSync } from 'node:child_process'; |
| 4 | +import { join, resolve, dirname } from 'node:path'; |
| 5 | +import { fileURLToPath } from 'node:url'; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | + |
| 10 | +const tmp = mkdtempSync(join(tmpdir(), 'rzui-smoke-')); |
| 11 | +let tarPath; |
| 12 | +try { |
| 13 | + // 1. pack the current workspace |
| 14 | + const coreDir = resolve(__dirname, '..'); |
| 15 | + const packOutput = execSync('npm pack --ignore-scripts --silent', { cwd: coreDir }).toString().trim(); |
| 16 | + const tar = packOutput.split('\n').pop().trim(); |
| 17 | + tarPath = resolve(coreDir, tar); |
| 18 | + console.log('tarPath: ', tarPath); |
| 19 | + |
| 20 | + // 2. init an empty project & install ONLY the tarball |
| 21 | + execSync('npm init -y', { cwd: tmp, stdio: 'ignore' }); |
| 22 | + execSync(`npm install --ignore-scripts --silent ${tarPath}`, { cwd: tmp, stdio: 'inherit' }); |
| 23 | + |
| 24 | + // 3. test postcss plugin |
| 25 | + execSync('node -e "require(\'@react-zero-ui/core/postcss\')"', { cwd: tmp, stdio: 'inherit' }); |
| 26 | + |
| 27 | + // 4. test postcss plugin |
| 28 | + execSync( |
| 29 | + "node -e \"const postcss = require('postcss'); " + |
| 30 | + "const rz = require('@react-zero-ui/core/postcss'); " + |
| 31 | + "postcss([rz]).process('h1{}', { from: undefined })" + |
| 32 | + ".then(()=>console.log('postcss ok'))\"", |
| 33 | + { cwd: tmp, stdio: 'inherit' } |
| 34 | + ); |
| 35 | + |
| 36 | + console.log('✅ smoke-test passed'); |
| 37 | +} finally { |
| 38 | + rmSync(tmp, { recursive: true, force: true }); |
| 39 | + rmSync(tarPath, { force: true }); |
| 40 | +} |
0 commit comments