From 19035e8f9397d03ed6b750bb4a95c13034ee8f54 Mon Sep 17 00:00:00 2001 From: wdh-home <243823965@qq.com> Date: Thu, 23 Apr 2026 21:30:55 +0800 Subject: [PATCH] test: allow unbuilt tdesign style fallback --- tests/miniprogram-compatibility.test.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/miniprogram-compatibility.test.js b/tests/miniprogram-compatibility.test.js index ab07417..781fc12 100644 --- a/tests/miniprogram-compatibility.test.js +++ b/tests/miniprogram-compatibility.test.js @@ -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) }) })