test: allow unbuilt tdesign style fallback

This commit is contained in:
2026-04-23 21:30:55 +08:00
parent 672612f1b5
commit 19035e8f93

View File

@@ -67,17 +67,38 @@ function getImportTarget(wxssPath, importPath) {
return path.resolve(path.dirname(wxssPath), importPath)
}
function getTDesignSourceFallback(importPath) {
const generatedPrefix = './miniprogram_npm/tdesign-miniprogram/'
if (!importPath.startsWith(generatedPrefix)) {
return null
}
return path.join(
PROJECT_ROOT,
'node_modules',
'tdesign-miniprogram',
'miniprogram_dist',
importPath.slice(generatedPrefix.length)
)
}
describe('miniprogram compatibility', () => {
test('avoids directory-level require paths that the miniprogram runtime cannot resolve reliably', () => {
expect(getDirectoryImportViolations()).toEqual([])
})
test('app.wxss imports the generated TDesign style entry that exists in the project', () => {
test('app.wxss points at a TDesign style entry that can be resolved before or after npm build', () => {
const appWxssPath = path.join(PROJECT_ROOT, 'app.wxss')
const appWxss = fs.readFileSync(appWxssPath, 'utf8')
const match = appWxss.match(/@import ['"]([^'"]+)['"];/)
const importPath = match && match[1]
const generatedTarget = importPath && getImportTarget(appWxssPath, importPath)
const sourceFallbackTarget = importPath && getTDesignSourceFallback(importPath)
expect(match).not.toBeNull()
expect(fs.existsSync(getImportTarget(appWxssPath, match[1]))).toBe(true)
expect(
fs.existsSync(generatedTarget) || (sourceFallbackTarget && fs.existsSync(sourceFallbackTarget))
).toBe(true)
})
})