@@ -10,6 +10,9 @@ import type { OutputEntry } from './test-utils.ts'
1010import { authKey , authSecret , delay , testCase } from './test-utils.ts'
1111
1212describe ( 'templates' , ( ) => {
13+ // Use unique prefix for all template names to avoid conflicts between test runs
14+ const testId = `${ Date . now ( ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 8 ) } `
15+
1316 describe ( 'create' , ( ) => {
1417 it (
1518 'should create templates' ,
@@ -18,7 +21,7 @@ describe('templates', () => {
1821 const output = new OutputCtl ( )
1922 const steps = { import : { robot : '/http/import' , url : `https://example.com/${ n } ` } }
2023 await fsp . writeFile ( `${ n } .json` , JSON . stringify ( steps ) )
21- await templates . create ( output , client , { name : `test-${ n } ` , file : `${ n } .json` } )
24+ await templates . create ( output , client , { name : `test-${ testId } - ${ n } ` , file : `${ n } .json` } )
2225 return output . get ( ) as OutputEntry [ ]
2326 } )
2427
@@ -88,7 +91,7 @@ describe('templates', () => {
8891
8992 describe ( 'modify' , ( ) => {
9093 let templateId : string
91- const originalName = `original-name-${ Date . now ( ) } `
94+ const originalName = `original-name-${ testId } `
9295
9396 beforeAll ( async ( ) => {
9497 const client = new TransloaditClient ( { authKey, authSecret } )
@@ -127,18 +130,19 @@ describe('templates', () => {
127130 testCase ( async ( client ) => {
128131 await fsp . writeFile ( 'template.json' , '' )
129132
133+ const newName = `new-name-${ testId } `
130134 const output = new OutputCtl ( )
131135 await templates . modify ( output , client , {
132136 template : templateId ,
133- name : 'new-name' ,
137+ name : newName ,
134138 file : 'template.json' ,
135139 } )
136140 const result = output . get ( )
137141
138142 expect ( result ) . to . have . lengthOf ( 0 )
139143 await delay ( 2000 )
140144 const template = await client . getTemplate ( templateId )
141- expect ( template ) . to . have . property ( 'name' ) . that . equals ( 'new-name' )
145+ expect ( template ) . to . have . property ( 'name' ) . that . equals ( newName )
142146 expect ( template ) . to . have . property ( 'content' ) . that . has . property ( 'steps' )
143147 } ) ,
144148 )
@@ -149,18 +153,19 @@ describe('templates', () => {
149153 const steps = { import : { robot : '/http/import' , url : 'https://example.com/renamed' } }
150154 await fsp . writeFile ( 'template.json' , JSON . stringify ( steps ) )
151155
156+ const newerName = `newer-name-${ testId } `
152157 const output = new OutputCtl ( )
153158 await templates . modify ( output , client , {
154159 template : templateId ,
155- name : 'newer-name' ,
160+ name : newerName ,
156161 file : 'template.json' ,
157162 } )
158163 const result = output . get ( )
159164
160165 expect ( result ) . to . have . lengthOf ( 0 )
161166 await delay ( 2000 )
162167 const template = await client . getTemplate ( templateId )
163- expect ( template ) . to . have . property ( 'name' ) . that . equals ( 'newer-name' )
168+ expect ( template ) . to . have . property ( 'name' ) . that . equals ( newerName )
164169 expect ( template ) . to . have . property ( 'content' ) . that . has . property ( 'steps' )
165170 } ) ,
166171 )
@@ -178,7 +183,7 @@ describe('templates', () => {
178183 const ids = await Promise . all (
179184 [ 1 , 2 , 3 , 4 , 5 ] . map ( async ( n ) => {
180185 const response = await client . createTemplate ( {
181- name : `delete-test-${ n } ` ,
186+ name : `delete-test-${ testId } - ${ n } ` ,
182187 template : {
183188 steps : { dummy : { robot : '/html/convert' , url : `https://example.com/${ n } ` } } ,
184189 } as TemplateContent ,
@@ -254,7 +259,7 @@ describe('templates', () => {
254259 'should update local files when outdated' ,
255260 testCase ( async ( client ) => {
256261 const params = {
257- name : `test-local-update-${ Date . now ( ) } ` ,
262+ name : `test-local-update-${ testId } ` ,
258263 template : {
259264 steps : { dummy : { robot : '/html/convert' , url : 'https://example.com/changed' } } ,
260265 } as TemplateContent ,
@@ -292,7 +297,7 @@ describe('templates', () => {
292297 'should update remote template when outdated' ,
293298 testCase ( async ( client ) => {
294299 const params = {
295- name : `test-remote-update-${ Date . now ( ) } ` ,
300+ name : `test-remote-update-${ testId } ` ,
296301 template : {
297302 steps : { dummy : { robot : '/html/convert' , url : 'https://example.com/unchanged' } } ,
298303 } as TemplateContent ,
0 commit comments