Skip to content

Commit

Permalink
BUGFIX: fixed report persist. Also added integration test and update …
Browse files Browse the repository at this point in the history
…readme.md.
  • Loading branch information
c0de1ovr committed Sep 7, 2018
1 parent a1036b7 commit 9bf6c25
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ install:
- yarn
script:
- yarn lint
- yarn test
- ./bin/integTest.sh
after_success:
- yarn release
- yarn global add @immowelt/docker-publish
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ docker run -v /path/for/reports:/usr/src/app/lighthouse immowelt/lighthouse-ci:l
* Threshold configuration via config file
* Create node API
* ~~Dockerized images for direct usage in CI pipeline~~
* ***Unit tests are missing!***
* ~~Unit tests are missing!~~
7 changes: 7 additions & 0 deletions bin/integTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# break on all failures
set -e

# Integration Test for report generation
node ./bin/ci.js https://immowelt.de -r
8 changes: 5 additions & 3 deletions src/report.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const Promise = require('bluebird')
const { resolve } = require('path')
const { existsSync, mkdirSync, writeFileSync } = require('fs')
const { existsSync, mkdirSync, writeFile } = require('fs')

const persist = (fileName, fileData, fileDestination) => {
if (!existsSync(fileDestination)) {
mkdirSync(fileDestination)
}
const filePathAndName = resolve(fileDestination, fileName)
writeFileSync(filePathAndName, fileData)
return filePathAndName
return Promise
.promisify(writeFile)(filePathAndName, fileData)
.thenReturn(filePathAndName)
}

module.exports = { persist }
4 changes: 2 additions & 2 deletions src/report.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ describe('report', () => {
existsSync.mockImplementation(() => false)
const persisted = persist('report.html', 'data', '/dest')
expect(mkdirSync.mock.calls.length).toBe(1)
expect(persisted).toBe('/dest/report.html')
persisted.then(data => expect(data).toBe('/dest/report.html'))
})
it('.persist() should persist and skip folder creation because path destination does exist', () => {
existsSync.mockImplementation(() => true)
const persisted = persist('report.html', 'data', '/dest')
expect(mkdirSync.mock.calls.length).toBe(0)
expect(persisted).toBe('/dest/report.html')
persisted.then(data => expect(data).toBe('/dest/report.html'))
})
})

0 comments on commit 9bf6c25

Please sign in to comment.