Skip to content

Prisma Adapter is conflicting with Jest #12768

Open
@orpheus6678

Description

@orpheus6678

Adapter type

@auth/prisma-adapter

Environment

  System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz
    Memory: 510.52 MB / 3.90 GB
  Binaries:
    Node: 22.12.0 - C:\Program Files\nodejs\node.EXE
    pnpm: 9.15.2 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.105)
  npmPackages:
    @auth/prisma-adapter: ^2.7.4 => 2.7.4 
    next: 15.1.3 => 15.1.3 
    next-auth: 5.0.0-beta.25 => 5.0.0-beta.25 
    react: ^19.0.0 => 19.0.0 

Reproduction URL

https://github.com/Learnathon-By-Geeky-Solutions/convicts/tree/rf/bug-swc

Describe the issue

Jest is crashing on reaching prisma adapter code because it uses ES2020 syntax. I know transpilers skip node_modules transpilation by default, and I have not added transformIgnorePatterns on jest.config.js. But I shouldnt have to. I have used next/jest instead which automatically configures jest, and I have transpilePackages: ["@auth/prisma-adapter"] in my next.config.ts (please check out the source). Despite all, jest yields the following on every run. It may be worth noting that next uses swc compiler (and thus @swc/jest) by default instead of babel. I would also like to report this regex execution as an extra.


> [email protected] test E:\convicts
> jest --ci

FAIL src/__tests__/login.test.tsx
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    E:\convicts\node_modules\.pnpm\@[email protected]_@[email protected][email protected][email protected][email protected][email protected]\node_modules\@auth\prisma-adapter\index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export function PrismaAdapter(prisma) {
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      27 |   //         async create({ args, query }) {
      28 |   //           args.data.username ??= `!${createId()}`
    > 29 |   //           return query(args)
         |                        ^
      30 |   //         },
      31 |   //       },
      32 |   //     },

      at Runtime.createScriptFromCode (node_modules/.pnpm/[email protected]/node_modules/jest-runtime/build/index.js:1505:14)
      at Object.<anonymous> (src/lib/auth.ts:29:24)
      at Object.<anonymous> (src/app/login/page.tsx:13:15)
      at Object.<anonymous> (src/__tests__/login.test.tsx:8:54)

(node:15040) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
(node:3248) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
PASS src/__tests__/snapshot.tsx
(node:14976) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
PASS src/__tests__/page.test.tsx

Test Suites: 1 failed, 2 passed, 3 total
Tests:       12 passed, 12 total
Snapshots:   1 passed, 1 total
Time:        8.721 s
Ran all test suites.
 ELIFECYCLE  Test failed. See above for more details.

How to reproduce

Just run pnpm test in the terminal.

Expected behavior

All tests pass without fail. Or at least, jest should not report this exact error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    adaptersChanges related to the core code concerning database adaptersbugSomething isn't workingtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions