-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BugDiver
committed
Mar 4, 2020
1 parent
cdf37ce
commit 388a287
Showing
5 changed files
with
34 additions
and
22 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
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 |
---|---|---|
@@ -1,33 +1,47 @@ | ||
import { existsSync, unlinkSync } from 'fs'; | ||
import { Screenshot } from '../../src/screenshot/Screenshot'; | ||
import { Util } from '../../src/utils/Util'; | ||
|
||
describe('Screenshot', () => { | ||
|
||
let screenshotFile: string; | ||
|
||
describe('.capture', () => { | ||
|
||
afterEach(() => { | ||
if (existsSync(screenshotFile)) { | ||
unlinkSync(screenshotFile); | ||
} | ||
}) | ||
|
||
it('should capture screen shot and return the buffer', async () => { | ||
process.env.gauge_screenshots_dir = ""; | ||
Util.readFileBuffer = jest.fn().mockReturnValue(new ArrayBuffer(10)); | ||
Util.spawn = jest.fn(); | ||
let data = await Screenshot.capture(); | ||
expect(data.length).toBe(10); | ||
screenshotFile = await Screenshot.capture(); | ||
expect(screenshotFile.endsWith('.png')).toBe(true); | ||
}) | ||
|
||
it('should return empty buffer if fails to capture screenshot', async () => { | ||
Util.readFileBuffer = jest.fn().mockReturnValue(new ArrayBuffer(10)); | ||
Util.spawn = jest.fn().mockImplementation(() => { throw new Error('faild to spawn') }); | ||
Util.spawn = jest.fn().mockImplementation(() => { throw new Error('failed to spawn') }); | ||
console.log = jest.fn(); | ||
let data = await Screenshot.capture(); | ||
expect(data.length).toBe(0); | ||
let file = await Screenshot.capture(); | ||
expect(file).toBe(""); | ||
}) | ||
|
||
it('should capture screenshot using customscreengrabber', async () => { | ||
Screenshot.setCustomScreenGrabber(() => { return new Uint8Array(new ArrayBuffer(10))}) | ||
let data = await Screenshot.capture(); | ||
expect(data.length).toBe(10); | ||
it('should capture screenshot using custom screen grabber and write data to file', async () => { | ||
process.env.gauge_screenshots_dir = process.cwd(); | ||
Screenshot.setCustomScreenGrabber(() => { return new Uint8Array(new ArrayBuffer(10)) }) | ||
screenshotFile = await Screenshot.capture(); | ||
expect(screenshotFile.endsWith('png')).toBeTruthy(); | ||
}) | ||
|
||
it('should capture screenshot using async customscreengrabber', async () => { | ||
Screenshot.setCustomScreenGrabber(async () => { return new Uint8Array(new ArrayBuffer(5))}) | ||
let data = await Screenshot.capture(); | ||
expect(data.length).toBe(5); | ||
it('should capture screenshot using async custom screen grabber and write data to file', async () => { | ||
process.env.gauge_screenshots_dir = ""; | ||
Screenshot.setCustomScreenGrabber(async () => { return new Uint8Array(new ArrayBuffer(5)) }) | ||
screenshotFile = await Screenshot.capture(); | ||
expect(screenshotFile.endsWith('png')).toBeTruthy(); | ||
}) | ||
}) | ||
}) |