npm-dependency-prune.test.mjs
2.02 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
49
50
51
52
53
54
55
56
57
58
import assert from 'node:assert/strict'
import { readFile } 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('mini-program npm dependency pruning', () => {
it('removes the unused glsx component plugin from every dependency manifest', async () => {
const packageJson = JSON.parse(
await readFile(path.join(projectRoot, 'package.json'), 'utf8')
)
const packageLock = JSON.parse(
await readFile(path.join(projectRoot, 'package-lock.json'), 'utf8')
)
const yarnLock = await readFile(path.join(projectRoot, 'yarn.lock'), 'utf8')
assert.equal(packageJson.dependencies['glsx-applet-component'], undefined)
assert.equal(
packageLock.packages[''].dependencies['glsx-applet-component'],
undefined
)
assert.equal(
packageLock.packages['node_modules/glsx-applet-component'],
undefined
)
assert.doesNotMatch(yarnLock, /^glsx-applet-component@/m)
})
it('keeps the privacy component dependency used by app.json', async () => {
const packageJson = JSON.parse(
await readFile(path.join(projectRoot, 'package.json'), 'utf8')
)
const packageLock = JSON.parse(
await readFile(path.join(projectRoot, 'package-lock.json'), 'utf8')
)
const yarnLock = await readFile(path.join(projectRoot, 'yarn.lock'), 'utf8')
const appConfig = JSON.parse(
await readFile(path.join(projectRoot, 'app.json'), 'utf8')
)
assert.equal(packageJson.dependencies['glsk-applet-component'], '^1.0.0')
assert.equal(
packageLock.packages[''].dependencies['glsk-applet-component'],
'^1.0.0'
)
assert.ok(packageLock.packages['node_modules/glsk-applet-component'])
assert.match(yarnLock, /^glsk-applet-component@\^1\.0\.0:\r?$/m)
assert.equal(
appConfig.usingComponents['glsx-privacy'],
'glsk-applet-component/GlsxPrivacy/index'
)
})
})