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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions backend/lib/mes-aides/emails/email-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { formatBenefits, basicBenefitText } from "./simulation-results.js"
import { mjml } from "./index.js"
import { EmailType } from "../../../../lib/enums/messaging.js"
import { SurveyType } from "../../../../lib/enums/survey.js"
import { fileURLToPath } from "url"

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")
Expand Down
18 changes: 14 additions & 4 deletions data/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ import { existsSync } from "node:fs"
import base from "./index.js"
import jamstackLoader from "@betagouv/jamstack-loader"
import path from "path"
import { fileURLToPath } from "url"
import { Jamstack } from "./types/jamstack.d.js"

const __dirname = new URL(".", import.meta.url).pathname
let configFile = path.join(__dirname, "../contribuer/public/admin/config.yml")
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)

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
10 changes: 6 additions & 4 deletions iframes/iframes.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import path from "path"
import { resolvePath } from "../lib/utils/path-utils.js"
import config from "../backend/config/index.js"
import webpack from "webpack"

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

export default {
mode: "production",
entry: {
"iframe-integration": path.resolve(__dirname, "./iframe-integration.ts"),
"iframe-integration": resolvePath(
import.meta.url,
"./iframe-integration.ts"
),
},
output: {
path: path.resolve(__dirname, "../public/documents"),
path: resolvePath(import.meta.url, "../public/documents"),
filename: "[name].js",
},
plugins: [new webpack.EnvironmentPlugin(["BASE_URL", "IFRAME_TITLE"])],
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/path-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { fileURLToPath } from "url"
import path from "path"

export function resolvePath(importMetaUrl: string, ...paths: string[]) {
const dirname = path.dirname(fileURLToPath(importMetaUrl))
return path.resolve(dirname, ...paths)
}

export { path }
Loading
Loading