@@ -4,23 +4,24 @@ import mockFs from "mock-fs"
44import mockDate from "mockdate"
55import PO from "pofile"
66import { mockConsole } from "@lingui/jest-mocks"
7+ import { format as formatDate } from "date-fns"
78
89import format from "./po"
910import { CatalogType } from "../catalog"
1011
11- describe ( "pofile format" , function ( ) {
12+ describe ( "pofile format" , ( ) => {
1213 afterEach ( ( ) => {
1314 mockFs . restore ( )
1415 mockDate . reset ( )
1516 } )
1617
17- it ( "should write catalog in pofile format" , function ( ) {
18+ it ( "should write catalog in pofile format" , ( ) => {
1819 mockFs ( {
1920 locale : {
2021 en : mockFs . directory ( ) ,
2122 } ,
2223 } )
23- mockDate . set ( new Date ( 2018 , 7 , 27 , 10 , 0 , 0 ) . toUTCString ( ) )
24+ mockDate . set ( new Date ( 2018 , 7 , 27 , 10 , 0 , 0 ) . toUTCString ( ) )
2425
2526 const filename = path . join ( "locale" , "en" , "messages.po" )
2627 const catalog : CatalogType = {
@@ -40,7 +41,9 @@ describe("pofile format", function () {
4041 } ,
4142 withDescription : {
4243 translation : "Message with description" ,
43- extractedComments : [ "Description is comment from developers to translators" ] ,
44+ extractedComments : [
45+ "Description is comment from developers to translators" ,
46+ ] ,
4447 } ,
4548 withComments : {
4649 comments : [ "Translator comment" , "This one might come from developer" ] ,
@@ -73,7 +76,7 @@ describe("pofile format", function () {
7376 expect ( pofile ) . toMatchSnapshot ( )
7477 } )
7578
76- it ( "should read catalog in pofile format" , function ( ) {
79+ it ( "should read catalog in pofile format" , ( ) => {
7780 const pofile = fs
7881 . readFileSync (
7982 path . join ( path . resolve ( __dirname ) , "fixtures" , "messages.po" )
@@ -94,7 +97,7 @@ describe("pofile format", function () {
9497 expect ( actual ) . toMatchSnapshot ( )
9598 } )
9699
97- it ( "should correct badly used comments" , function ( ) {
100+ it ( "should correct badly used comments" , ( ) => {
98101 const po = PO . parse ( `
99102 #. First description
100103 #. Second comment
@@ -123,7 +126,7 @@ describe("pofile format", function () {
123126 expect ( actual ) . toMatchSnapshot ( )
124127 } )
125128
126- it ( "should throw away additional msgstr if present" , function ( ) {
129+ it ( "should throw away additional msgstr if present" , ( ) => {
127130 const po = PO . parse ( `
128131 msgid "withMultipleTranslation"
129132 msgstr[0] "This is just fine"
@@ -150,7 +153,7 @@ describe("pofile format", function () {
150153 } )
151154 } )
152155
153- it ( "should write the same catalog as it was read" , function ( ) {
156+ it ( "should write the same catalog as it was read" , ( ) => {
154157 const pofile = fs
155158 . readFileSync (
156159 path . join ( path . resolve ( __dirname ) , "fixtures" , "messages.po" )
@@ -172,10 +175,12 @@ describe("pofile format", function () {
172175 mockFs . restore ( )
173176 // on windows mockFs adds ··· to multiline string, so this strictly equal comparison can't be done
174177 // we test that the content if the same inlined...
175- expect ( actual . replace ( / ( \r \n | \n | \r ) / gm, "" ) ) . toEqual ( pofile . replace ( / ( \r \n | \n | \r ) / gm, "" ) )
178+ expect ( actual . replace ( / ( \r \n | \n | \r ) / gm, "" ) ) . toEqual (
179+ pofile . replace ( / ( \r \n | \n | \r ) / gm, "" )
180+ )
176181 } )
177182
178- it ( "should not include origins if origins option is false" , function ( ) {
183+ it ( "should not include origins if origins option is false" , ( ) => {
179184 mockFs ( {
180185 locale : {
181186 en : mockFs . directory ( ) ,
@@ -205,4 +210,60 @@ describe("pofile format", function () {
205210 const pofileOriginPrefix = "#:"
206211 expect ( pofile ) . toEqual ( expect . not . stringContaining ( pofileOriginPrefix ) )
207212 } )
213+
214+ it ( "should not include lineNumbers if lineNumbers option is false" , ( ) => {
215+ mockFs ( {
216+ locale : {
217+ en : mockFs . directory ( ) ,
218+ } ,
219+ } )
220+
221+ const filename = path . join ( "locale" , "en" , "messages.po" )
222+ const catalog : CatalogType = {
223+ static : {
224+ translation : "Static message" ,
225+ } ,
226+ withOrigin : {
227+ translation : "Message with origin" ,
228+ origin : [ [ "src/App.js" , 4 ] ] ,
229+ } ,
230+ withMultipleOrigins : {
231+ translation : "Message with multiple origin" ,
232+ origin : [
233+ [ "src/App.js" , 4 ] ,
234+ [ "src/Component.js" , 2 ] ,
235+ ] ,
236+ } ,
237+ }
238+ format . write ( filename , catalog , {
239+ origins : true ,
240+ lineNumbers : false ,
241+ locale : "en" ,
242+ } )
243+ const pofile = fs . readFileSync ( filename ) . toString ( )
244+ mockFs . restore ( )
245+ expect ( pofile ) . toMatchInlineSnapshot ( `
246+ msgid ""
247+ msgstr ""
248+ "POT-Creation-Date: ${ formatDate ( new Date ( ) , "yyyy-MM-dd HH:mmxxxx" ) } \\n"
249+ "Mime-Version: 1.0\\n"
250+ "Content-Type: text/plain; charset=utf-8\\n"
251+ "Content-Transfer-Encoding: 8bit\\n"
252+ "X-Generator: @lingui/cli\\n"
253+ "Language: en\\n"
254+
255+ msgid "static"
256+ msgstr "Static message"
257+
258+ #: src/App.js
259+ msgid "withOrigin"
260+ msgstr "Message with origin"
261+
262+ #: src/App.js
263+ #: src/Component.js
264+ msgid "withMultipleOrigins"
265+ msgstr "Message with multiple origin"
266+
267+ ` )
268+ } )
208269} )
0 commit comments