Parcourir la source

Fixed extracts check test (async bug)

rigwild il y a 5 ans
Parent
commit
dc85be1378
2 fichiers modifiés avec 13 ajouts et 8 suppressions
  1. 3 1
      .gitignore
  2. 10 7
      test/api/api.js

+ 3 - 1
.gitignore

@@ -1,5 +1,6 @@
 .DS_Store
 node_modules
+package-lock.json
 
 # local env files
 .env.local
@@ -21,4 +22,5 @@ yarn-error.log*
 
 /images
 /dist
-/logs
+/logs
+/test/images

+ 10 - 7
test/api/api.js

@@ -37,6 +37,7 @@ const serve = () => {
 
 // Before starting all the tests, copy `test/images_test` to `test/images`
 test.before(async t => {
+  await fs.remove(path.resolve(testDir, 'images'))
   await fs.copy(path.resolve(testDir, 'images_test'), path.resolve(testDir, 'images'))
 })
 
@@ -200,7 +201,7 @@ test('GET /getImageExtracts?sceneName=bathroom&imageQuality=10&horizontalExtract
   t.truthy(res.body.data.find(x => x.includes('Incompatible number of vertical extracts')), json(res.body))
 })
 
-test('GET /getImageExtracts?sceneName=bathroom&imageQuality=10&horizontalExtractCount=5&verticalExtractCount=2', async t => {
+test.serial('GET /getImageExtracts?sceneName=bathroom&imageQuality=10&horizontalExtractCount=5&verticalExtractCount=2', async t => {
   const res = await request(t.context.server)
     .get(`${apiPrefix}/getImageExtracts?sceneName=bathroom&imageQuality=10&horizontalExtractCount=5&verticalExtractCount=2`)
 
@@ -214,20 +215,22 @@ test('GET /getImageExtracts?sceneName=bathroom&imageQuality=10&horizontalExtract
 
   t.is(res2.status, 200, json(res2))
   t.is(res2.header['content-type'], 'image/png', json(res2))
+})
 
+test.serial('Extracts were successfully generated', async t => {
   // Check the extract on the file system
   const extracts = path.resolve(imagesPath, 'bathroom', 'extracts')
-  const aBathroomConfig = path.resolve(extracts, 'bathroom', 'x5_y2')
-  const aBathroomConfigZone = path.resolve(extracts, 'bathroom', 'x5_y2', 'zone00001')
-  const aBathroomConfigZoneImg = path.resolve(extracts, 'bathroom', 'x5_y2', 'zone00001', 'bathroom_zone00001_10.png')
+  const aBathroomConfig = path.resolve(extracts, 'x5_y2')
+  const aBathroomConfigZone = path.resolve(aBathroomConfig, 'zone00001')
+  const aBathroomConfigZoneImg = path.resolve(aBathroomConfigZone, 'bathroom_zone00001_10.png')
   const fsp = fs.promises
   // Check `bathroom/extracts`
   t.true(await fs.pathExists(extracts))
-  t.is(await fsp.readdir(extracts), ['x5_y2'])
+  t.deepEqual(await fsp.readdir(extracts), ['x5_y2'])
 
   // Check `bathroom/extracts/x5_y2`
-  t.true(await fs.pathExists(aBathroomConfig))
-  t.is((await fsp.readdir(extracts)).length, 10)
+  t.true(await fs.pathExists(aBathroomConfig), aBathroomConfig)
+  t.is((await fsp.readdir(aBathroomConfig)).length, 10)
 
   // Check `bathroom/extracts/x5_y2/zone00001`
   t.true(await fs.pathExists(aBathroomConfigZone))