mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
b7033196d2
The `waitUntilCalled` utility now has a timeout. It will now throw an error if the stub is not called enough times, rather than blocking forever. The return type had to be changed to a function, so that we could throw when the timeout is triggered. I tried returning an error that rejected first, but if you don't handle the error synchronously Node.js will consider it to be an unhandled Promise rejected (even if it _is_ handled later on). I worked around this by resolving in the timeout case as well, so that there is never a "deferred" Promise exception in the timeout case. The returned function re-throws the error if it's given. That way there is never any unhandled Promise rejection.
59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
const { strict: assert } = require('assert')
|
|
const { By, Key } = require('selenium-webdriver')
|
|
const waitUntilCalled = require('../lib/wait-until-called')
|
|
const { withFixtures } = require('./helpers')
|
|
|
|
/**
|
|
* WARNING: These tests must be run using a build created with `yarn build:test:metrics`, so that it has
|
|
* the correct Segment host and write keys set. Otherwise this test will fail.
|
|
*/
|
|
describe('Segment metrics', function () {
|
|
this.timeout(0)
|
|
|
|
it('should send first three Page metric events upon fullscreen page load', async function () {
|
|
const ganacheOptions = {
|
|
accounts: [
|
|
{
|
|
secretKey:
|
|
'0x7C9529A67102755B7E6102D6D950AC5D5863C98713805CEC576B945B15B71EAC',
|
|
balance: 25000000000000000000,
|
|
},
|
|
],
|
|
}
|
|
await withFixtures(
|
|
{
|
|
fixtures: 'metrics-enabled',
|
|
ganacheOptions,
|
|
title: this.test.title,
|
|
mockSegment: true,
|
|
},
|
|
async ({ driver, segmentStub }) => {
|
|
const threeSegmentEventsReceived = waitUntilCalled(segmentStub, null, {
|
|
callCount: 3,
|
|
})
|
|
await driver.navigate()
|
|
|
|
const passwordField = await driver.findElement(By.css('#password'))
|
|
await passwordField.sendKeys('correct horse battery staple')
|
|
await passwordField.sendKeys(Key.ENTER)
|
|
|
|
await threeSegmentEventsReceived()
|
|
|
|
assert.ok(segmentStub.called, 'Segment should receive metrics')
|
|
|
|
const firstSegmentEvent = segmentStub.getCall(0).args[0]
|
|
assert.equal(firstSegmentEvent.name, 'Home')
|
|
assert.equal(firstSegmentEvent.context.page.path, '/')
|
|
|
|
const secondSegmentEvent = segmentStub.getCall(1).args[0]
|
|
assert.equal(secondSegmentEvent.name, 'Unlock Page')
|
|
assert.equal(secondSegmentEvent.context.page.path, '/unlock')
|
|
|
|
const thirdSegmentEvent = segmentStub.getCall(2).args[0]
|
|
assert.equal(thirdSegmentEvent.name, 'Home')
|
|
assert.equal(thirdSegmentEvent.context.page.path, '/')
|
|
},
|
|
)
|
|
})
|
|
})
|