|
| 1 | +import { it, describe, expect } from 'vitest' |
| 2 | + |
| 3 | +import { initFonts, toImage } from './utils.js' |
| 4 | +import satori from '../src/index.js' |
| 5 | + |
| 6 | +describe('webkit-text-stroke', () => { |
| 7 | + let fonts |
| 8 | + initFonts((f) => (fonts = f)) |
| 9 | + |
| 10 | + it('should work basic text stroke', async () => { |
| 11 | + const svg = await satori( |
| 12 | + <div |
| 13 | + style={{ |
| 14 | + width: 100, |
| 15 | + height: 100, |
| 16 | + fontSize: 30, |
| 17 | + background: '#ebebeb', |
| 18 | + color: '#ffffff', |
| 19 | + WebkitTextStroke: '4px #000000', |
| 20 | + }} |
| 21 | + > |
| 22 | + Hello, world |
| 23 | + </div>, |
| 24 | + { width: 100, height: 100, fonts } |
| 25 | + ) |
| 26 | + expect(toImage(svg, 100)).toMatchImageSnapshot() |
| 27 | + }) |
| 28 | + |
| 29 | + it('should work nested text stroke', async () => { |
| 30 | + const svg = await satori( |
| 31 | + <div |
| 32 | + style={{ |
| 33 | + display: 'flex', |
| 34 | + flexWrap: 'wrap', |
| 35 | + width: 100, |
| 36 | + height: 100, |
| 37 | + fontSize: 30, |
| 38 | + background: '#ebebeb', |
| 39 | + color: '#ffffff', |
| 40 | + WebkitTextStroke: '4px #000000', |
| 41 | + }} |
| 42 | + > |
| 43 | + Hello, <span style={{ WebkitTextStrokeColor: '#ff0000' }}>world</span> |
| 44 | + </div>, |
| 45 | + { width: 100, height: 100, fonts } |
| 46 | + ) |
| 47 | + expect(toImage(svg, 100)).toMatchImageSnapshot() |
| 48 | + }) |
| 49 | + |
| 50 | + it('should work nested and complex text stroke', async () => { |
| 51 | + const svg = await satori( |
| 52 | + <div |
| 53 | + style={{ |
| 54 | + display: 'flex', |
| 55 | + flexWrap: 'wrap', |
| 56 | + width: 100, |
| 57 | + height: 100, |
| 58 | + fontSize: 30, |
| 59 | + background: '#ebebeb', |
| 60 | + color: '#ffffff', |
| 61 | + WebkitTextStroke: '4px #000000', |
| 62 | + }} |
| 63 | + > |
| 64 | + Hello, |
| 65 | + <span style={{ WebkitTextStrokeColor: '#f00' }}>w</span> |
| 66 | + <span style={{ WebkitTextStrokeColor: '#ff0' }}>o</span> |
| 67 | + <span style={{ WebkitTextStrokeColor: '#0f0' }}>r</span> |
| 68 | + <span style={{ WebkitTextStrokeColor: '#0ff' }}>l</span> |
| 69 | + <span style={{ WebkitTextStrokeColor: '#00f' }}>d</span> |
| 70 | + <span |
| 71 | + style={{ |
| 72 | + WebkitTextStrokeColor: '#f0f', |
| 73 | + WebkitTextStrokeWidth: '6px', |
| 74 | + }} |
| 75 | + > |
| 76 | + ! |
| 77 | + </span> |
| 78 | + </div>, |
| 79 | + { width: 100, height: 100, fonts } |
| 80 | + ) |
| 81 | + expect(toImage(svg, 100)).toMatchImageSnapshot() |
| 82 | + }) |
| 83 | +}) |
0 commit comments