Home > database >  Jest Test Suite Failed after adding the firebase-admin
Jest Test Suite Failed after adding the firebase-admin

Time:01-26

I added a firebase-admin in the NestJS Project, the unit test pass in the local code but fails in the CI/CD Pipeline.

Test suite failed to run
    Jest encountered an unexpected token
    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
    Here's what you can do:
     • 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/en/configuration.html
    Details:
    /opt/atlassian/pipelines/agent/build/node_modules/firebase-admin/lib/app/firebase-namespace.js:84
            this.INTERNAL = new FirebaseNamespaceInternals(appStore ?? new lifecycle_1.AppStore());
                                                                     ^
    SyntaxError: Unexpected token '?'
        at compileFunction (<anonymous>)
      at Runtime._execModule (../node_modules/jest-runtime/build/index.js:1157:58)
      at Object.<anonymous> (../node_modules/firebase-admin/lib/default-namespace.js:19:30)
      at Object.<anonymous> (../node_modules/firebase-admin/lib/index.js:19:18)

All the tests passed locally from VS Code

enter image description here

I tried adding the testPathIgnorePatterns and other settings provided on the web. Didn't work.

CodePudding user response:

The Nullish Coalescing Operator (??) was introduced to Node in version 14. Update your CI/CD pipeline to be a newer version of Node. The current version is 18 and I believe 12 is no longer LTS so upgrading is definitely something to look into.

  • Related