-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from rmachado-studocu/add-screen-name-generato…
…r-in-options feat: adds option `screenshotNameGenerator` to customize screenshots' name
- Loading branch information
Showing
7 changed files
with
123 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ tmp/* | |
yarn-error.log | ||
test.js | ||
.vscode | ||
test/screenshots | ||
test/*.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,6 @@ module.exports = { | |
|
||
// CODE BASED | ||
RULE_SEPARATOR: '-#-', | ||
|
||
SCREENSHOT_NAME_GENERATOR: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const fs = require('fs-extra'); | ||
const path = require('path'); | ||
const crypto = require('crypto'); | ||
|
||
const rootDir = path.join(__dirname, '..', '..'); | ||
const helpers = require('./../helpers.js'); | ||
const Rule = require(path.join(rootDir, 'lib/classes/Rule.class')); | ||
|
||
const urls = [ | ||
'http://localhost:8000/test/data/test.html?1', | ||
'http://localhost:8000/test/data/test.html?2', | ||
'http://localhost:8000/test/data/test.html?3', | ||
'http://localhost:8000/test/data/test.html?4', | ||
]; | ||
|
||
describe('Screenshots', () => { | ||
describe('Check screenshot names', () => { | ||
test('Check that the normal screenshots were generated with the name based on the URL', async () => { | ||
const files = await fs.readdir(path.join(__dirname, '..', 'screenshots', 'normal')); | ||
expect( | ||
urls.every(url => { | ||
const expectedScreenName = url.replace(/[^\w\s]/gi, '_') + '.png'; | ||
return files.includes(expectedScreenName); | ||
}) | ||
).toBeTruthy(); | ||
}); | ||
|
||
test('Check that the screenshots with a name generator function were generated with the name as the URL SHA1 hashed', async () => { | ||
const files = await fs.readdir(path.join(__dirname, '..', 'screenshots', 'withFunction')); | ||
expect( | ||
urls.every(url => { | ||
const sha1 = crypto.createHash('sha1'); | ||
sha1.update(url); | ||
const expectedScreenName = `${sha1.digest('hex')}.png`; | ||
return files.includes(expectedScreenName); | ||
}) | ||
).toBeTruthy(); | ||
}); | ||
}); | ||
}); |