Jest not recognizing Yarn workspace module in CircleCI - jestjs

My tests run fine locally, but in CircleCI I get this error “Cannot find module ‘shared-data-model’” which is one of my Yarn workspaces.
The stack trace of the error points to Resolver.resolveModule (../node_modules/#jest/core/node_modules/jest-resolve/build/index.js:276:11)
I am running
Jest 25.1.0,
Yarn 1.22,
Node.js 12.16
Any ideas what could be causing this? Thank you

I figured out the problem. I am using typescript CLI tsc to transpile my module from /src to /dist, and I wasn't running the transpile step on CI to generate the /dist folder, so when it tried to find the entrypoint of the module dist/index.js there was nothing there. Once I ran the build tsc step in CI it worked as expected.

Related

Circular errors about babel-loader when launching React app

When I run yarn dev I get the error that:
ERROR in Entry module not found: Error: Can't resolve 'babel-loader' in...
Following this answer, I manually installed balel loader as a dev dependency. But then when I run yarn dev I get this:
I go through those 4 steps, then run yarn dev again, and I get the first error again.
Anyone know what's going? Why isn't babel-loader being auto-installed as a dependency? (I checked in /node_modules and it's not there.)
Thanks very much in advance.

Heroku : Cannot find module 'pg'?

I tried deploying on heroku and had error
So the file structure would be:
/app
----app.js
----node_modules/
It is also necessary to move pg from devDependencies into Dependencies and run npm run build.

typescript runs strange on heroku

I have a typescript project and want my running code to get generated by heroku when I deploy. I therefore added "postinstall": "tsc" to package.json so that tsc would be run on heroku after npm install is complete (I do have typescript in my dependencies).
It does run, but for some reason, tsc crashes with RangeError: Maximum call stack size exceeded on an obscure file .heroku/node/lib/node_modules/npm/node_modules/slide/lib/async-map-ordered.js which it shouldn't be running on at all. This setup works perfectly on my machine, on Circle.ci, and on a freshly cloned repo.
I had a theory that maybe tsc was being run in the wrong directory, but when I used pwd && ls && tsc It printed the correct directory (/tmp/build_5292b1b9c3c13c35489f46510acb565e) and the files that are in my directory.
My question is: Why is tsc running in this strange way on heroku, and what do I have to do to make typescript work on a heroku deployment?

AVA test setup: "Unexpected token export"

Problem
I'm trying to add AVA tests to a project and my tests are not parsing ES2015 modules correctly with my Babel setup. What is odd to me is the imports are working fine and if I run my npm run build and run the output from the REPL it works...so it seems that AVA is not transpiling export statements correctly or something is wrong with my config in my package.json? I've tried reading through the docs and looking at other examples without success.
Steps to reproduce
Clone https://github.com/trevordmiller/utility-functions
checkout the tests branch
npm install
npm test
Get an error (screenshot below) - ES2015 module export error on line 7 of getURLSlug:
Add "require": ["babel-register"] to the AVA configuration in your package.json

How to run Jest tests on Jenkins Server

I'm attempting to run my Jest Test during Jenkins deployment. If I ssh into the server, I can sudo into the Jenkins user and successfully run the tests from the workspace. However, I get an error when I attempt to build the project from the GUI. Here is my project setup:
I have installed the nodejs plugin, which in turn installs gulp, jest-cli and babel globally.
Then in build steps:
The test fails with this error:
TypeError: Cannot read property 'getResourceByPath' of null
at Loader.getDependenciesFromPath (/var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:570:39)
at /var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/TestRunner.js:250:22
at process._tickCallback (node.js:368:9)
Running 6 test suites...
FAIL resources/__tests__/myTest.js
It appears that Node is having trouble requiring modules from the tests, but I'm not totally sure. Any help or direction would be appreciated.

Resources