Closed justin-mellor closed 1 month ago
There are probably some packaging issues and NodeJs cannot import botframework-webchat
.
For example, use-ref-from
's exports["."].import.default
is broken https://publint.dev/use-ref-from@0.1.0 and this is the error on NodeJs:
// repro.mjs
import "use-ref-from"
// $ node repro.mjs
// /home/hiroshi/code/tmp/vitest-botframework-webchat/node_modules/.pnpm/use-ref-from@0.1.0_react@18.3.1/node_modules/use-ref-from/lib/esmodules/index.js:1
// import useRefFrom from './useRefFrom';
// ^^^^^^
// SyntaxError: Cannot use import statement outside a module
// at wrapSafe (node:internal/modules/cjs/loader:1378:20)
To workaround this on Vitest, you can probably tweak test.server.deps.inline
, but it'll probably require adding all the dependency chains till use-ref-from
, meaning every dependencies appearing in pnpm why
like this:
$ pnpm why use-ref-from
dependencies:
botframework-webchat 4.18.0
├─┬ botframework-webchat-api 4.18.0
│ └── use-ref-from 0.1.0
└─┬ botframework-webchat-component 4.18.0
├─┬ botframework-webchat-api 4.18.0
│ └── use-ref-from 0.1.0
├─┬ use-propagate 0.1.0
│ └── use-ref-from 0.0.3
└── use-ref-from 0.1.0
I fiddled with test.server.deps.inline
and test.deps.optimizer
, but it looks like either ends up with some issues due to internal dependencies.
If you don't need to unit-test botframework-webchat
by yourself, then the simplest workaround would be to just mock this dependency like vi.mock('botframework-webchat', () => ({ renderWebChat: vi.fn() }))
.
@hi-ogawa thanks for the suggestion. Mocking the call is perfect as I don't want to test the component itself.
Describe the bug
If you import botframework-webchat you get an error when you run vitest.
Have tried using deps options to try and get it to work, but can't seem to get anything to work Initially raised this against botframework-webchat, but think this is actually a problem with vitest https://github.com/microsoft/BotFramework-WebChat/issues/5011
Reproduction
See https://github.com/justin-mellor/vitest-botframework-webchat
This is a simple vue site build using create-vue that I have modified to include botframework-webchat in the HelloWorld component
If you run
npm run build
it all builds fine but if you runnpm run test:unit
you get the errorSystem Info
Used Package Manager
npm
Validations