Skip to content

Commit 740a4a5

Browse files
committed
chore: configure Jest ESM and fix CI/CD pipeline
- Configured --experimental-vm-modules for native ESM support. - Added mocks for isomorphic-dompurify and nodemailer. - Fixed database connection issues in tests using dotenv/config. - Updated GitHub Actions workflow and cleaned up jest.config.js.
1 parent 078816d commit 740a4a5

File tree

8 files changed

+2288
-632
lines changed

8 files changed

+2288
-632
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
pull_request:
77
branches: [ main, master ]
88

9-
# Esto le dice a GitHub que entre a la carpeta email-api para ejecutar todo
109
defaults:
1110
run:
1211
working-directory: email-api
@@ -38,18 +37,20 @@ jobs:
3837
with:
3938
node-version: '20'
4039
cache: 'npm'
41-
# Aquí también ajustamos la ruta del lock file
4240
cache-dependency-path: email-api/package-lock.json
4341

4442
- name: Install dependencies
45-
run: npm install
46-
#run: npm ci
43+
# 'npm ci' es más rápido y seguro en pipelines que 'npm install'
44+
run: npm ci
4745

4846
- name: Run Tests
4947
env:
48+
# Inyectamos la URL de la base de datos del servicio de arriba
5049
DATABASE_URL: postgres://user_test:password_test@localhost:5432/auth_mailer_test
51-
SECRET_KEY: ${{ secrets.SECRET_KEY }}
50+
SECRET_KEY: ${{ secrets.SECRET_KEY || 'test_secret_key' }}
5251
GOOGLE_APP_PASSWORD: ${{ secrets.GOOGLE_APP_PASSWORD }}
5352
EMAIL: ${{ secrets.EMAIL }}
5453
NODE_ENV: test
55-
run: npm test
54+
# Forzamos que Node reconozca los módulos experimentales en el pipeline
55+
NODE_OPTIONS: "--experimental-vm-modules"
56+
run: npm test

email-api/.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "current"
8+
},
9+
"modules": "auto"
10+
}
11+
]
12+
]
13+
}

email-api/jest.config.js

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,7 @@
1-
/*import 'dotenv/config';
2-
3-
export default {
4-
testEnvironment: 'node',
5-
transform: {
6-
"^.+\\.(t|j)sx?$": "@swc/jest",
7-
},
8-
moduleNameMapper: {
9-
'^(\\.{1,2}/.*)\\.js$': '$1',
10-
},
11-
};*/
12-
131
import 'dotenv/config';
142

153
export default {
164
testEnvironment: 'node',
17-
transform: {
18-
"^.+\\.jsx?$": ["@swc/jest", {
19-
jsc: {
20-
parser: {
21-
syntax: "ecmascript",
22-
jsx: true,
23-
},
24-
transform: {},
25-
},
26-
}],
27-
},
28-
moduleNameMapper: {
29-
'^(\\.{1,2}/.*)\\.js$': '$1',
30-
},
5+
// Esto asegura que las variables se carguen antes de cada test
6+
setupFiles: ['dotenv/config']
317
};

0 commit comments

Comments
 (0)