forked from jspm/jspm-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproviders.test.ts
62 lines (57 loc) · 1.8 KB
/
providers.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
import assert from "assert";
import { availableProviders } from "../src/utils";
import {
type Scenario,
mapDirectory,
mapFile,
runScenarios,
} from "./scenarios";
const scenarios: Scenario[] = [
// Scenario that checks we can swap providers with a reinstall:
{
files: await mapDirectory("test/fixtures/scenario_provider_swap"),
commands: [`jspm install --provider nodemodules`],
validationFn: async (files) => {
const map = files.get("importmap.json");
assert(!!map);
assert(!map.includes("jspm.io"));
},
},
// Scenario that checks the provider is auto-detected from the initial map:
{
files: await mapFile("test/fixtures/unpkg.importmap.json"),
commands: [`jspm link -m unpkg.importmap.json -o importmap.json`],
validationFn: async (files) => {
const map = files.get("importmap.json");
assert(!!map);
assert(!map.includes("jspm.io"));
},
},
];
// Scenarios that check we can use each available provider:
const files = await mapDirectory("test/fixtures/scenario_providers");
for (const provider of availableProviders) {
let spec = "lit";
let name = "lit";
if (provider.includes("deno")) {
spec = "denoland:oak/body.ts"; // deno doesn't support npm packages
name = "oak/body.ts";
}
if (provider === "node") {
spec = "@jspm/core/nodelibs/fs"; // node provider is only for polyfills
name = "@jspm/core/nodelibs/fs";
}
if (provider === "nodemodules") {
spec = "lit"; // must be installed in the fixture
name = "lit";
}
scenarios.push({
files,
commands: [`jspm install ${spec} -p ${provider} -e production`],
validationFn: async (files: Map<string, string>) => {
const map = JSON.parse(files.get("importmap.json") ?? "{}");
assert(map?.imports?.[name]);
},
});
}
runScenarios(scenarios);