|
1 |
| -import { promises as fs } from 'node:fs'; |
| 1 | +import fs from 'node:fs'; |
2 | 2 | import path from 'node:path';
|
3 |
| -import { pretty } from './pretty'; |
| 3 | +import { lenientParse, pretty, wrapText } from './pretty'; |
4 | 4 |
|
5 |
| -describe('pretty', () => { |
6 |
| - it("should prettify Preview component's complex characters correctly", async () => { |
7 |
| - const stripeHTML = await fs.readFile( |
8 |
| - path.resolve(__dirname, './stripe-email.html'), |
9 |
| - 'utf8', |
10 |
| - ); |
| 5 | +const stripeHTML = fs.readFileSync( |
| 6 | + path.resolve(__dirname, './stripe-email.html'), |
| 7 | + 'utf8', |
| 8 | +); |
11 | 9 |
|
12 |
| - expect(await pretty(stripeHTML)).toMatchSnapshot(); |
| 10 | +describe('lenientParse()', () => { |
| 11 | + it('should parse base doucment correctly', () => { |
| 12 | + const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body style="background-color:#fff;"><h1>whatever</h1><input placeholder="hello world"/></body></html>`; |
| 13 | + expect(lenientParse(document)).toMatchSnapshot(); |
13 | 14 | });
|
| 15 | +}); |
14 | 16 |
|
15 |
| - test('if mso syntax does not wrap', async () => { |
16 |
| - expect( |
17 |
| - await pretty( |
18 |
| - `<span><!--[if mso]><i style="mso-font-width:100%;mso-text-raise:12" hidden>  </i><![endif]--></span>`, |
19 |
| - ), |
20 |
| - ).toMatchSnapshot(); |
| 17 | +describe('pretty', () => { |
| 18 | + it('should prettify base doucment correctly', () => { |
| 19 | + const document = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head></head><body style="background-color:#fff;"><h1>whatever</h1><input placeholder="hello world"/></body></html>`; |
| 20 | + expect(pretty(document, { lineBreak: '\n' })).toBe(''); |
21 | 21 | });
|
| 22 | + |
| 23 | + // it("should prettify Preview component's complex characters correctly", async () => { |
| 24 | + // const stripeHTML = await fs.readFile( |
| 25 | + // path.resolve(__dirname, './stripe-email.html'), |
| 26 | + // 'utf8', |
| 27 | + // ); |
| 28 | + // |
| 29 | + // expect(await pretty(stripeHTML)).toMatchSnapshot(); |
| 30 | + // }); |
| 31 | + // |
| 32 | + // test('if mso syntax does not wrap', async () => { |
| 33 | + // expect( |
| 34 | + // await pretty( |
| 35 | + // `<span><!--[if mso]><i style="mso-font-width:100%;mso-text-raise:12" hidden>  </i><![endif]--></span>`, |
| 36 | + // ), |
| 37 | + // ).toMatchSnapshot(); |
| 38 | + // }); |
| 39 | +}); |
| 40 | + |
| 41 | +test('wrapText()', () => { |
| 42 | + expect( |
| 43 | + wrapText( |
| 44 | + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum tristique.', |
| 45 | + '', |
| 46 | + 10, |
| 47 | + '\n', |
| 48 | + ), |
| 49 | + ).toMatchSnapshot(); |
| 50 | + expect( |
| 51 | + wrapText( |
| 52 | + 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis laoreet tortor in orci ultricies, at fermentum nisl aliquam. Mauris ornare ut eros non vulputate. Aliquam quam massa, sagittis et nunc at, tincidunt vestibulum justo. Sed semper lectus a urna finibus congue. Aliquam erat volutpat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin molestie enim sed mauris ultrices interdum.', |
| 53 | + ' ', |
| 54 | + 78, |
| 55 | + '\n', |
| 56 | + ), |
| 57 | + ).toMatchSnapshot(); |
22 | 58 | });
|
0 commit comments