@@ -13,7 +13,7 @@ import testutil = require('./testutil');
1313
1414describe ( 'Loc Tests' , function ( ) {
1515
16- before ( function ( done ) {
16+ beforeEach ( function ( done ) {
1717 try {
1818 testutil . initialize ( ) ;
1919 }
@@ -72,6 +72,54 @@ describe('Loc Tests', function () {
7272
7373 done ( ) ;
7474 } )
75+ it ( 'gets loc string from second loc resources.json' , function ( done ) {
76+ this . timeout ( 1000 ) ;
77+
78+ // Don't reset values each time we call setResourcesPath for this test.
79+ process . env [ 'TASKLIB_INPROC_UNITS' ] = '' ;
80+
81+ // Arrange
82+ var tempFolder = path . join ( testutil . getTestTemp ( ) , 'loc-str-from-loc-res-json2' ) ;
83+ shell . mkdir ( '-p' , tempFolder ) ;
84+
85+ // Create first task.json and resources file
86+ var jsonStr = "{\"messages\": {\"key6\" : \"string for key 6.\"}}" ;
87+ var jsonPath = path . join ( tempFolder , 'task.json' ) ;
88+ fs . writeFileSync ( jsonPath , jsonStr ) ;
89+
90+ var tempLocFolder = path . join ( tempFolder , 'Strings' , 'resources.resjson' , 'zh-CN' ) ;
91+ shell . mkdir ( '-p' , tempLocFolder ) ;
92+ var locJsonStr = "{\"loc.messages.key6\" : \"loc cn-string for key 6.\"}" ;
93+ var locJsonPath = path . join ( tempLocFolder , 'resources.resjson' ) ;
94+ fs . writeFileSync ( locJsonPath , locJsonStr ) ;
95+
96+ // Create second task.json and resources file
97+ var nestedLocFolder = path . join ( tempFolder , 'nested' ) ;
98+ shell . mkdir ( '-p' , nestedLocFolder ) ;
99+
100+ var jsonStr2 = "{\"messages\": {\"keySecondFile\" : \"string for keySecondFile.\"}}" ;
101+ var jsonPath2 = path . join ( nestedLocFolder , 'task.json' ) ;
102+ fs . writeFileSync ( jsonPath2 , jsonStr2 ) ;
103+
104+ var tempLocFolder2 = path . join ( nestedLocFolder , 'Strings' , 'resources.resjson' , 'zh-CN' ) ;
105+ shell . mkdir ( '-p' , tempLocFolder2 ) ;
106+ var locJsonStr2 = "{\"loc.messages.keySecondFile\" : \"loc cn-string for keySecondFile.\"}" ;
107+ var locJsonPath2 = path . join ( tempLocFolder2 , 'resources.resjson' ) ;
108+ fs . writeFileSync ( locJsonPath2 , locJsonStr2 ) ;
109+
110+ process . env [ 'SYSTEM_CULTURE' ] = 'ZH-cn' ; // Lib should handle casing differences for culture.
111+
112+ // Act
113+ tl . setResourcePath ( jsonPath ) ;
114+ tl . setResourcePath ( jsonPath2 ) ;
115+
116+ // Assert
117+ assert . equal ( tl . loc ( 'key6' ) , 'loc cn-string for key 6.' , 'string not found for key.' ) ;
118+ assert . equal ( tl . loc ( 'keySecondFile' ) , 'loc cn-string for keySecondFile.' , 'string not found for keySecondFile.' ) ;
119+
120+ done ( ) ;
121+ } )
122+
75123 it ( 'fallback to current string if culture resources.resjson not found' , function ( done ) {
76124 this . timeout ( 1000 ) ;
77125
0 commit comments