forked from jspm/jspm-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.test.ts
160 lines (138 loc) · 4.86 KB
/
install.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import assert from "assert";
import type { IImportMap } from "../src/types";
import { type Scenario, runScenarios } from "./scenarios";
const scenarios: Scenario[] = [
// Basic install:
{
commands: ["jspm install [email protected] [email protected]"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map: IImportMap = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.react,
"https://ga.jspm.io/npm:[email protected]/dev.index.js"
);
},
},
// Install, but with a production environment:
{
commands: ["jspm install [email protected] [email protected] -e production"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.react,
"https://ga.jspm.io/npm:[email protected]/index.js"
);
},
},
// Install, but with deno environment:
{
commands: ["jspm install [email protected] [email protected] -e deno"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.react,
"https://ga.jspm.io/npm:[email protected]/dev.index.js"
);
// "deno" should replace "browser" env:
assert.deepEqual(map.env, ["deno", "development", "module"]);
},
},
// Install, but with both deno _and_ browser environments:
{
commands: ["jspm install [email protected] [email protected] -e deno,browser"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.react,
"https://ga.jspm.io/npm:[email protected]/dev.index.js"
);
// Both "deno" and "browser" envs should be present:
assert.deepEqual(map.env, ["browser", "deno", "development", "module"]);
},
},
// Install, but using a alias for the package:
{
commands: ["jspm install -e production [email protected]"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.custom,
"https://ga.jspm.io/npm:[email protected]/index.js"
);
},
},
// Reinstall, changing from development to production:
{
commands: [
"jspm install -e development [email protected]",
"jspm install -e production",
],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert(map.imports.react);
assert(!map.imports.react.includes("dev"));
},
},
// Installing should respect the existing import map's "env" field:
{
commands: ["jspm install -e deno,production [email protected]", "jspm install"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.deepEqual(map.env, ["deno", "module", "production"]);
assert(map.imports.react);
},
},
// You should be able to swap providers using the -p flag:
{
commands: ["jspm install -p jsdelivr -e production,browser [email protected]"],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 2);
const map = JSON.parse(files.get("importmap.json"));
assert.strictEqual(
map.imports.react,
"https://cdn.jsdelivr.net/npm/[email protected]/index.js"
);
},
},
// Even if you give "jspm install" a different output map, it should still
// behave additively and write all top-level pins to the output:
{
commands: [
"jspm install -e production,browser [email protected] [email protected]",
"jspm install -o output.importmap.json lodash", // extract lodash
],
validationFn: async (files: Map<string, string>) => {
assert.equal(files.size, 3);
assert(files.get("importmap.json"));
assert(files.get("output.importmap.json"));
const map = JSON.parse(files.get("output.importmap.json"));
assert.strictEqual(
map.imports.react,
"https://ga.jspm.io/npm:[email protected]/index.js"
);
assert.strictEqual(
map.imports.lodash,
"https://ga.jspm.io/npm:[email protected]/lodash.js"
);
},
},
// Installing should always bump the version if possible.
{
commands: ["jspm install [email protected]", "jspm install react"],
validationFn: async (files: Map<string, string>) => {
const map: IImportMap = JSON.parse(files.get("importmap.json"));
assert.notStrictEqual(
map.imports.react,
"https://cdn.jsdelivr.net/npm/[email protected]/index.js"
);
},
},
];
await runScenarios(scenarios);