]> BookStack Code Mirror - bookstack/blob - resources/js/wysiwyg/lexical/list/__tests__/utils.ts
aa95a7a01b080790579665254e74b76d0b389ad5
[bookstack] / resources / js / wysiwyg / lexical / list / __tests__ / utils.ts
1 /**
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  *
7  */
8 import {expect} from '@playwright/test';
9 import prettier from 'prettier';
10
11 // This tag function is just used to trigger prettier auto-formatting.
12 // (https://prettier.io/blog/2020/08/24/2.1.0.html#api)
13 export function html(
14   partials: TemplateStringsArray,
15   ...params: string[]
16 ): string {
17   let output = '';
18   for (let i = 0; i < partials.length; i++) {
19     output += partials[i];
20     if (i < partials.length - 1) {
21       output += params[i];
22     }
23   }
24   return output;
25 }
26
27 export function expectHtmlToBeEqual(expected: string, actual: string): void {
28   expect(prettifyHtml(expected)).toBe(prettifyHtml(actual));
29 }
30
31 export function prettifyHtml(s: string): string {
32   return prettier.format(s.replace(/\n/g, ''), {parser: 'html'});
33 }