Browse Source

test: Better path compare than just strings (#13548)

* Better path comparision than just strings

* Linter fix

* Resolving paths first to always obtain absolute path so path.relative() can work

* Using assert.ok which better fits the test

* No need to resolve parameters of path.resolve

* Added assertion to type of returned path for download item
Tomas Rycl 6 years ago
parent
commit
9b6a37ead7
1 changed files with 6 additions and 1 deletions
  1. 6 1
      spec/api-session-spec.js

+ 6 - 1
spec/api-session-spec.js

@@ -289,12 +289,17 @@ describe('session module', () => {
       res.end(mockPDF)
       downloadServer.close()
     })
+
+    const isPathEqual = (path1, path2) => {
+      return path.relative(path1, path2) === ''
+    }
     const assertDownload = (event, state, url, mimeType,
                                    receivedBytes, totalBytes, disposition,
                                    filename, port, savePath, isCustom) => {
       assert.equal(state, 'completed')
       assert.equal(filename, 'mock.pdf')
-      assert.equal(savePath, path.join(__dirname, 'fixtures', 'mock.pdf'))
+      assert.ok(path.isAbsolute(savePath))
+      assert.ok(isPathEqual(savePath, path.join(__dirname, 'fixtures', 'mock.pdf')))
       if (isCustom) {
         assert.equal(url, `${protocolName}://item`)
       } else {