ChromeLauncher.test.ts (1766B)
1 /** 2 * @license 3 * Copyright 2023 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 import {describe, it} from 'node:test'; 7 8 import expect from 'expect'; 9 10 import {getFeatures, removeMatchingFlags} from './ChromeLauncher.js'; 11 12 describe('getFeatures', () => { 13 it('returns an empty array when no options are provided', () => { 14 const result = getFeatures('--foo'); 15 expect(result).toEqual([]); 16 }); 17 18 it('returns an empty array when no options match the flag', () => { 19 const result = getFeatures('--foo', ['--bar', '--baz']); 20 expect(result).toEqual([]); 21 }); 22 23 it('returns an array of values when options match the flag', () => { 24 const result = getFeatures('--foo', ['--foo=bar', '--foo=baz']); 25 expect(result).toEqual(['bar', 'baz']); 26 }); 27 28 it('does not handle whitespace', () => { 29 const result = getFeatures('--foo', ['--foo bar', '--foo baz ']); 30 expect(result).toEqual([]); 31 }); 32 33 it('handles equals sign around the flag and value', () => { 34 const result = getFeatures('--foo', ['--foo=bar', '--foo=baz ']); 35 expect(result).toEqual(['bar', 'baz']); 36 }); 37 }); 38 39 describe('removeMatchingFlags', () => { 40 it('empty', () => { 41 const a: string[] = []; 42 expect(removeMatchingFlags(a, '--foo')).toEqual([]); 43 }); 44 45 it('with one match', () => { 46 const a: string[] = ['--foo=1', '--bar=baz']; 47 expect(removeMatchingFlags(a, '--foo')).toEqual(['--bar=baz']); 48 }); 49 50 it('with multiple matches', () => { 51 const a: string[] = ['--foo=1', '--foo=2', '--bar=baz']; 52 expect(removeMatchingFlags(a, '--foo')).toEqual(['--bar=baz']); 53 }); 54 55 it('with no matches', () => { 56 const a: string[] = ['--foo=1', '--bar=baz']; 57 expect(removeMatchingFlags(a, '--baz')).toEqual(['--foo=1', '--bar=baz']); 58 }); 59 });