11import generate from "@babel/generator"
22import { compile , createCompiledCatalog } from "./compile"
33
4- describe ( "compile" , function ( ) {
4+ describe ( "compile" , ( ) => {
55 const getSource = ( message ) =>
66 generate ( compile ( message ) as any , {
77 compact : true ,
88 minified : true ,
99 } ) . code
1010
11- it ( "should optimize string only messages" , function ( ) {
11+ it ( "should optimize string only messages" , ( ) => {
1212 expect ( getSource ( "Hello World" ) ) . toEqual ( '"Hello World"' )
1313 } )
1414
@@ -17,21 +17,21 @@ describe("compile", function () {
1717 expect ( getSource ( "''" ) ) . toEqual ( '"\'"' )
1818 } )
1919
20- it ( "should compile arguments" , function ( ) {
20+ it ( "should compile arguments" , ( ) => {
2121 expect ( getSource ( "{name}" ) ) . toEqual ( '[["name"]]' )
2222
2323 expect ( getSource ( "B4 {name} A4" ) ) . toEqual ( '["B4 ",["name"]," A4"]' )
2424 } )
2525
26- it ( "should compile arguments with formats" , function ( ) {
26+ it ( "should compile arguments with formats" , ( ) => {
2727 expect ( getSource ( "{name, number}" ) ) . toEqual ( '[["name","number"]]' )
2828
2929 expect ( getSource ( "{name, number, percent}" ) ) . toEqual (
3030 '[["name","number","percent"]]'
3131 )
3232 } )
3333
34- it ( "should compile plural" , function ( ) {
34+ it ( "should compile plural" , ( ) => {
3535 expect ( getSource ( "{name, plural, one {Book} other {Books}}" ) ) . toEqual (
3636 '[["name","plural",{one:"Book",other:"Books"}]]'
3737 )
@@ -53,7 +53,7 @@ describe("compile", function () {
5353 )
5454 } )
5555
56- it ( "should compile select" , function ( ) {
56+ it ( "should compile select" , ( ) => {
5757 expect ( getSource ( "{name, select, male {He} female {She}}" ) ) . toEqual (
5858 '[["name","select",{male:"He",female:"She"}]]'
5959 )
@@ -67,15 +67,15 @@ describe("compile", function () {
6767 )
6868 } )
6969
70- it ( "should report failed message on error" , function ( ) {
70+ it ( "should report failed message on error" , ( ) => {
7171 expect ( ( ) =>
7272 getSource ( "{value, plural, one {Book} other {Books" )
7373 ) . toThrowErrorMatchingSnapshot ( )
7474 } )
7575} )
7676
77- describe ( "createCompiledCatalog" , function ( ) {
78- describe ( "options.namespace" , function ( ) {
77+ describe ( "createCompiledCatalog" , ( ) => {
78+ describe ( "options.namespace" , ( ) => {
7979 const getCompiledCatalog = ( namespace ) =>
8080 createCompiledCatalog (
8181 "fr" ,
@@ -85,24 +85,24 @@ describe("createCompiledCatalog", function () {
8585 }
8686 )
8787
88- it ( "should compile with es" , function ( ) {
88+ it ( "should compile with es" , ( ) => {
8989 expect ( getCompiledCatalog ( "es" ) ) . toMatchSnapshot ( )
9090 } )
9191
92- it ( "should compile with window" , function ( ) {
92+ it ( "should compile with window" , ( ) => {
9393 expect ( getCompiledCatalog ( "window.test" ) ) . toMatchSnapshot ( )
9494 } )
9595
96- it ( "should compile with global" , function ( ) {
96+ it ( "should compile with global" , ( ) => {
9797 expect ( getCompiledCatalog ( "global.test" ) ) . toMatchSnapshot ( )
9898 } )
9999
100- it ( "should error with invalid value" , function ( ) {
100+ it ( "should error with invalid value" , ( ) => {
101101 expect ( ( ) => getCompiledCatalog ( "global" ) ) . toThrowErrorMatchingSnapshot ( )
102102 } )
103103 } )
104104
105- describe ( "options.strict" , function ( ) {
105+ describe ( "options.strict" , ( ) => {
106106 const getCompiledCatalog = ( strict ) =>
107107 createCompiledCatalog (
108108 "cs" ,
@@ -115,16 +115,16 @@ describe("createCompiledCatalog", function () {
115115 }
116116 )
117117
118- it ( "should return message key as a fallback translation" , function ( ) {
118+ it ( "should return message key as a fallback translation" , ( ) => {
119119 expect ( getCompiledCatalog ( false ) ) . toMatchSnapshot ( )
120120 } )
121121
122- it ( "should't return message key as a fallback in strict mode" , function ( ) {
122+ it ( "should't return message key as a fallback in strict mode" , ( ) => {
123123 expect ( getCompiledCatalog ( true ) ) . toMatchSnapshot ( )
124124 } )
125125 } )
126126
127- describe ( "options.pseudoLocale" , function ( ) {
127+ describe ( "options.pseudoLocale" , ( ) => {
128128 const getCompiledCatalog = ( pseudoLocale ) =>
129129 createCompiledCatalog (
130130 "ps" ,
@@ -136,12 +136,37 @@ describe("createCompiledCatalog", function () {
136136 }
137137 )
138138
139- it ( "should return catalog with pseudolocalized messages" , function ( ) {
139+ it ( "should return catalog with pseudolocalized messages" , ( ) => {
140140 expect ( getCompiledCatalog ( "ps" ) ) . toMatchSnapshot ( )
141141 } )
142142
143- it ( "should return compiled catalog when pseudoLocale doesn't match current locale" , function ( ) {
143+ it ( "should return compiled catalog when pseudoLocale doesn't match current locale" , ( ) => {
144144 expect ( getCompiledCatalog ( "en" ) ) . toMatchSnapshot ( )
145145 } )
146146 } )
147+
148+ describe ( "options.compilerBabelOptions" , ( ) => {
149+ const getCompiledCatalog = ( opts = { } ) =>
150+ createCompiledCatalog (
151+ "ru" ,
152+ {
153+ Hello : "Alohà" ,
154+ } ,
155+ opts
156+ )
157+
158+ it ( "by default should return catalog without ASCII chars" , ( ) => {
159+ expect ( getCompiledCatalog ( ) ) . toMatchSnapshot ( )
160+ } )
161+
162+ it ( "should return catalog without ASCII chars" , ( ) => {
163+ expect ( getCompiledCatalog ( {
164+ compilerBabelOptions : {
165+ jsescOption : {
166+ minimal : false ,
167+ }
168+ }
169+ } ) ) . toMatchSnapshot ( )
170+ } )
171+ } )
147172} )
0 commit comments