-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.js
67 lines (60 loc) · 2.18 KB
/
test.js
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
const test = require("ava");
const React = require("react");
const renderer = require("react-test-renderer");
const fs = require("fs");
const filenameMap = require("./filenameMap");
const commonjsIcons = require("./package/index");
const commonjsIconsLight = require("./package/light/index");
test("the npm package", (t) => {
// should set sideEffects to false to allow webpack to optimize re-exports
const packageJson = require("./package/package.json");
t.false(packageJson.sideEffects);
});
for (const iconName of Object.keys(commonjsIcons)) {
test(`icons > ${iconName}`, (t) => {
const renderedIcon = renderer
.create(React.createElement(commonjsIcons[iconName]))
.toJSON();
// t.is(renderedIcon[0].type, 'style') // generated by emotion
t.is(renderedIcon[1].type, "svg");
t.is(renderedIcon[1].props["data-testid"], `${iconName}Icon`);
});
}
test("ES module index file", (t) => {
const esmReExports = fs
.readFileSync("./package/esm/index.js", "utf-8")
.split("\n")
.filter((line) => line.length > 0);
t.is(esmReExports.length, Object.keys(commonjsIcons).length);
for (const line of esmReExports) {
const match = line.match(
/^export \{ default as (.+?) \} from '\.\/(.+?)'$/
);
t.is(filenameMap[match[1]] || match[1], match[2]);
t.truthy(commonjsIcons[match[1]]);
}
});
for (const iconName of Object.keys(commonjsIconsLight)) {
test(`light icons > ${iconName}`, (t) => {
const renderedIcon = renderer
.create(React.createElement(commonjsIconsLight[iconName]))
.toJSON();
// t.is(renderedIcon[0].type, 'style') // generated by emotion
t.is(renderedIcon[1].type, "svg");
t.is(renderedIcon[1].props["data-testid"], `${iconName}Icon`);
});
}
test("mdi-light ES module index file", (t) => {
const esmReExports = fs
.readFileSync("./package/esm/light/index.js", "utf-8")
.split("\n")
.filter((line) => line.length > 0);
t.is(esmReExports.length, Object.keys(commonjsIconsLight).length);
for (const line of esmReExports) {
const match = line.match(
/^export \{ default as (.+?) \} from '\.\/(.+?)'$/
);
t.is(match[1], match[2]);
t.truthy(commonjsIconsLight[match[1]]);
}
});