Skip to content
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

Merged
merged 6 commits into from
Jan 6, 2019
Merged

webdriverio: updating screenshot call to handle backslash #3251

merged 6 commits into from
Jan 6, 2019

Conversation

StephenABoyd
Copy link
Contributor

Proposed changes

Updating the saveScreenshot method to be able to start with a backslash.

Types of changes

  • 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

  • I have read the CONTRIBUTING 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

@codecov
Copy link

codecov bot commented Jan 4, 2019

Codecov Report

Merging #3251 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           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
Impacted Files Coverage Δ
...webdriverio/src/commands/browser/saveScreenshot.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44ad3c8...c1f1528. Read the comment docs.

Copy link
Member

@christian-bromann christian-bromann left a 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('\\')
Copy link
Member

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('\\')

Copy link
Contributor Author

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

Copy link
Member

@christian-bromann christian-bromann left a 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
Copy link
Member

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

Copy link
Contributor Author

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')

Copy link
Member

@christian-bromann christian-bromann Jan 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is fs.existsSync?

Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label Jan 6, 2019
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@christian-bromann christian-bromann merged commit 1a09fb7 into webdriverio:master Jan 6, 2019
yamkay pushed a commit to MoveInc/webdriverio that referenced this pull request Jun 13, 2019
…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
yamkay pushed a commit to MoveInc/webdriverio that referenced this pull request Sep 4, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Polish 💅 PRs that contain improvements on existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants