-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webdriverio: updating screenshot call to handle backslash #3251
webdriverio: updating screenshot call to handle backslash #3251
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3251 +/- ##
=======================================
Coverage 96.44% 96.44%
=======================================
Files 131 131
Lines 2814 2814
Branches 607 607
=======================================
Hits 2714 2714
Misses 90 90
Partials 10 10
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to add a test?
@@ -32,7 +32,7 @@ export default async function saveScreenshot (filepath) { | |||
throw new Error('saveScreenshot expects a filepath of type string and ".png" file ending') | |||
} | |||
|
|||
const absoluteFilepath = filepath.startsWith('/') | |||
const absoluteFilepath = filepath.startsWith('/') | filepath.startsWith('\\') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be a proper OR
const absoluteFilepath = filepath.startsWith('/') || filepath.startsWith('\\')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, somehow I missed that it wasn't, will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments on the unit tests
|
||
it('should not change filepath if starts with forward slash', async () => { | ||
const fs = require('fs').default | ||
fs.existsSync = () => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since fs
is already a mock, let's use mockReturnValue
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this? Whenever I try that it tells me that mockReturnValue
is not a function
const fs = require('fs').default
fs.existsSync.mockReturnValue(false)
spy = jest.spyOn(fs, 'writeFileSync')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is fs.existsSync
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to use mockReturnValue
it needs to be jest.fn()
. Just updated it in the fs.js
mock.
|
||
it('should not change filepath if starts with backslash slash', async () => { | ||
const fs = require('fs').default | ||
fs.existsSync = () => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
||
it('should change filepath if does not start with forward or back slash', async () => { | ||
const fs = require('fs').default | ||
fs.existsSync = () => true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@@ -1,4 +1,4 @@ | |||
const fs = jest.genMockFromModule('fs') | |||
fs.writeFileSync = jest.fn() | |||
fs.writeFileSync = (path, data, options) => path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can then revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
…o#3251) ## Proposed changes Updating the ```saveScreenshot``` method to be able to start with a backslash. ## Types of changes [//]: # (What types of changes does your code introduce to WebdriverIO?) [//]: # (_Put an `x` in the boxes that apply_) - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist [//]: # (_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._) - [x] I have read the [CONTRIBUTING](https://github.com/webdriverio/webdriverio/blob/master/CONTRIBUTING.md) doc - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added necessary documentation (if appropriate) ## Further comments I wanted to introduce this because when trying to save a screenshot to a network location the filepath starts with ```\\\\``` (Two backslashes and two escape characters). Before this, it would just append the server path to the current directory. ### Reviewers: @webdriverio/technical-committee
…o#3251) ## Proposed changes Updating the ```saveScreenshot``` method to be able to start with a backslash. ## Types of changes [//]: # (What types of changes does your code introduce to WebdriverIO?) [//]: # (_Put an `x` in the boxes that apply_) - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist [//]: # (_Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._) - [x] I have read the [CONTRIBUTING](https://github.com/webdriverio/webdriverio/blob/master/CONTRIBUTING.md) doc - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added necessary documentation (if appropriate) ## Further comments I wanted to introduce this because when trying to save a screenshot to a network location the filepath starts with ```\\\\``` (Two backslashes and two escape characters). Before this, it would just append the server path to the current directory. ### Reviewers: @webdriverio/technical-committee
Proposed changes
Updating the
saveScreenshot
method to be able to start with a backslash.Types of changes
Checklist
Further comments
I wanted to introduce this because when trying to save a screenshot to a network location the filepath starts with
\\\\
(Two backslashes and two escape characters). Before this, it would just append the server path to the current directory.Reviewers: @webdriverio/technical-committee