question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues using React components in test environment

See original GitHub issue

We’ve recently replaced our hand-rolled components with the ones provided by our toolkit. All works well when running the extension normally, but we get the following exception when running our tests:

/Users/dee/Programming/work/nordic/vscode-nrf-connect/node_modules/@vscode/webview-ui-toolkit/react/index.js:3
import { provideReactWrapper } from '@microsoft/fast-react-wrapper';
^^^^^^

SyntaxError: Cannot use import statement outside a module

This is being hit when our test imports the React component that makes use of the toolkit components. For context, our source code and tests are compiled using tsc -p ., and are run through the runTests utility provided by @vscode/test-electron. This means there’s no bundling stage involved, which I guess is why we’re not seeing this when the extension is running normally.

Is it possible that there’s something misconfigured in the library, i.e. a missing "type": "module" in the package.json file?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
deerob4commented, Oct 13, 2022

Hey, thanks for looking into this!

Our extension isn’t open source unfortunately, but I created a minimal example that reproduces the issue. It implements a simple counter webview that uses the VSCodeButton component, as well as a couple of tests, and includes a rough approximation of our test environment. I hope it’s useful!

1reaction
hawkticehurstcommented, Sep 26, 2022

Thanks for the bug report @deerob4!

Been a bit busy with other pressing work lately but will put it on the top of my todo list once I have some free cycles

Also thank you so much for the call out of a missing "type": "module"! I thought that was something I included long ago, but adding it might be a solution to some other problems I’ve been tackling with the toolkit

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Environments - React
In an environment where you can't simulate a DOM (e.g. testing React Native components on Node.js), you could use event simulation helpers to...
Read more >
Unit Testing Behavior of React Components with Test-Driven ...
The internet is full of excellent examples of how to unit test React components that have purely presentational concerns. This is fairly easy...
Read more >
The current testing environment is not configured to support ...
I noticed this after switching from jest to vitest, and not changing anything else.
Read more >
A Practical Guide to Testing React Applications ... - LambdaTest
This article on React Testing explores different methods of testing React components and also dive into some advanced testing principles and ...
Read more >
How to Test React Components: the Complete Guide
I will first show you the React component and then the tests for it, with detailed explanations of each. You can also follow...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found