Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration jest => vitest WIP #4806

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports = {
env: {
node: true,
es2021: true,
jest: true,
},
extends: [
"eslint:recommended",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install dependencies
if: steps.restore-dependencies.outputs.cache-hit != 'true'
run: npm ci --prefer-offline --no-audit
- name: Jest
- name: Vitest
run: npm run test
deploy_equinoxe_production:
if: github.ref == 'refs/heads/main'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ jobs:
echo "Waiting for OpenFisca to be ready..."
sleep 2
done
- name: Jest
- name: Vitest
run: npm run test
build:
name: Build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ npm run serve

There are several levels of tests:

- Unit tests are executed by [Jest](https://jestjs.io/fr/) and run with `npm test`.
- Unit tests are executed by [Vitest](https://vitest.dev/) and run with `npm test`.
- End-to-end test are executed with [Cypress](https://www.cypress.io/) with `npm run cypress`

You can safely use `npm test && npm run cypress` to drive your developments.
Expand Down
7 changes: 5 additions & 2 deletions backend/lib/mes-aides/emails/email-render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs"
import path from "path"
import consolidate from "consolidate"
import { fileURLToPath } from "url"

const mustache = consolidate.mustache
import config from "../../../config/index.js"
Expand All @@ -10,11 +11,13 @@ import { mjml } from "./index.js"
import { EmailType } from "../../../../lib/enums/messaging.js"
import { SurveyType } from "../../../../lib/enums/survey.js"

const __dirname = new URL(".", import.meta.url).pathname
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

function readFile(filePath) {
return fs.readFileSync(path.join(__dirname, filePath), "utf8")
return fs.readFileSync(path.resolve(__dirname, filePath), "utf8")
}

const emailTemplate = readFile("templates/email.mjml")
const footerTemplate = readFile("templates/footer.mjml")
const headerTemplate = readFile("templates/header.mjml")
Expand Down
4 changes: 2 additions & 2 deletions backend/lib/smtp.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config from "../config/index.js"
import nodemailer from "nodemailer"
import nodemailer, { TransportOptions } from "nodemailer"
import { Email } from "../../lib/types/email.js"

const transporter = nodemailer.createTransport(config.smtp)
const transporter = nodemailer.createTransport(config.smtp as TransportOptions)

export function sendEmailSmtp(email: Email) {
const { tags, ...emailParameters } = email
Expand Down
19 changes: 14 additions & 5 deletions data/all.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import { existsSync } from "node:fs"
import base from "./index.js"
import jamstackLoader from "@betagouv/jamstack-loader"
import path from "path"
import { Jamstack } from "./types/jamstack.d.js"
import path from "path"
import { fileURLToPath } from "url"

const __dirname = path.dirname(fileURLToPath(import.meta.url))

const __dirname = new URL(".", import.meta.url).pathname
let configFile = path.join(__dirname, "../contribuer/public/admin/config.yml")
let configFile = path.resolve(
__dirname,
"../contribuer/public/admin/config.yml"
)
let jamstack: Jamstack

if (existsSync(configFile)) {
jamstack = jamstackLoader.get(configFile)
} else {
configFile = path.join(__dirname, "../../contribuer/public/admin/config.yml")
jamstack = jamstackLoader.get(`${configFile}`)
configFile = path.resolve(
__dirname,
"../../contribuer/public/admin/config.yml"
)
jamstack = jamstackLoader.get(configFile)
}

export default base.generate(jamstack)
6 changes: 4 additions & 2 deletions data/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import path from "path"
import yaml from "js-yaml"
import fs from "fs"
import { fileURLToPath } from "url"
import jamstackLoader from "@betagouv/jamstack-loader"
const __dirname = new URL(".", import.meta.url).pathname
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const jamstack = jamstackLoader.get(
path.join(__dirname, "../contribuer/public/admin/config.yml")
path.resolve(__dirname, "../contribuer/public/admin/config.yml")
)

const typesMap = {
Expand Down
5 changes: 4 additions & 1 deletion iframes/iframes.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import path from "path"
import config from "../backend/config/index.js"
import webpack from "webpack"
import { fileURLToPath } from "url"

const __dirname = new URL(".", import.meta.url).pathname
process.env.BASE_URL = config.baseURL
process.env.IFRAME_TITLE = config.iframeTitle

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

export default {
mode: "production",
entry: {
Expand Down
Loading
Loading