feat(SW-706): add Lokalise tooling and codemod
This commit is contained in:
134
apps/scandic-web/codemods/lokalise/lokalise.test.ts
Normal file
134
apps/scandic-web/codemods/lokalise/lokalise.test.ts
Normal file
@@ -0,0 +1,134 @@
|
||||
import { readFileSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
|
||||
import { describe, expect, test } from "@jest/globals"
|
||||
import { IndentationText, Project } from "ts-morph"
|
||||
|
||||
import { processSourceFile } from "./lokalise"
|
||||
|
||||
describe("Lokalise codemod", () => {
|
||||
test("serverComponent: intl.formatMessage with only id", () => {
|
||||
const input = readFileSync(
|
||||
join(__dirname, "./fixtures/serverComponentOnlyId.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const expected = readFileSync(
|
||||
join(__dirname, "./expectations/serverComponentOnlyId.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const project = new Project({
|
||||
manipulationSettings: {
|
||||
indentationText: IndentationText.TwoSpaces,
|
||||
},
|
||||
})
|
||||
const sourceFile = project.createSourceFile(
|
||||
"./fixtures/serverComponent.tsx",
|
||||
input
|
||||
)
|
||||
|
||||
processSourceFile(sourceFile)
|
||||
|
||||
const result = sourceFile.getFullText()
|
||||
|
||||
expect(result).toBe(expected)
|
||||
})
|
||||
|
||||
test("serverComponent: intl.formatMessage with ternary inside", () => {
|
||||
const input = readFileSync(
|
||||
join(__dirname, "./fixtures/serverComponentWithTernaryInside.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const expected = readFileSync(
|
||||
join(__dirname, "./expectations/serverComponentWithTernaryInside.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const project = new Project({
|
||||
manipulationSettings: {
|
||||
indentationText: IndentationText.TwoSpaces,
|
||||
},
|
||||
})
|
||||
const sourceFile = project.createSourceFile(
|
||||
"./fixtures/serverComponentWithTernaryInside.tsx",
|
||||
input
|
||||
)
|
||||
|
||||
processSourceFile(sourceFile)
|
||||
|
||||
const result = sourceFile.getFullText()
|
||||
expect(result).toBe(expected)
|
||||
})
|
||||
|
||||
test("serverComponent: intl.formatMessage with variables", () => {
|
||||
const input = readFileSync(
|
||||
join(__dirname, "./fixtures/serverComponentWithVariables.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const expected = readFileSync(
|
||||
join(__dirname, "./expectations/serverComponentWithVariables.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const project = new Project({
|
||||
manipulationSettings: {
|
||||
indentationText: IndentationText.TwoSpaces,
|
||||
},
|
||||
})
|
||||
const sourceFile = project.createSourceFile(
|
||||
"./fixtures/serverComponentWithVariables.tsx",
|
||||
input
|
||||
)
|
||||
|
||||
processSourceFile(sourceFile)
|
||||
|
||||
const result = sourceFile.getFullText()
|
||||
expect(result).toBe(expected)
|
||||
})
|
||||
|
||||
test("serverComponent: intl.formatMessage with variable for id", () => {
|
||||
const input = readFileSync(
|
||||
join(__dirname, "./fixtures/serverComponentVariableId.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const expected = readFileSync(
|
||||
join(__dirname, "./expectations/serverComponentVariableId.tsx"),
|
||||
{
|
||||
encoding: "utf-8",
|
||||
}
|
||||
)
|
||||
|
||||
const project = new Project({
|
||||
manipulationSettings: {
|
||||
indentationText: IndentationText.TwoSpaces,
|
||||
},
|
||||
})
|
||||
const sourceFile = project.createSourceFile(
|
||||
"./fixtures/serverComponentVariableId.tsx",
|
||||
input
|
||||
)
|
||||
|
||||
processSourceFile(sourceFile)
|
||||
|
||||
const result = sourceFile.getFullText()
|
||||
expect(result).toBe(expected)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user