I think this may be a common problem but couldn't ...
# help
a
I think this may be a common problem but couldn't find any information on this: Currently running into issues with Jest and external dependencies, wondering if this was documented somewhere on how to overcome it
r
I had this very same problem today after upgrading the file-type dependency and couldn't quickly find a way around it.
t
@Ash Rhazaly can I see your jest config?
a
Sure
Copy code
"jest": {
    "collectCoverageFrom": [
      "src/**/*.ts",
      "test/**/*.ts",
      "!**/node_modules/**"
    ],
    "coverageReporters": [
      "html",
      "text",
      "text-summary",
      "cobertura"
    ],
    "setupFilesAfterEnv": [
      "./src/jest-test-setup.js"
    ],
    "testMatch": [
      "**/*.test.ts"
    ]
  }
t
is there a reason you added your own config instead of using the default?
a
jest-test-setup.js
Copy code
jest.mock("./config", () => {
  return {
    ...jest.requireActual("./config"),
    log: jest.fn(),
  };
});

jest.mock("./common", () => {
  return {
    ...jest.requireActual("./common"),
  };
});
t
this needs settings to compile the typescript tests
And I'd recommend calling jest directly instead of going through sst
a
Ah okay noted
Still getting the similar error output am I missing anything else?
Copy code
module.exports = {
  collectCoverageFrom: ["src/**/*.ts", "test/**/*.ts", "!**/node_modules/**"],
  coverageReporters: ["html", "text", "text-summary", "cobertura"],
  setupFilesAfterEnv: ["./src/jest-test-setup.js"],
  testMatch: ["**/*.*test.(ts|tsx|js)"],
  transform: {
    "\\.ts$": "esbuild-runner/jest",
  },
};
t
did you install
esbuild-runner
? I'm not too sure because if you're calling jest directly SST isn't involved in the process
a
Yup just did, still running into the same output, I tried both methods of invoking jest directly and through SST the error output remains the same
t
Can you follow the instructions in the error message?
It seems you're importing esm middy code that isn't working in the current jest env
r
My next port of call when I get back to investigating this was using ts-jest@next https://kulshekhar.github.io/ts-jest/docs/next/guides/esm-support/
Probably a red herring as the next version is behind the current version, but noticed the useESM: true option which I'll try soon
a
Yeah this is still bugging me and I'm tempted to just forgo the tests for now
I'll try different jest configurations to get this working
found the problem, seems that the latest version tags for
@middy/core
are causing it, rollback to the last stable version and it'll work fine
^3.0.0-alpha.5
was causing the errors
r
Yeah, unfortunately for me, the
file-type
dependency has a major version update that causes this. They moved to pure ESM
t
I'm sorta running into this problem as well in an unrelated way. In the new gql starter we're wokrin gon we're using pure ESM and I just got around to setting up jest and it hasn't been straightfoward
r
Interesting, what I haven't gotten my head around is how to reliably have a mixed code base where some is ESM and some CommonJS