forked from ckb-js/lumos
-
Notifications
You must be signed in to change notification settings - Fork 1
/
module.test.mjs
43 lines (35 loc) · 1.11 KB
/
module.test.mjs
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
import { createRequire } from "node:module";
import test from "ava";
import { minimatch } from "minimatch";
const MODULES = [
"@ckb-lumos/bi",
"@ckb-lumos/codec",
"@ckb-lumos/codec/bytes",
"@ckb-lumos/codec/number",
"@ckb-lumos/toolkit",
"@ckb-lumos/base",
"@ckb-lumos/base/blockchain",
"@ckb-lumos/base/since",
"@ckb-lumos/base/utils",
"@ckb-lumos/rpc",
"@ckb-lumos/rpc/types/api",
"@ckb-lumos/rpc/types/rpc",
];
const require = createRequire(import.meta.url);
MODULES.forEach((module) => {
test(`Resolve esm&cjs from ${module}`, async (t) => {
const resolvedEsm = await import.meta.resolve(module);
const resolvedCjs = require.resolve(module);
t.true(minimatch(resolvedEsm, `**/lib.esm/**/*.js`));
t.true(minimatch(resolvedCjs, `**/lib/**/*.js`));
const esm = await import(module);
const cjs = require(module);
const exportedEsm = Object.keys(esm);
const exportedCjs = Object.keys(cjs);
t.deepEqual(
exportedEsm.sort((a, b) => a.localeCompare(b)),
exportedCjs.sort((a, b) => a.localeCompare(b))
);
t.true(exportedEsm.length > 0);
});
});