forked from parcel-bundler/parcel
/
svg-react.js
59 lines (53 loc) 路 1.93 KB
/
svg-react.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
import assert from 'assert';
import {bundle, outputFS} from '@parcel/test-utils';
import path from 'path';
describe('svg-react', function () {
it('should support transforming SVGs to react components', async function () {
let b = await bundle(
path.join(__dirname, '/integration/svg-react/react.js'),
{
defaultConfig: path.join(
__dirname,
'integration/custom-configs/.parcelrc-svg-react',
),
},
);
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf-8');
assert(!file.includes('inkscape'));
assert(file.includes('const SvgIcon ='));
assert(file.includes('_react.createElement("svg"'));
});
it('should support transforming SVGs to typescript react components', async function () {
let b = await bundle(
path.join(__dirname, '/integration/svg-react-typescript/react.ts'),
{
defaultConfig: path.join(
__dirname,
'integration/custom-configs/.parcelrc-svg-react',
),
},
);
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf-8');
let types = await outputFS.readFile(b.getBundles()[1].filePath, 'utf-8');
assert(!file.includes('inkscape'));
assert(file.includes('react.createElement("svg"'));
assert(types.includes('const Icon: SVGRComponent'));
});
it('should find and use a .svgrrc and .svgorc config file', async function () {
let b = await bundle(
path.join(__dirname, '/integration/svg-react-config/react.js'),
{
defaultConfig: path.join(
__dirname,
'integration/custom-configs/.parcelrc-svg-react',
),
},
);
let file = await outputFS.readFile(b.getBundles()[0].filePath, 'utf-8');
assert(!file.includes('inkscape'));
assert(!/\d\.\d/.test(file));
assert(file.includes('const SvgIcon ='));
assert(file.includes('(0, _preact.h)("svg"'));
assert(file.includes('width: "1em"'));
});
});