As a newcomer to setting up GitLab CI, I am currently venturing into implementing a small web application using the MERN pipeline (MongoDB, express, react, Nodejs). My goal is to create a simple project akin to google drive where users can store and manage their files online. Here's the breakdown of my project structure:
So far, I have configured unit tests for the backend using Jest and super test. I've installed all necessary packages and set up jest.config.ts for compiling typescript tests. However, I encountered an issue where the test file couldn't detect my installed jest if I only performed npm install for required packages in the backend folder. To address this, I ended up installing all required packages for testing in both the root folder and the backend folder. Below are the packages used:
cloud_todo/package.json:
{
"dependencies": {
"supertest": "^6.3.3"
},
"devDependencies": {
"@babel/core": "^7.22.1",
...
}
cloud_todo/backend/package.json:
{
"name": "backend",
"version": "1.0.0",
...
}
cloud_todo/backend/jest.config.ts:
/*
* For a detailed explanation regarding each configuration property...
*/
export default {
coverageProvider: "v8",
...
};
With the backend unit tests functioning well locally, I proceeded to set up a GitLab CI/CD pipeline with the following yml file:
cloud_todo/.gitlab-ci.yml
image: node:latest
stages:
- npm
- test
npm:
stage: npm
...
}
test:
stage: test
...
Despite these efforts, my pipeline kept throwing the same error message:
$ cd backend
$ npm test
...
Error: Cannot find package 'ts-node' imported from ...
Cleaning up project directory and file based variables...
ERROR: Job failed: exit code 1
I tried multiple solutions like installing ts-node in the script and changing docker images, but none worked. I also experimented with various tips found online, but they didn't provide a solution specific to my project.