-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resizeTab): Allow resizing of the viewport
- Loading branch information
1 parent
38b3103
commit 379ae96
Showing
6 changed files
with
81 additions
and
1 deletion.
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
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,29 @@ | ||
# `resizeTab(tab, width, height)` | ||
Changes the size of the viewport of a tab | ||
|
||
## Example | ||
```js | ||
import { openBrowser, openTab, resizeTab } from 'puppet-strings' | ||
|
||
async function run() { | ||
const browser = await openBrowser('google-chrome') | ||
const tab = await openTab(browser, 'http://example.com') | ||
await resizeTab(tab, 1200, 800) | ||
} | ||
|
||
run() | ||
``` | ||
|
||
## Parameters | ||
* `tab` ([Tab](../../interface#tab-object)) | ||
* `width` (number) | ||
* `height` (number) | ||
|
||
## Returns | ||
* `promise` (Promise<void>) | ||
|
||
## Details | ||
The size of the viewport is changed, meaning `window.innerWidth` and | ||
`window.innerHeight`. The actual Chrome window will be slightly larger. | ||
|
||
Only the given tab will be affected; other tabs will keep their current size. |
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,10 @@ | ||
/* @flow */ | ||
import type { Tab } from 'puppet-strings' | ||
|
||
export default async function( | ||
{ puppeteer: { page } }: Tab, | ||
width: number, | ||
height: number | ||
): Promise<void> { | ||
await page.setViewport({ width, height }) | ||
} |
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,39 @@ | ||
/* @flow */ | ||
import ava from 'ava' | ||
import { | ||
withChrome, | ||
withDirectory, | ||
writeFile | ||
} from 'puppet-strings/test/helpers' | ||
import { openTab, resizeTab, evalInTab } from 'puppet-strings' | ||
|
||
withChrome() | ||
const test = withDirectory(ava) | ||
|
||
test('resizing the viewport of a tab', async t => { | ||
const { browser } = global | ||
const { directory } = t.context | ||
|
||
const filePath = await writeFile( | ||
directory, | ||
'index.html', | ||
` | ||
<!doctype html> | ||
<meta charset="utf-8"> | ||
` | ||
) | ||
|
||
const tab = await openTab(browser, `file://${filePath}`) | ||
|
||
await resizeTab(tab, 700, 800) | ||
t.deepEqual( | ||
await evalInTab(tab, [], 'return [window.innerWidth, window.innerHeight]'), | ||
[700, 800] | ||
) | ||
|
||
await resizeTab(tab, 900, 700) | ||
t.deepEqual( | ||
await evalInTab(tab, [], 'return [window.innerWidth, window.innerHeight]'), | ||
[900, 700] | ||
) | ||
}) |
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