upload-config.test.mjs
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import assert from 'node:assert/strict'
import { readFile, stat } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, it } from 'node:test'
const projectRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../..'
)
describe('小程序上传边界', () => {
it('项目运行时固定为 Node 24 LTS', async () => {
const packageJson = JSON.parse(
await readFile(path.join(projectRoot, 'package.json'), 'utf8')
)
assert.equal(packageJson.volta?.node, '24.18.0')
assert.equal(packageJson.engines?.node, '>=24 <25')
const guardSource = await readFile(
path.join(projectRoot, 'scripts/wx-upload-guard.js'),
'utf8'
)
assert.match(guardSource, /nodeMajor < 24/)
})
it('文档、测试和开发脚本不会进入小程序上传包', async () => {
const config = JSON.parse(
await readFile(path.join(projectRoot, 'project.config.json'), 'utf8')
)
const ignoredFolders = new Set(
config.packOptions.ignore
.filter(item => item.type === 'folder')
.map(item => item.value)
)
for (const folder of ['docs', 'tests', 'scripts']) {
assert.ok(ignoredFolders.has(folder), `未忽略开发目录:${folder}`)
}
})
it('上传前守卫脚本存在并执行静态闭包检查', async () => {
const guardPath = path.join(projectRoot, 'scripts/wx-upload-guard.js')
assert.ok((await stat(guardPath)).isFile())
const source = await readFile(guardPath, 'utf8')
assert.match(source, /check-work-order-migration\.mjs/)
})
})