Skip to content

Commit 5c62d8f

Browse files
committed
test: add overwriteDefault test
1 parent 4501919 commit 5c62d8f

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

cli.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const cli = meow(
1414
-l, --locales locales [require: true]
1515
-f, --format json | yaml [default: json]
1616
-d, --default-locale default locale
17-
-w, --overwrite-default default: false
17+
--overwriteDefault default: false
1818
--flat json [default: true] | yaml [default: false]
1919
2020
Example
@@ -43,13 +43,13 @@ const cli = meow(
4343
type: 'string',
4444
alias: 'd'
4545
},
46-
withDescriptions: {
46+
overwriteDefault: {
4747
type: 'boolean',
48-
default: false
48+
default: true
4949
},
50-
'overwrite-default': {
50+
withDescriptions: {
5151
type: 'boolean',
52-
default: true
52+
default: false
5353
},
5454
// babel-plugin-react-intl boolean options
5555
extractSourceLocation: {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $ extract-messages --help
100100
-l, --locales locales [require: true]
101101
-f, --format json | yaml [default: json]
102102
-d, --default-locale default locale
103-
-w, --overwrite-default default: false
103+
--overwriteDefault default: false
104104
--flat json [default: true] | yaml [default: false]
105105

106106
Example

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Opts = {
6262
defaultLocale: string
6363
format?: string
6464
flat?: boolean
65+
overwriteDefault?: boolean
6566
}
6667

6768
// eslint-disable-next-line max-lines-per-function

src/test/json/__snapshots__/test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,19 @@ Array [
123123
"z.hello",
124124
]
125125
`;
126+
127+
exports[`with overwriteDefault 1`] = `
128+
Object {
129+
"a.custom.hello": "hello",
130+
"a.custom.world": "world",
131+
"b.custom.message": "Default Message",
132+
}
133+
`;
134+
135+
exports[`with overwriteDefault 2`] = `
136+
Object {
137+
"a.custom.hello": "",
138+
"a.custom.world": "",
139+
"b.custom.message": "",
140+
}
141+
`;

src/test/json/test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ test('export using custom module', async () => {
6666
expect(en).toMatchSnapshot()
6767
expect(ja).toMatchSnapshot()
6868
})
69+
70+
test('with overwriteDefault', async () => {
71+
const tmp = tempy.directory()
72+
fs.writeFileSync(
73+
path.resolve(tmp, 'en.json'),
74+
JSON.stringify(
75+
{
76+
'a.custom.hello': 'hello',
77+
'a.custom.world': 'world',
78+
'b.custom.message': 'Default Message'
79+
},
80+
null,
81+
2
82+
),
83+
'utf8'
84+
)
85+
await m(['en', 'ja'], 'src/test/fixtures/custom/**/*.js', tmp, {
86+
defaultLocale: 'en',
87+
moduleSourceName: '../i18n',
88+
overwriteDefault: false
89+
})
90+
const en = JSON.parse(fs.readFileSync(path.resolve(tmp, 'en.json'), 'utf8'))
91+
const ja = JSON.parse(fs.readFileSync(path.resolve(tmp, 'ja.json'), 'utf8'))
92+
expect(en).toMatchSnapshot()
93+
expect(ja).toMatchSnapshot()
94+
})

0 commit comments

Comments
 (0)