forked from parcel-bundler/parcel
/
svg-react.js
39 lines (36 loc) 路 1.32 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
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'));
});
});