Skip to content
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
10 changes: 6 additions & 4 deletions src/commands/po2json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export default function po2json(
let poData: PoData | PoDataCompact = parse(
fs.readFileSync(path).toString()
);
const errMessage = checkDuplicateKeys(poData);
if (format === "compact") {
const errMessage = checkDuplicateKeys(poData);

if (errMessage) {
progress.fail(errMessage);
process.exit(1);
if (errMessage) {
progress.fail(errMessage);
process.exit(1);
}
}
const messages = iterateTranslations(poData.translations);
if (!nostrip) {
Expand Down
17 changes: 15 additions & 2 deletions tests/commands/test_po2js.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from "path";
import { execSync } from "child_process";
import { execSync, spawnSync } from "child_process";

const poPath = path.resolve(__dirname, "../fixtures/po2jsTest/po2js.po");

Expand Down Expand Up @@ -39,7 +39,7 @@ const errMessage =
" this potentially can lead to translation loss.";

const poPath2 = path.resolve(__dirname, "../fixtures/checkTest/same_key.po");
test("Should get exception about same key", () => {
test("should get exception about same key for compact format", () => {
try {
execSync(
`ts-node src/index.ts po2json --format=compact -n ${poPath2}`,
Expand All @@ -53,3 +53,16 @@ test("Should get exception about same key", () => {
expect(err.stderr.toString()).toContain(errMessage);
}
});

test("should NOT get exception about same key for verbose format", () => {
const result = spawnSync(
`ts-node src/index.ts po2json --format=verbose -n ${poPath2}`,
{
shell: true,
encoding: "utf8"
}
);

expect(result.status).toBe(0);
expect(result.stderr).not.toContain(errMessage);
});