-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compile): remove verbose output when using flow with template
- Loading branch information
1 parent
9895281
commit 5aaaf95
Showing
9 changed files
with
291 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`CLI Command: Compile Locales Validation Should throw error for invalid locale 1`] = ` | ||
Error: Invalid locale abra (missing plural rules)! | ||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (with template) 1`] = ` | ||
Object { | ||
en: /*eslint-disable*/module.exports={messages:JSON.parse("{\\"Hello World\\":\\"Hello World\\"}")};, | ||
pl: undefined, | ||
} | ||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (with template) 2`] = ` | ||
Error: Failed to compile catalog for locale pl! | ||
Missing 1 translation(s) | ||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show error and stop compilation of catalog if message doesnt have a translation (no template) 1`] = ` | ||
Error: Failed to compile catalog for locale pl! | ||
Missing 1 translation(s) | ||
`; | ||
|
||
exports[`CLI Command: Compile allowEmpty = false Should show missing messages verbosely when verbose = true 1`] = ` | ||
en ⇒ /test/en.js | ||
Error: Failed to compile catalog for locale pl! | ||
Missing translations: | ||
Hello World | ||
Test String | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import {command} from "../lingui-compile" | ||
import {makeConfig} from "@lingui/conf" | ||
import path from "path" | ||
import {getConsoleMockCalls, mockConsole} from "@lingui/jest-mocks" | ||
import mockFs from "mock-fs" | ||
import fs from 'fs' | ||
|
||
function readFsToJson(directory: string, filter?: (filename: string) => boolean) { | ||
const out = {} | ||
|
||
fs | ||
.readdirSync(directory) | ||
.map((filename) => { | ||
const filepath = path.join(directory, filename) | ||
|
||
if (fs.lstatSync(filepath).isDirectory()) { | ||
out[filename] = readFsToJson(filepath) | ||
return out | ||
} | ||
|
||
if (!filter || filter(filename)) { | ||
out[filename] = fs.readFileSync(filepath).toString() | ||
} | ||
}) | ||
|
||
return out | ||
} | ||
|
||
describe('CLI Command: Compile', () => { | ||
xit('Should return error if no messages', () => { | ||
const config = makeConfig({ | ||
locales: ['en', 'pl'], | ||
rootDir: path.join(__dirname, 'fixtures/compile'), | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'] | ||
}] | ||
}) | ||
|
||
const result = command(config, {}) | ||
expect(result).toBeFalsy() | ||
}) | ||
|
||
describe('Merge Catalogs', () => { | ||
// todo | ||
}) | ||
|
||
describe('Locales Validation', () => { | ||
// todo: should be moved to @lingui/conf | ||
it('Should throw error for invalid locale', () => { | ||
const config = makeConfig({ | ||
locales: ['abra'], | ||
rootDir: '/test', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
mockFs() | ||
|
||
mockConsole((console) => { | ||
const result = command(config, {}) | ||
mockFs.restore() | ||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
|
||
expect(result).toBeTruthy() | ||
}) | ||
}) | ||
|
||
it('Should not throw error for pseudolocale', () => { | ||
const config = makeConfig({ | ||
locales: ['abracadabra'], | ||
rootDir: '/test', | ||
pseudoLocale: 'abracadabra', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
mockFs() | ||
|
||
mockConsole((console) => { | ||
const result = command(config, {}) | ||
mockFs.restore() | ||
expect(console.error).not.toBeCalled() | ||
expect(result).toBeTruthy() | ||
}) | ||
}) | ||
}) | ||
|
||
describe('allowEmpty = false', () => { | ||
const config = makeConfig({ | ||
locales: ['en', 'pl'], | ||
sourceLocale: 'en', | ||
rootDir: '/test', | ||
catalogs: [{ | ||
path: '<rootDir>/{locale}', | ||
include: ['<rootDir>'], | ||
exclude: [] | ||
}] | ||
}) | ||
|
||
it('Should show error and stop compilation of catalog ' + | ||
'if message doesnt have a translation (no template)', () => { | ||
mockFs({ | ||
'/test': { | ||
'en.po': ` | ||
msgid "Hello World" | ||
msgstr "Hello World" | ||
`, | ||
'pl.po': ` | ||
msgid "Hello World" | ||
msgstr "Cześć świat" | ||
msgid "Test String" | ||
msgstr "" | ||
` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false | ||
}) | ||
const actualFiles = readFsToJson('/test') | ||
|
||
expect(actualFiles['pl.js']).toBeFalsy() | ||
expect(actualFiles['en.js']).toBeTruthy() | ||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
it('Should show error and stop compilation of catalog ' + | ||
' if message doesnt have a translation (with template)', () => { | ||
mockFs({ | ||
'/test': { | ||
'messages.pot': ` | ||
msgid "Hello World" | ||
msgstr "" | ||
`, | ||
'pl.po': `` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false | ||
}) | ||
|
||
const actualFiles = readFsToJson('/test') | ||
|
||
expect({ | ||
pl: actualFiles['pl.js'], | ||
en: actualFiles['en.js'] | ||
}).toMatchSnapshot() | ||
|
||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
|
||
it('Should show missing messages verbosely when verbose = true', () => { | ||
mockFs({ | ||
'/test': { | ||
'pl.po': ` | ||
msgid "Hello World" | ||
msgstr "" | ||
msgid "Test String" | ||
msgstr "" | ||
` | ||
} | ||
}) | ||
|
||
mockConsole((console) => { | ||
const result = command(config, { | ||
allowEmpty: false, | ||
verbose: true | ||
}) | ||
|
||
mockFs.restore() | ||
|
||
const log = getConsoleMockCalls(console.error) | ||
expect(log).toMatchSnapshot() | ||
expect(result).toBeFalsy() | ||
}) | ||
}) | ||
|
||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.