Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('Should use headless chrome only when needed', async () => {
(fs.statSync as any).mockImplementation((_) => true);
(os.platform as any).mockImplementation(() => 'win32');
(opn as any).mockImplementation(async (url, opts) => { })
await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")
expect(opn.mock.calls.length).toBe(1);
expect(opn.mock.calls[0][0]).toBe("http://theurl")
expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })
await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)
expect(opn.mock.calls.length).toBe(2);
expect(opn.mock.calls[1][0]).toBe("http://theurl")
expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})
test('Should use headless chrome only when needed', async () => {
(fs.statSync as any).mockImplementation((_) => true);
(os.platform as any).mockImplementation(() => 'win32');
(opn as any).mockImplementation(async (url, opts) => { })
await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")
expect(opn.mock.calls.length).toBe(1);
expect(opn.mock.calls[0][0]).toBe("http://theurl")
expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })
await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)
expect(opn.mock.calls.length).toBe(2);
expect(opn.mock.calls[1][0]).toBe("http://theurl")
expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})