langchain-ai / langgraphjs

Build resilient language agents as graphs.
https://langchain-ai.github.io/langgraphjs/
MIT License
667 stars 105 forks source link

Jest to test custom checkpoint saver #500

Open gnaryak opened 2 months ago

gnaryak commented 2 months ago

Hi - I am writing a custom checkpoint saver to save checkpoints to session storage or local storage in the browser. I would like to write tests in Jest as I develop it, but when I run jest, it tells me:

/Users/me/gh/my-project/node_modules/@langchain/langgraph/web.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export * from './dist/web.js'
                                                                                      ^^^^^^
    SyntaxError: Unexpected token 'export'

      1 | import type { RunnableConfig } from "@langchain/core/runnables";
    > 2 | import { BaseCheckpointSaver } from "@langchain/langgraph/web";

I am able to write a test outside of jest using Typescript with assert statements, and running it with tsx.

I would prefer to include this test with our suite of Jest tests, and to be able to use Jest.

Any suggestions for being able to test my custom checkpoint saver with Jest?

Also, any advice about creating a checkpoint saver that uses session storage or local storage? I am using the SqliteSaver as a guide.

Thanks!

jacoblee93 commented 2 months ago

Hey @gnaryak! Is your local project in CJS or ESM?

Does it work if you switch from one to the other?

gnaryak commented 2 months ago

Hi @jacoblee93 - ESM. I can't really switch the project. We are committed to ESM. Thanks.