test: allow unbuilt tdesign style fallback
This commit is contained in:
@@ -67,17 +67,38 @@ function getImportTarget(wxssPath, importPath) {
|
|||||||
return path.resolve(path.dirname(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', () => {
|
describe('miniprogram compatibility', () => {
|
||||||
test('avoids directory-level require paths that the miniprogram runtime cannot resolve reliably', () => {
|
test('avoids directory-level require paths that the miniprogram runtime cannot resolve reliably', () => {
|
||||||
expect(getDirectoryImportViolations()).toEqual([])
|
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 appWxssPath = path.join(PROJECT_ROOT, 'app.wxss')
|
||||||
const appWxss = fs.readFileSync(appWxssPath, 'utf8')
|
const appWxss = fs.readFileSync(appWxssPath, 'utf8')
|
||||||
const match = appWxss.match(/@import ['"]([^'"]+)['"];/)
|
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(match).not.toBeNull()
|
||||||
expect(fs.existsSync(getImportTarget(appWxssPath, match[1]))).toBe(true)
|
expect(
|
||||||
|
fs.existsSync(generatedTarget) || (sourceFallbackTarget && fs.existsSync(sourceFallbackTarget))
|
||||||
|
).toBe(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user