Skip to content

Commit

Permalink
Convert one test over to happy-dom as unlike JSDOM, that can access s…
Browse files Browse the repository at this point in the history
…tyle.sheet
  • Loading branch information
eoghanmurray committed Aug 2, 2024
1 parent 63d79fb commit 9770a16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"eslint-plugin-compat": "^5.0.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-tsdoc": "^0.2.17",
"happy-dom": "^14.12.0",
"markdownlint": "^0.25.1",
"markdownlint-cli": "^0.31.1",
"prettier": "2.8.4",
Expand Down
1 change: 0 additions & 1 deletion packages/rrdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"eslint": "^8.15.0",
"happy-dom": "^14.12.0",
"puppeteer": "^17.1.3",
"typescript": "^5.4.5",
"vite": "^5.3.1",
Expand Down
13 changes: 8 additions & 5 deletions packages/rrweb-snapshot/test/css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type BuildCache,
type textNode,
} from '../src/types';
import { Window } from 'happy-dom';

describe('css parser', () => {
function parse(plugin: AcceptedPlugin, input: string): string {
Expand Down Expand Up @@ -88,20 +89,21 @@ li[attr="has,comma"] a.\\:hover {background: red;}`,

describe('css splitter', () => {
it('finds css textElement splits correctly', () => {
const style = JSDOM.fragment(`<style></style>`).querySelector('style');
const window = new Window({ url: 'https://localhost:8080' });
const document = window.document;
document.head.innerHTML = '<style>.a{background-color:red;}</style>';
const style = document.querySelector('style');
if (style) {
// as authored, e.g. no spaces
style.appendChild(JSDOM.fragment('.a{background-color:red;}'));
style.appendChild(JSDOM.fragment('.a{background-color:black;}'));
style.append('.a{background-color:black;}');

// how it is currently stringified (spaces present)
const expected = [
'.a { background-color: red; }',
'.a { background-color: black; }',
];
const browserSheet = expected.join('');
// can't do this as JSDOM doesn't have style.sheet
//expect(stringifyStylesheet(style.sheet!)).toEqual(browserSheet);
expect(stringifyStylesheet(style.sheet!)).toEqual(browserSheet);

expect(splitCssText(browserSheet, style)).toEqual(expected);
}
Expand Down Expand Up @@ -133,6 +135,7 @@ describe('css splitter', () => {
const browserSheet = expected.join('');

// can't do this as JSDOM doesn't have style.sheet
// also happy-dom doesn't strip out vendor-prefixed rules like a real browser does
//expect(stringifyStylesheet(style.sheet!)).toEqual(browserSheet);

expect(splitCssText(browserSheet, style)).toEqual(expected);
Expand Down

0 comments on commit 9770a16

Please sign in to comment.