simple tests
This commit is contained in:
Родитель
8a699c94f2
Коммит
f5d08ca3da
|
@ -0,0 +1,109 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import { stub } from 'sinon';
|
||||
import { expect } from 'chai';
|
||||
import { Quality } from '.';
|
||||
import { DarwinFirefoxBrowserFinder } from './darwinFirefox';
|
||||
|
||||
describe('darwin: firefox', () => {
|
||||
const lsreturn = [
|
||||
'/Applications/Firefox.app',
|
||||
' /Applications/Firefox Developer Edition.app',
|
||||
' /Applications/Firefox Nightly.app',
|
||||
];
|
||||
|
||||
const setup = (options: { lsreturn: string[]; pathsThatExist: string[] }) => {
|
||||
const execa = {
|
||||
command: stub().resolves({ stdout: options.lsreturn.join('\n') }),
|
||||
};
|
||||
|
||||
const fs = {
|
||||
access: (path: string) => {
|
||||
if (!options.pathsThatExist.includes(path)) {
|
||||
throw new Error('no access here!');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const finder = new DarwinFirefoxBrowserFinder(
|
||||
{ FIREFOX_PATH: '/custom/path' },
|
||||
fs as any,
|
||||
execa as any,
|
||||
);
|
||||
|
||||
return finder;
|
||||
};
|
||||
|
||||
it('does not return when paths dont exist', async () => {
|
||||
expect(
|
||||
await setup({
|
||||
lsreturn,
|
||||
pathsThatExist: [],
|
||||
}).findAll(),
|
||||
).to.be.empty;
|
||||
});
|
||||
|
||||
it('returns and orders correctly', async () => {
|
||||
expect(
|
||||
await setup({
|
||||
lsreturn,
|
||||
pathsThatExist: [
|
||||
'/custom/path/Contents/MacOS/firefox',
|
||||
'/Applications/Firefox.app/Contents/MacOS/firefox',
|
||||
'/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox',
|
||||
'/Applications/Firefox Nightly.app/Contents/MacOS/firefox',
|
||||
],
|
||||
}).findAll(),
|
||||
).to.deep.equal([
|
||||
{
|
||||
path: '/custom/path/Contents/MacOS/firefox',
|
||||
quality: Quality.Custom,
|
||||
},
|
||||
{
|
||||
path: '/Applications/Firefox Nightly.app/Contents/MacOS/firefox',
|
||||
quality: Quality.Nightly,
|
||||
},
|
||||
{
|
||||
path: '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox',
|
||||
quality: Quality.Dev,
|
||||
},
|
||||
{
|
||||
path: '/Applications/Firefox.app/Contents/MacOS/firefox',
|
||||
quality: Quality.Stable,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('finds well-known paths', async () => {
|
||||
const s = setup({
|
||||
lsreturn,
|
||||
pathsThatExist: [
|
||||
'/custom/path/Contents/MacOS/firefox',
|
||||
'/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox',
|
||||
'/Applications/Firefox.app/Contents/MacOS/firefox',
|
||||
],
|
||||
});
|
||||
|
||||
let calls = 0;
|
||||
expect(
|
||||
await s.findWhere((exe) => {
|
||||
calls++;
|
||||
return exe.quality === Quality.Stable;
|
||||
}),
|
||||
).to.deep.equal({
|
||||
path: '/Applications/Firefox.app/Contents/MacOS/firefox',
|
||||
quality: Quality.Stable,
|
||||
});
|
||||
|
||||
expect(calls).to.equal(1);
|
||||
|
||||
expect(
|
||||
await s.findWhere((exe) => {
|
||||
calls++;
|
||||
return exe.quality === Quality.Canary;
|
||||
}),
|
||||
).to.be.undefined;
|
||||
});
|
||||
});
|
|
@ -0,0 +1,61 @@
|
|||
/*---------------------------------------------------------
|
||||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
|
||||
import { expect } from 'chai';
|
||||
import { Quality } from '.';
|
||||
import { WindowsFirefoxBrowserFinder } from './windowsFirefox';
|
||||
|
||||
describe('windows: firefox', () => {
|
||||
const test = (pathsThatExist: string[]) => {
|
||||
const fs = {
|
||||
access: (path: string) => {
|
||||
if (!pathsThatExist.includes(path)) {
|
||||
throw new Error('no access here!');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
return new WindowsFirefoxBrowserFinder(
|
||||
{
|
||||
LOCALAPPDATA: '%APPDATA%',
|
||||
PROGRAMFILES: '%PROGRAMFILES%',
|
||||
'PROGRAMFILES(X86)': '%PROGRAMFILES(X86)%',
|
||||
FIREFOX_PATH: 'C:\\custom\\path\\firefox.exe',
|
||||
},
|
||||
fs as any,
|
||||
).findAll();
|
||||
};
|
||||
|
||||
it('does not return when paths dont exist', async () => {
|
||||
expect(await test([])).to.be.empty;
|
||||
});
|
||||
|
||||
it('returns and orders correctly', async () => {
|
||||
expect(
|
||||
await test([
|
||||
'C:\\custom\\path\\firefox.exe',
|
||||
'%PROGRAMFILES%\\Firefox Developer Edition\\firefox.exe',
|
||||
'%PROGRAMFILES%\\Firefox Nightly\\firefox.exe',
|
||||
'%APPDATA%\\Mozilla Firefox\\firefox.exe',
|
||||
]),
|
||||
).to.deep.equal([
|
||||
{
|
||||
path: 'C:\\custom\\path\\firefox.exe',
|
||||
quality: Quality.Custom,
|
||||
},
|
||||
{
|
||||
path: '%APPDATA%\\Mozilla Firefox\\firefox.exe',
|
||||
quality: Quality.Stable,
|
||||
},
|
||||
{
|
||||
path: '%PROGRAMFILES%\\Firefox Developer Edition\\firefox.exe',
|
||||
quality: Quality.Dev,
|
||||
},
|
||||
{
|
||||
path: '%PROGRAMFILES%\\Firefox Nightly\\firefox.exe',
|
||||
quality: Quality.Nightly,
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -29,11 +29,7 @@ export class WindowsFirefoxBrowserFinder implements IBrowserFinder {
|
|||
type: Quality.Nightly,
|
||||
},
|
||||
{
|
||||
name: `${sep}Mozilla${sep}Firefox${sep}firefox.exe`,
|
||||
type: Quality.Beta,
|
||||
},
|
||||
{
|
||||
name: `${sep}Mozilla${sep}Firefox${sep}firefox.exe`,
|
||||
name: `${sep}Mozilla Firefox${sep}firefox.exe`,
|
||||
type: Quality.Stable,
|
||||
},
|
||||
];
|
||||
|
|
Загрузка…
Ссылка в новой задаче