-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.js
55 lines (48 loc) · 1.91 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
import test from 'ava'
import React from 'react'
import renderer from 'react-test-renderer'
import fs from '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.type, 'svg')
t.is(commonjsIcons[iconName].muiName, 'SvgIcon')
})
}
test('ES module index file', (t) => {
const esmReExports = fs.readFileSync('./package/index.es.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.type, 'svg')
t.is(commonjsIconsLight[iconName].muiName, 'SvgIcon')
})
}
test('mdi-light ES module index file', (t) => {
const esmReExports = fs.readFileSync('./package/light/index.es.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]])
}
})