Skip to content

Commit

Permalink
Fix unit tests timing out
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Aug 30, 2023
1 parent b37a267 commit a5b5601
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Page.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Blob } from 'node:buffer';
import { beforeAll, describe, expect, it, vi } from 'vitest';
import React, { createRef } from 'react';
import { fireEvent, render } from '@testing-library/react';
Expand Down Expand Up @@ -351,6 +352,9 @@ describe('Page', () => {
});

it('requests page to be rendered with default rotation when given nothing', async () => {
const originalBlob = globalThis.Blob;
globalThis.Blob = Blob as unknown as typeof globalThis.Blob;

const { func: onRenderSuccess, promise: onRenderSuccessPromise } =
makeAsyncCallback<[PageCallback]>();

Expand All @@ -370,9 +374,14 @@ describe('Page', () => {
// Expect the SVG layer not to be rotated
expect(parseInt(width, 10)).toBe(Math.floor(viewport.width));
expect(parseInt(height, 10)).toBe(Math.floor(viewport.height));

globalThis.Blob = originalBlob;
});

it('requests page to be rendered with given rotation when given rotate prop', async () => {
const originalBlob = globalThis.Blob;
globalThis.Blob = Blob as unknown as typeof globalThis.Blob;

const { func: onRenderSuccess, promise: onRenderSuccessPromise } =
makeAsyncCallback<[PageCallback]>();
const rotate = 90;
Expand All @@ -393,6 +402,8 @@ describe('Page', () => {
// Expect the SVG layer to be rotated
expect(parseInt(width, 10)).toBe(Math.floor(viewport.width));
expect(parseInt(height, 10)).toBe(Math.floor(viewport.height));

globalThis.Blob = originalBlob;
});

it('requests page to be rendered in canvas mode by default', async () => {
Expand Down
6 changes: 6 additions & 0 deletions src/Page/PageSVG.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Blob } from 'node:buffer';
import { beforeAll, describe, expect, it } from 'vitest';
import React from 'react';
import { render } from '@testing-library/react';
Expand Down Expand Up @@ -45,6 +46,9 @@ describe('PageSVG', () => {

describe('loading', () => {
it('renders a page and calls onRenderSuccess callback properly', async () => {
const originalBlob = globalThis.Blob;
globalThis.Blob = Blob as unknown as typeof globalThis.Blob;

const { func: onRenderSuccess, promise: onRenderSuccessPromise } = makeAsyncCallback();

muteConsole();
Expand All @@ -60,6 +64,8 @@ describe('PageSVG', () => {
await expect(onRenderSuccessPromise).resolves.toMatchObject([{}]);

restoreConsole();

globalThis.Blob = originalBlob;
});

it('calls onRenderError when failed to render canvas', async () => {
Expand Down
11 changes: 11 additions & 0 deletions src/Thumbnail.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Blob } from 'node:buffer';
import { beforeAll, describe, expect, it, vi } from 'vitest';
import React, { createRef } from 'react';
import { fireEvent, render } from '@testing-library/react';
Expand Down Expand Up @@ -329,6 +330,9 @@ describe('Thumbnail', () => {
});

it('requests page to be rendered with default rotation when given nothing', async () => {
const originalBlob = globalThis.Blob;
globalThis.Blob = Blob as unknown as typeof globalThis.Blob;

const { func: onRenderSuccess, promise: onRenderSuccessPromise } =
makeAsyncCallback<[PageCallback]>();

Expand All @@ -348,9 +352,14 @@ describe('Thumbnail', () => {
// Expect the SVG layer not to be rotated
expect(parseInt(width, 10)).toBe(Math.floor(viewport.width));
expect(parseInt(height, 10)).toBe(Math.floor(viewport.height));

globalThis.Blob = originalBlob;
});

it('requests page to be rendered with given rotation when given rotate prop', async () => {
const originalBlob = globalThis.Blob;
globalThis.Blob = Blob as unknown as typeof globalThis.Blob;

const { func: onRenderSuccess, promise: onRenderSuccessPromise } =
makeAsyncCallback<[PageCallback]>();
const rotate = 90;
Expand All @@ -376,6 +385,8 @@ describe('Thumbnail', () => {
// Expect the SVG layer to be rotated
expect(parseInt(width, 10)).toBe(Math.floor(viewport.width));
expect(parseInt(height, 10)).toBe(Math.floor(viewport.height));

globalThis.Blob = originalBlob;
});

it('requests page to be rendered in canvas mode by default', async () => {
Expand Down

0 comments on commit a5b5601

Please sign in to comment.