Skip to content

Commit

Permalink
test: Use vitest file snapshot feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
jheer committed Dec 16, 2024
1 parent 692b520 commit d110266
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/vgplot/test/render.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { beforeEach, afterEach, expect, describe, it } from 'vitest';
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { Coordinator } from '@uwdata/mosaic-core';
import { JSDOM } from 'jsdom';
Expand All @@ -15,6 +14,7 @@ beforeEach(() => {
{ pretendToBeVisual: true }
);

// assign browser environment globals
globalThis.window = dom.window;
globalThis.document = dom.window.document;
globalThis.navigator ??= dom.window.navigator;
Expand Down Expand Up @@ -46,13 +46,9 @@ describe('render', () => {
async function renderTest(name) {
const specPath = resolve(cwd, `specs/${name}.js`);
const htmlPath = resolve(cwd, `output/${name}.html`);
const [expected, { default: run }] = await Promise.all([
readFile(htmlPath, { encoding: 'utf8' }),
import(specPath)
]);
const { default: run } = await import(specPath);
const mc = new Coordinator(nodeConnector(), { logger: null });
const el = await run(createAPIContext({ coordinator: mc }));

await clientsReady(el);
expect(el.outerHTML).toEqual(expected);
await expect(el.outerHTML).toMatchFileSnapshot(htmlPath);
}

0 comments on commit d110266

Please sign in to comment.