const { test } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const crypto = require('node:crypto'); const root = path.resolve(__dirname, '../../..'); const read = name => fs.readFileSync(path.join(root, name), 'utf8'); test('WeChat effective business source and all packaged data match the pre-migration snapshot', () => { const baseline = JSON.parse(read('apps/miniprogram/weapp/frontend/source-baseline.json')); for (const [file, expected] of Object.entries(baseline)) { const bytes = fs.readFileSync(path.join(root, 'apps/miniprogram/weapp/frontend/src', file)); const variants = [bytes]; // Git normalizes text line endings; preserve the raw migration hashes while // accepting an equivalent checkout on Windows or Unix. Binary files stay exact. if (/\.(?:[cm]?js|jsx|ts|tsx|scss|css|html|json|md)$/i.test(file)) { const lf = bytes.toString('utf8').replace(/\r\n/g, '\n'); variants.push(Buffer.from(lf), Buffer.from(lf.replace(/\n/g, '\r\n'))); } assert.ok(variants.some(value => crypto.createHash('sha256').update(value).digest('hex') === expected), file); } }); test('WeChat build and tests no longer compile another project source', () => { for (const file of ['config/index.ts', 'tsconfig.json', 'scripts/copy-weapp-static.mjs', 'scripts/test-runtime.cjs', 'scripts/test-social.cjs']) { const source = read(`apps/miniprogram/weapp/${file}`); assert.doesNotMatch(source, /(?:\.\.\/h5|\.\.\/\.\.\/h5|apps\/taro)/); } }); test('Taro Web runtime API routing has no production failover', () => { const config = read('apps/taro/web/config/index.ts'); assert.doesNotMatch(config, /https:\/\/(?:api\.)?nomadro\.(?:cn|com)/); assert.match(config, /127\.0\.0\.1:10089/); const social = read('apps/taro/web/src/services/socialApi.ts'); assert.doesNotMatch(social, /https:\/\/(?:api\.)?nomadro\.(?:cn|com)/); }); test('XHS book builds never invoke a sibling project writer', () => { const source = read('apps/miniprogram/xhs/scripts/assemble_book.py'); assert.doesNotMatch(source, /weapp|pack-hackrobot-book/); assert.doesNotMatch(read('apps/miniprogram/xhs/scripts/export-xhs-offline.mjs'), /path\.join\(mini, 'weapp'\)/); });