PuppeteerNode.test.ts (2287B)
1 /** 2 * @license 3 * Copyright 2024 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 import fs from 'node:fs'; 7 import {tmpdir} from 'node:os'; 8 import {join} from 'node:path'; 9 import {describe, it, beforeEach, afterEach} from 'node:test'; 10 11 import expect from 'expect'; 12 13 import {PuppeteerNode} from './PuppeteerNode.js'; 14 15 describe('PuppeteerNode', () => { 16 let tmpDir: string; 17 18 beforeEach(() => { 19 tmpDir = fs.mkdtempSync(join(tmpdir(), 'puppeteer-unit-test-')); 20 }); 21 22 afterEach(() => { 23 fs.rmdirSync(tmpDir); 24 }); 25 26 describe('executablePath()', () => { 27 it('returns the default path', () => { 28 const puppeteer = new PuppeteerNode({ 29 isPuppeteerCore: false, 30 configuration: { 31 cacheDirectory: tmpDir, 32 }, 33 }); 34 expect(puppeteer.executablePath()).toContain('chrome'); 35 }); 36 37 it('returns the default path based on the default browser configuration', () => { 38 const puppeteer = new PuppeteerNode({ 39 isPuppeteerCore: false, 40 configuration: { 41 cacheDirectory: tmpDir, 42 defaultBrowser: 'firefox', 43 }, 44 }); 45 expect(puppeteer.executablePath().toLowerCase()).toContain('firefox'); 46 }); 47 48 it('returns the default path for a given Chrome channel', () => { 49 const puppeteer = new PuppeteerNode({ 50 isPuppeteerCore: false, 51 configuration: { 52 cacheDirectory: tmpDir, 53 }, 54 }); 55 expect(puppeteer.executablePath('chrome').toLowerCase()).toContain( 56 'chrome', 57 ); 58 }); 59 60 it('returns the default path for chrome-headless-shell', () => { 61 const puppeteer = new PuppeteerNode({ 62 isPuppeteerCore: false, 63 configuration: { 64 cacheDirectory: tmpDir, 65 }, 66 }); 67 expect( 68 puppeteer 69 .executablePath({ 70 headless: 'shell', 71 }) 72 .toLowerCase(), 73 ).toContain('chrome-headless-shell'); 74 }); 75 }); 76 77 describe('defaultArgs()', () => { 78 it('returns the default args without arguments', () => { 79 const puppeteer = new PuppeteerNode({ 80 isPuppeteerCore: false, 81 configuration: { 82 cacheDirectory: tmpDir, 83 }, 84 }); 85 expect(puppeteer.defaultArgs()).toBeInstanceOf(Array); 86 }); 87 }); 88 });