FluidFramework
FluidFramework copied to clipboard
Unit test failing with Jest 28 for packages depending on `@fluid-experimental/property-dds`
Describe the bug
We have packages that rely on @fluid-experimental/property-dds
. After upgrading jest to version 28 tests that refers to the package would fail with the following:
Jest encountered an unexpected token
[...]
Details:
C:\Users\weiwei\code\dp\node_modules\msgpackr\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { Packr, Encoder, addExtension, pack, encode, NEVER, ALWAYS, DECIMAL_ROUND, DECIMAL_FIT, REUSE_BUFFER_MODE } from './pack.js' ^^^^^^
SyntaxError: Unexpected token 'export'
at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
at Object.<anonymous> (node_modules/@fluid-experimental/property-dds/src/propertyTree.ts:11:1)
Changing jest testEnvironment
to node passes the test, but unfortunately we do need jsdom
for the app.
To Reproduce
I have created a minimal repo to demonstrate the failure.
Steps to reproduce the behavior:
- Go to https://github.com/weiwei/fluidtest. Clone the demo repo.
- Run
npm install
andnpm test
in both themain
branch(jest 28) andjest27
branch. - See the test result.
Expected behavior
Test should pass on jest 28.
Logs
Do you need to use Jest 28? Or is 27 sufficient for your needs?
@tylerbutler The issue seems to be with two of the dependencies of property-dds: msgpackr & uuid, which seems to configure exports
incorrectly.
Following a similar solution to the one posted in this article fixes the issue:
export default {
testEnvironment: "jsdom",
preset: "ts-jest",
moduleNameMapper: {
'^msgpackr': require.resolve('msgpackr'),
'^uuid$': require.resolve('uuid')
},
};
This PR has been automatically marked as stale because it has had no activity for 60 days. It will be closed if no further activity occurs within 8 days of this comment. Thank you for your contributions to Fluid Framework!