UNPKG

@vscode/js-debug-browsers

Version:

Browser launch and discovery logic used in VS Code's JavaScript Debugger

92 lines 4.12 kB
"use strict"; /*--------------------------------------------------------- * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); const darwinChrome_1 = require("./darwinChrome"); const sinon_1 = require("sinon"); const chai_1 = require("chai"); describe('darwin: chrome', () => { const lsreturn = [ ' /Applications/Google Chrome.app', ' /Users/foo/Applications (Parallels)/{f5861500-b6d1-4929-b85d-d920e2656184} Applications.localized/Google Chrome.app', '/Applications/Google Chrome.app', ' /Applications/Google Chrome Canary.app', ]; const setup = (options) => { const execa = { command: (0, sinon_1.stub)().resolves({ stdout: options.lsreturn.join('\n') }), }; const fs = { access: (path) => { if (!options.pathsThatExist.includes(path)) { throw new Error('no access here!'); } }, }; const finder = new darwinChrome_1.DarwinChromeBrowserFinder({ CHROME_PATH: '/custom/path' }, fs, execa); return finder; }; it('does not return when paths dont exist', async () => { (0, chai_1.expect)(await setup({ lsreturn, pathsThatExist: [], }).findAll()).to.be.empty; }); it('returns and orders correctly', async () => { (0, chai_1.expect)(await setup({ lsreturn, pathsThatExist: [ '/custom/path/Contents/MacOS/Google Chrome', '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', '/Users/foo/Applications (Parallels)/{f5861500-b6d1-4929-b85d-d920e2656184} Applications.localized/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', ], }).findAll()).to.deep.equal([ { path: '/custom/path/Contents/MacOS/Google Chrome', quality: "custom" /* Custom */, }, { path: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', quality: "canary" /* Canary */, }, { path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', quality: "stable" /* Stable */, }, { path: '/Users/foo/Applications (Parallels)/{f5861500-b6d1-4929-b85d-d920e2656184} Applications.localized/Google Chrome.app/Contents/MacOS/Google Chrome', quality: "dev" /* Dev */, }, ]); }); it('finds well-known paths', async () => { const s = setup({ lsreturn, pathsThatExist: [ '/custom/path/Contents/MacOS/Google Chrome', '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', '/Users/foo/Applications (Parallels)/{f5861500-b6d1-4929-b85d-d920e2656184} Applications.localized/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', ], }); let calls = 0; (0, chai_1.expect)(await s.findWhere((exe) => { calls++; return exe.quality === "stable" /* Stable */; })).to.deep.equal({ path: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', quality: "stable" /* Stable */, }); (0, chai_1.expect)(calls).to.equal(1); (0, chai_1.expect)(await s.findWhere((exe) => { calls++; return exe.quality === "dev" /* Dev */; })).to.deep.equal({ path: '/Users/foo/Applications (Parallels)/{f5861500-b6d1-4929-b85d-d920e2656184} Applications.localized/Google Chrome.app/Contents/MacOS/Google Chrome', quality: "dev" /* Dev */, }); }); }); //# sourceMappingURL=darwinChrome.test.js.map