-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Added new tests for the FirefoxAndroidExtensionRunner
- Loading branch information
Showing
1 changed file
with
137 additions
and
0 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
tests/unit/test-extension-runners/test.firefox-android.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* @flow */ | ||
|
||
import {assert} from 'chai'; | ||
import {describe, it} from 'mocha'; | ||
import deepcopy from 'deepcopy'; | ||
import sinon from 'sinon'; | ||
|
||
import { | ||
FirefoxAndroidExtensionRunner, | ||
} from '../../../src/extension-runners/firefox-android'; | ||
import type { | ||
FirefoxAndroidExtensionRunnerParams, | ||
} from '../../../src/extension-runners/firefox-android'; | ||
import { | ||
UsageError, | ||
} from '../../../src/errors'; | ||
import { | ||
basicManifest, | ||
getFakeFirefox, | ||
getFakeRemoteFirefox, | ||
// makeSureItFails, | ||
StubChildProcess, | ||
} from '../helpers'; | ||
|
||
// Fake result for client.installTemporaryAddon().then(installResult => ...) | ||
const tempInstallResult = { | ||
addon: {id: 'some-addon@test-suite'}, | ||
}; | ||
|
||
function getFakeADBKit(implementations = {}) { | ||
const fakeADBClient = { | ||
listDevices: sinon.spy(() => { | ||
return []; | ||
}), | ||
...implementations, | ||
}; | ||
|
||
return { | ||
createClient: sinon.spy(() => { | ||
return fakeADBClient; | ||
}), | ||
fakeADBClient, | ||
util: { | ||
readAll: sinon.spy(() => ''), | ||
}, | ||
}; | ||
} | ||
|
||
type PrepareParams = { | ||
params?: Object, | ||
deps?: Object, | ||
fakeFirefoxApp?: Object, | ||
fakeRemoteFirefox?: Object, | ||
fakeADBClient?: Object, | ||
debuggerPort?: number, | ||
} | ||
|
||
function prepareExtensionRunnerParams({ | ||
params, fakeFirefoxApp, fakeRemoteFirefox, fakeADBClient, debuggerPort, | ||
}: PrepareParams = {}) { | ||
const remoteFirefox = getFakeRemoteFirefox({ | ||
installTemporaryAddon: sinon.spy( | ||
() => Promise.resolve(tempInstallResult) | ||
), | ||
...fakeRemoteFirefox, | ||
}); | ||
const firefoxProcess = new StubChildProcess(); | ||
|
||
// $FLOW_IGNORE: allow overriden params for testing purpose. | ||
const runnerParams: FirefoxAndroidExtensionRunnerParams = { | ||
extensions: [{ | ||
sourceDir: '/fake/sourceDir', | ||
manifestData: deepcopy(basicManifest), | ||
}], | ||
keepProfileChanges: false, | ||
browserConsole: false, | ||
startUrl: undefined, | ||
firefoxBinary: 'firefox', | ||
preInstall: false, | ||
firefoxApp: getFakeFirefox({ | ||
run: sinon.spy(() => { | ||
return Promise.resolve({ | ||
debuggerPort, | ||
firefox: firefoxProcess, | ||
}); | ||
}), | ||
...fakeFirefoxApp, | ||
}, debuggerPort), | ||
adb: getFakeADBKit(fakeADBClient), | ||
firefoxClient: () => { | ||
return Promise.resolve(remoteFirefox); | ||
}, | ||
...(params || {}), | ||
}; | ||
|
||
return { | ||
remoteFirefox, | ||
firefoxProcess, | ||
params: runnerParams, | ||
}; | ||
} | ||
|
||
describe('util/extension-runners/firefox-android', () => { | ||
|
||
it('raises an UsageError if no adb binary has been found', async () => { | ||
const {params} = prepareExtensionRunnerParams({ | ||
fakeADBClient: { | ||
listDevices: sinon.spy(() => { | ||
const fakeADBError = new Error('spawn adb'); | ||
// $FLOW_FIXME: reuse ErrorWithCode from other tests | ||
fakeADBError.code = 'ENOENT'; | ||
return Promise.reject(fakeADBError); | ||
}), | ||
}, | ||
}); | ||
|
||
const {adb} = params; | ||
|
||
const runnerInstance = new FirefoxAndroidExtensionRunner(params); | ||
|
||
let actualException; | ||
|
||
try { | ||
await runnerInstance.run(); | ||
} catch (error) { | ||
actualException = error; | ||
} | ||
|
||
sinon.assert.calledOnce(adb.createClient); | ||
sinon.assert.calledOnce(adb.fakeADBClient.listDevices); | ||
|
||
assert.ok(actualException instanceof UsageError); | ||
assert.match(actualException && actualException.message, | ||
/No adb executable has been found/); | ||
}); | ||
|
||
}); |