UNPKG

playwright-fluent

Version:
100 lines (99 loc) 3.61 kB
"use strict"; /* eslint-disable @typescript-eslint/no-var-requires */ describe('get-chrome-path', () => { afterEach(() => { jest.resetModules(); }); test('should return X64 windows path on Windows platform', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'Windows_NT', })); jest.mock('fs', () => ({ ...jest.requireActual('fs'), existsSync: (path) => { if (path === 'C:/Program Files/Google/Chrome/Application/chrome.exe') { return true; } return false; }, })); // When const result = require('../get-chrome-path').getChromePath(); // Then expect(result).toBe('C:/Program Files/Google/Chrome/Application/chrome.exe'); }); test('should return X86 windows path on Windows platform', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'Windows_NT', })); jest.mock('fs', () => ({ ...jest.requireActual('fs'), existsSync: (path) => { if (path === 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe') { return true; } return false; }, })); // When const result = require('../get-chrome-path').getChromePath(); // Then expect(result).toBe('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'); }); test('should return default MacOS path on MAcOS platform', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'Darwin', })); // When const result = require('../get-chrome-path').getChromePath(); // Then expect(result).toBe('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'); }); test('should return default Unix path on Unix platform for google stable install', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'Linux', })); jest.mock('which', () => ({ ...jest.requireActual('which'), sync: (input) => input, })); // WHen const result = require('../get-chrome-path').getChromePath(); // Then expect(result).toBe('google-chrome-stable'); }); test('should return default Unix path on Unix platform for google install', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'Linux', })); jest.mock('which', () => ({ ...jest.requireActual('which'), sync: (input) => (input === 'google-chrome' ? 'google-chrome' : ''), })); // When const result = require('../get-chrome-path').getChromePath(); // Then expect(result).toBe('google-chrome'); }); test('should return an error when platform is unknown', () => { // Given jest.mock('os', () => ({ ...jest.requireActual('os'), type: () => 'foo', })); // When // Then const expectedError = new Error(`Platform 'foo' is not yet supported in playwright-fluent. You should supply the path to the Chrome App in the launch options.`); expect(() => require('../get-chrome-path').getChromePath()).toThrow(expectedError); }); });