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

Don't warn about duplicate default message if it's empty #502

Merged
merged 1 commit into from
May 19, 2019
Merged
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
18 changes: 18 additions & 0 deletions packages/cli/src/api/__snapshots__/extract.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ Object {
}
`;

exports[`collect should use defined default 1`] = `
Object {
msg.id: Object {
defaults: Second default,
origin: Array [
Array [
onlyOneDefault/First.js,
2,
],
Array [
onlyOneDefault/Second.js,
5,
],
],
},
}
`;

exports[`order should order messages alphabetically 1`] = `
Object {
en: Object {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/api/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ExtractOptions = {
* should be the same (raise an error if defaults are different).
*/
function mergeMessage(msgId, prev, next) {
if (prev.defaults !== next.defaults) {
if (prev.defaults && next.defaults && prev.defaults !== next.defaults) {
throw new Error(
`Encountered different defaults for message ${chalk.yellow(msgId)}` +
`\n${chalk.yellow(prettyOrigin(prev.origin))} ${prev.defaults}` +
Expand All @@ -32,6 +32,7 @@ function mergeMessage(msgId, prev, next) {

return {
...next,
defaults: prev.defaults || next.defaults,
origin: R.concat(prev.origin, next.origin)
}
}
Expand Down
22 changes: 22 additions & 0 deletions packages/cli/src/api/extract.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ describe("collect", function() {
origin: [["diffDefaults/Second.js", 5]]
}
})
},

// test case for when only one defaults message is specified
onlyOneDefault: {
"First.js.json": JSON.stringify({
"msg.id": {
origin: [["onlyOneDefault/First.js", 2]]
}
}),
"Second.js.json": JSON.stringify({
"msg.id": {
defaults: "Second default",
origin: [["onlyOneDefault/Second.js", 5]]
}
})
}
})
})
Expand Down Expand Up @@ -162,6 +177,13 @@ describe("collect", function() {
}).toThrowErrorMatchingSnapshot()
}
})

it("should use defined default", function() {
const { collect } = require("./extract")
const catalog = collect("onlyOneDefault")
mockFs.restore()
expect(catalog).toMatchSnapshot()
})
})

describe("cleanObsolete", function() {
Expand Down