Skip to content

How to setup worker in unit test in Create-React-App? #729

Description

@ed-sparkes

What are you trying to achieve? Please describe.

Run a test that loads a pdf from local file in a CRA app.

Describe solutions you've tried

I have tried putting the following at the top of my unit test file

import { pdfjs } from 'react-pdf';
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.js`;

but i get the following error

setting up fake worker failed: "Cannot find module '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.5.207/pdf.worker.min.js' from '../../node_modules/pdfjs-dist/build/pdf.js'".

Environment

"react-scripts": "^4.0.1",
"react-pdf": "^5.1.0",
"react": "^17.0.1",

Metadata

Metadata

Assignees

Labels

questionFurther information is requestedstale

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions