Skip to content

Commit

Permalink
try-catch cli loadProject, bump test timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jldec committed Apr 10, 2024
1 parent 5fb6c41 commit 7760ace
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 63 deletions.
61 changes: 33 additions & 28 deletions inlang/source-code/cli/src/utilities/getInlangProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,42 @@ export let lastUsedProject: InlangProject | undefined
* Gets the inlang project and exits if the project contains errors.
*/
export async function getInlangProject(args: { projectPath: string }): Promise<InlangProject> {
const baseDirectory = process.cwd()
const projectPath = resolve(baseDirectory, args.projectPath)
try {
const baseDirectory = process.cwd()
const projectPath = resolve(baseDirectory, args.projectPath)

let repoRoot = await findRepoRoot({ nodeishFs: fs, path: projectPath })
let repoRoot = await findRepoRoot({ nodeishFs: fs, path: projectPath })

if (!repoRoot) {
console.error(
`Could not find repository root for path ${projectPath}, falling back to direct fs access`
)
repoRoot = baseDirectory
}
const repo = await openRepository(repoRoot, {
nodeishFs: fs,
})

const project = await loadProject({
projectPath,
repo,
appId: id,
})

if (project.errors().length > 0) {
for (const error of project.errors()) {
console.error(error)
if (!repoRoot) {
console.error(
`Could not find repository root for path ${projectPath}, falling back to direct fs access`
)
repoRoot = baseDirectory
}
const repo = await openRepository(repoRoot, {
nodeishFs: fs,
})

const project = await loadProject({
projectPath,
repo,
appId: id,
})

if (project.errors().length > 0) {
for (const error of project.errors()) {
console.error(error)
}
process.exit(1)
}
process.exit(1)
}

// eslint-disable-next-line no-console
console.log("getInlangProject loaded", projectPath)
// eslint-disable-next-line no-console
console.log("getInlangProject loaded", projectPath)

lastUsedProject = project
return project
lastUsedProject = project
return project
} catch (err) {
console.error(`Error opening inlang project at ${args.projectPath}`, err)
process.exit(1)
}
}
74 changes: 39 additions & 35 deletions inlang/source-code/sdk/multi-project-test/multi-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,62 @@ describe.concurrent("sanity check run behavior", () => {
})
})

describe.concurrent("translate multiple projects in different directories", () => {
it(
"project1 in root",
async () => {
await run("pnpm translate1")
const result = await fs.readFile(join(__dirname, "locales", "de.json"), "utf8")
expect(result).toEqual(`{
describe.concurrent(
"translate multiple projects in different directories",
() => {
it(
"project1 in root",
async () => {
await run("pnpm translate1")
const result = await fs.readFile(join(__dirname, "locales", "de.json"), "utf8")
expect(result).toEqual(`{
"$schema": "https://inlang.com/schema/inlang-message-format",
"project1_message_key_1": "Mock translate local en to de: Generated message (1)",
"project1_message_key_2": "Mock translate local en to de: Generated message (2)",
"project1_message_key_3": "Mock translate local en to de: Generated message (3)"
}`)
},
{ timeout: 10000 }
)
},
{ timeout: 10000 }
)

it(
"project2 in project2-dir",
async () => {
await run("pnpm translate2")
const result = await fs.readFile(
join(__dirname, "project2-dir", "locales", "de.json"),
"utf8"
)
expect(result).toEqual(`{
it(
"project2 in project2-dir",
async () => {
await run("pnpm translate2")
const result = await fs.readFile(
join(__dirname, "project2-dir", "locales", "de.json"),
"utf8"
)
expect(result).toEqual(`{
"$schema": "https://inlang.com/schema/inlang-message-format",
"project2_message_key_1": "Mock translate local en to de: Generated message (1)",
"project2_message_key_2": "Mock translate local en to de: Generated message (2)",
"project2_message_key_3": "Mock translate local en to de: Generated message (3)"
}`)
},
{ timeout: 10000 }
)
},
{ timeout: 10000 }
)

it(
"project3 in project3-dir",
async () => {
await run("pnpm translate3")
const result = await fs.readFile(
join(__dirname, "project3-dir", "locales", "de.json"),
"utf8"
)
expect(result).toEqual(`{
it(
"project3 in project3-dir",
async () => {
await run("pnpm translate3")
const result = await fs.readFile(
join(__dirname, "project3-dir", "locales", "de.json"),
"utf8"
)
expect(result).toEqual(`{
"$schema": "https://inlang.com/schema/inlang-message-format",
"project3_message_key_1": "Mock translate local en to de: Generated message (1)",
"project3_message_key_2": "Mock translate local en to de: Generated message (2)",
"project3_message_key_3": "Mock translate local en to de: Generated message (3)"
}`)
},
{ timeout: 30000 }
)
})
},
{ timeout: 30000 }
)
},
{ timeout: 50000 }
)

// run command in __dirname
// returns 0 or rejects promise with error
Expand Down

0 comments on commit 7760ace

Please sign in to comment.