forked from pkgxdev/pkgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhydrate.test.ts
82 lines (69 loc) · 2.2 KB
/
hydrate.test.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { assertEquals } from "deno/testing/asserts.ts"
import suite from "../integration.suite.ts"
import { PackageRequirement } from "types"
import * as semver from "utils/semver.ts"
import { it } from "deno/testing/bdd.ts"
import { hydrate } from "prefab"
it(suite, "hydrates.1", async function() {
const pkgs = [
{ project: 'nodejs.org', constraint: new semver.Range('*') },
{ project: 'nodejs.org', constraint: new semver.Range('>=18.14') }
]
const rv1 = semver.intersect(pkgs[0].constraint, pkgs[1].constraint)
assertEquals(rv1.toString(), '>=18.14')
const rv = await hydrate(pkgs, (_a: PackageRequirement, _b: boolean) => Promise.resolve([]))
let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'nodejs.org') {
nodes++
assertEquals(pkg.constraint.toString(), '>=18.14')
}
}
assertEquals(nodes, 1)
})
it(suite, "hydrates.2", async function() {
const pkgs = [
{ project: 'pipenv.pypa.io', constraint: new semver.Range('*') },
{ project: 'python.org', constraint: new semver.Range('~3.9') }
]
const rv = await hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
if (pkg.project === 'pipenv.pypa.io') {
return Promise.resolve([
{ project: 'python.org', constraint: new semver.Range('>=3.7') }
])
} else {
return Promise.resolve([])
}
})
let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'python.org') {
assertEquals(pkg.constraint.toString(), '~3.9')
nodes++
}
}
assertEquals(nodes, 1)
})
it(suite, "hydrates.3", async function() {
const pkgs = [
{ project: 'pipenv.pypa.io', constraint: new semver.Range('*') },
{ project: 'python.org', constraint: new semver.Range('~3.9') }
]
const rv = await hydrate(pkgs, (pkg: PackageRequirement, _dry: boolean) => {
if (pkg.project === 'pipenv.pypa.io') {
return Promise.resolve([
{ project: 'python.org', constraint: new semver.Range('~3.9.1') }
])
} else {
return Promise.resolve([])
}
})
let nodes = 0
for (const pkg of rv.pkgs) {
if (pkg.project === 'python.org') {
assertEquals(pkg.constraint.toString(), '~3.9.1')
nodes++
}
}
assertEquals(nodes, 1)
})