Closed devleejb closed 2 weeks ago
Could I work on this issue?
@having-dlrow Sure! This seems to be a good issue to understand CodePair's CI!
Add tests for backend failed.
1.Build
was successful.2.Test
failed due to missing environment variables.
Build
- name: Run build
run: npm run build
working-directory: ${{ env.working-directory }}
Test
- name: Run test
run: npm run test
2-1. Test Fail Log
Test Suites: 20 failed, 20 total
Tests: 20 failed, 20 total
Snapshots: 0 total
Time: 8.534 s
Ran all test suites.
22 afterEach(async () => {
→ 23 const deleteWorkspaces = prismaService.workspace.deleteMany(
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:10
|
9 | provider = "mongodb"
10 | url = env("DATABASE_URL")
|
Validation Error Count: 1
For more detailed error information, please refer to https://github.com/having-dlrow/codepair/actions/runs/10114844891.
Using an in-memory database when in a Node.js CI environment.
// Example
const Datastore = require('nedb');
const mongoose = require('mongoose');
let db;
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'ci') {
// NeDB setup
db = new Datastore({ filename: 'datafile', autoload: true });
} else {
// MongoDB setup
mongoose.connect(process.env.DATABASE_URL, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log('Connected to MongoDB');
});
}
module.exports = db;
Installing MongoDB instance on the runner
jobs:
test:
name: Check the source code
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
options: >-
--health-cmd "mongo --eval 'db.runCommand({ ping: 1 })'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
matrix:
node-version: [18.x]
env:
working-directory: ./backend
DATABASE_URL: mongodb://localhost:27017/testdb
Providing a CI environment (MongoDB) and an env.ci file
Using GitHub secrets to inject values. However, a MongoDB connection endpoint is required for the CI environment.
# Method of replacing keys
- name: Replace environment variables in .env.development
run: |
sed -i 's/^DATABASE_URL=.*/DATABASE_URL=${{ secrets.DATABASE_URL }}/g' .env.development
sed -i 's/^OPENAI_API_KEY=.*/OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}/g' .env.development
# Method of replacing files
- name: Make .env.development
run: |
touch .env.development
echo "${{ secrets.env }}" >> .env.development
shell: bash
if anyone has other solutions or opinions, I would be grateful to hear them. @devleejb
@having-dlrow It seems that we need to discuss the test environment. I think it is out of scope.
How about we only add build test to this issue and create a new issue for the test environment? (If you are interested in the new issue, would you enroll the issue? I like your approaches.)
I also have a idea.
I think we can handle the test environment using docker. In yorkie
, docker container runs for using mongodb.
@having-dlrow Could you share your progress?
What would you like to be added: Currently, our CI setup using GitHub Actions does not include build tests for both Frontend and Backend applications, making it difficult to determine if the build is successful or not.
To improve the CI pipeline, it is recommended to add build tests for both the Frontend and Backend applications. This will allow us to validate the build process and catch any potential errors early on.
Why is this needed: Adding build tests for both the Frontend and Backend applications in our CI pipeline will help ensure the stability and quality of our codebase. It will provide a more comprehensive testing environment and help prevent issues from being deployed to production.