|
1 | 1 | /* eslint-disable no-restricted-syntax */ |
2 | 2 | import * as fs from 'fs'; |
3 | 3 | import { Canvas, resetEntityCounter } from '@antv/g'; |
4 | | -import { format } from 'prettier'; |
5 | | -import xmlserializer from 'xmlserializer'; |
| 4 | +import { serializeToString } from 'xmlserializer'; |
| 5 | +import { optimize } from 'svgo'; |
6 | 6 | import * as tests from './components'; |
7 | 7 | import { renderCanvas, sleep } from './canvas'; |
8 | 8 | import { fetch } from './fetch'; |
9 | 9 |
|
| 10 | +const format = (svg: SVGElement) => { |
| 11 | + return optimize(serializeToString(svg as any), { |
| 12 | + js2svg: { |
| 13 | + pretty: true, |
| 14 | + indent: 2, |
| 15 | + }, |
| 16 | + plugins: [ |
| 17 | + 'cleanupIds', |
| 18 | + 'cleanupAttrs', |
| 19 | + 'sortAttrs', |
| 20 | + 'sortDefsChildren', |
| 21 | + 'removeUselessDefs', |
| 22 | + { |
| 23 | + name: 'convertPathData', |
| 24 | + params: { |
| 25 | + floatPrecision: 4, |
| 26 | + forceAbsolutePath: true, |
| 27 | + |
| 28 | + applyTransforms: false, |
| 29 | + applyTransformsStroked: false, |
| 30 | + straightCurves: false, |
| 31 | + convertToQ: false, |
| 32 | + lineShorthands: false, |
| 33 | + convertToZ: false, |
| 34 | + curveSmoothShorthands: false, |
| 35 | + smartArcRounding: false, |
| 36 | + removeUseless: false, |
| 37 | + collapseRepeated: false, |
| 38 | + utilizeAbsolute: false, |
| 39 | + negativeExtraSpace: false, |
| 40 | + }, |
| 41 | + }, |
| 42 | + { |
| 43 | + name: 'convertTransform', |
| 44 | + params: { |
| 45 | + floatPrecision: 4, |
| 46 | + |
| 47 | + convertToShorts: false, |
| 48 | + matrixToTransform: false, |
| 49 | + shortTranslate: false, |
| 50 | + shortScale: false, |
| 51 | + shortRotate: false, |
| 52 | + removeUseless: false, |
| 53 | + collapseIntoOne: false, |
| 54 | + }, |
| 55 | + }, |
| 56 | + { |
| 57 | + name: 'cleanupNumericValues', |
| 58 | + params: { |
| 59 | + floatPrecision: 4, |
| 60 | + }, |
| 61 | + }, |
| 62 | + ], |
| 63 | + }).data; |
| 64 | +}; |
| 65 | + |
10 | 66 | // @ts-ignore |
11 | 67 | global.fetch = fetch; |
12 | 68 |
|
@@ -39,9 +95,7 @@ describe('integration', () => { |
39 | 95 | const container = canvas.getConfig().container as HTMLElement; |
40 | 96 | const dom = container.querySelector('svg'); |
41 | 97 |
|
42 | | - actual = format(xmlserializer.serializeToString(dom as any), { |
43 | | - parser: 'babel', |
44 | | - }); |
| 98 | + actual = format(dom as SVGElement); |
45 | 99 |
|
46 | 100 | // Remove ';' after format by babel. |
47 | 101 | if (actual !== 'null') actual = actual.slice(0, -2); |
|
0 commit comments