@@ -2,15 +2,30 @@ import { getCatalogDependentFiles, getFormat } from "@lingui/cli/api"
2
2
import { makeConfig } from "@lingui/conf"
3
3
import { Catalog } from "../catalog"
4
4
import { FormatterWrapper } from "../formats"
5
+ import mockFs from "mock-fs"
5
6
6
7
describe ( "getCatalogDependentFiles" , ( ) => {
7
8
let format : FormatterWrapper
8
9
9
10
beforeAll ( async ( ) => {
10
11
format = await getFormat ( "po" , { } , "en" )
11
12
} )
13
+ afterEach ( ( ) => {
14
+ mockFs . restore ( )
15
+ } )
16
+
17
+ it ( "Should return list template + fallbacks + sourceLocale" , async ( ) => {
18
+ mockFs ( {
19
+ "src/locales" : {
20
+ "messages.pot" : "bla" ,
21
+ "en.po" : "bla" ,
22
+ "pl.po" : "bla" ,
23
+ "es.po" : "bla" ,
24
+ "pt-PT.po" : "bla" ,
25
+ "pt-BR.po" : "bla" ,
26
+ } ,
27
+ } )
12
28
13
- it ( "Should return list template + fallbacks + sourceLocale" , ( ) => {
14
29
const config = makeConfig (
15
30
{
16
31
locales : [ "en" , "pl" , "es" , "pt-PT" , "pt-BR" ] ,
@@ -34,7 +49,10 @@ describe("getCatalogDependentFiles", () => {
34
49
config
35
50
)
36
51
37
- expect ( getCatalogDependentFiles ( catalog , "pt-PT" ) ) . toMatchInlineSnapshot ( `
52
+ const actual = await getCatalogDependentFiles ( catalog , "pt-PT" )
53
+ mockFs . restore ( )
54
+
55
+ expect ( actual ) . toMatchInlineSnapshot ( `
38
56
[
39
57
src/locales/messages.pot,
40
58
src/locales/pt-BR.po,
@@ -43,7 +61,18 @@ describe("getCatalogDependentFiles", () => {
43
61
` )
44
62
} )
45
63
46
- it ( "Should not return itself" , ( ) => {
64
+ it ( "Should not return itself" , async ( ) => {
65
+ mockFs ( {
66
+ "src/locales" : {
67
+ "messages.pot" : "bla" ,
68
+ "en.po" : "bla" ,
69
+ "pl.po" : "bla" ,
70
+ "es.po" : "bla" ,
71
+ "pt-PT.po" : "bla" ,
72
+ "pt-BR.po" : "bla" ,
73
+ } ,
74
+ } )
75
+
47
76
const config = makeConfig (
48
77
{
49
78
locales : [ "en" , "pl" , "es" , "pt-PT" , "pt-BR" ] ,
@@ -67,10 +96,59 @@ describe("getCatalogDependentFiles", () => {
67
96
config
68
97
)
69
98
70
- expect ( getCatalogDependentFiles ( catalog , "en" ) ) . toMatchInlineSnapshot ( `
99
+ const actual = await getCatalogDependentFiles ( catalog , "en" )
100
+ mockFs . restore ( )
101
+
102
+ expect ( actual ) . toMatchInlineSnapshot ( `
71
103
[
72
104
src/locales/messages.pot,
73
105
]
74
106
` )
75
107
} )
108
+
109
+ it ( "Should not return non-existing files" , async ( ) => {
110
+ mockFs ( {
111
+ "src/locales" : {
112
+ // "messages.pot": "bla",
113
+ "en.po" : "bla" ,
114
+ "pl.po" : "bla" ,
115
+ "es.po" : "bla" ,
116
+ "pt-PT.po" : "bla" ,
117
+ "pt-BR.po" : "bla" ,
118
+ } ,
119
+ } )
120
+
121
+ const config = makeConfig (
122
+ {
123
+ locales : [ "en" , "pl" , "es" , "pt-PT" , "pt-BR" ] ,
124
+ sourceLocale : "en" ,
125
+ fallbackLocales : {
126
+ "pt-PT" : "pt-BR" ,
127
+ default : "en" ,
128
+ } ,
129
+ } ,
130
+ { skipValidation : true }
131
+ )
132
+
133
+ const catalog = new Catalog (
134
+ {
135
+ name : null ,
136
+ path : "src/locales/{locale}" ,
137
+ include : [ "src/" ] ,
138
+ exclude : [ ] ,
139
+ format,
140
+ } ,
141
+ config
142
+ )
143
+
144
+ const actual = await getCatalogDependentFiles ( catalog , "pt-PT" )
145
+ mockFs . restore ( )
146
+
147
+ expect ( actual ) . toMatchInlineSnapshot ( `
148
+ [
149
+ src/locales/pt-BR.po,
150
+ src/locales/en.po,
151
+ ]
152
+ ` )
153
+ } )
76
154
} )
0 commit comments