• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / 8f1d960f-a1b2-42b3-89d4-5e0b2b4f8e83

pending completion
8f1d960f-a1b2-42b3-89d4-5e0b2b4f8e83

Pull #2854

circleci

Joey Zhou
run tests
Pull Request #2854: MNTOR-741

282 of 1394 branches covered (20.23%)

Branch coverage included in aggregate %.

91 of 91 new or added lines in 7 files covered. (100.0%)

959 of 3823 relevant lines covered (25.09%)

4.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/e2e/utils/helpers.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
import { request } from '@playwright/test'
6

7
export const defaultScreenshotOpts = {
×
8
  animations: 'disabled',
9
  maxDiffPixelRatio: 0.04
10
}
11

12
export const ENV_URLS = {
×
13
  dev: 'https://fx-breach-alerts.herokuapp.com',
14
  stage: 'https://stage.firefoxmonitor.nonprod.cloudops.mozgcp.net'
15
}
16

17
export const setEnvVariables = async (email) => {
×
18
  process.env.E2E_TEST_ENV = process.env.E2E_TEST_ENV || 'dev'
×
19
  process.env.E2E_TEST_ACCOUNT_EMAIL_FREE = email
×
20
  process.env.E2E_TEST_BASE_URL = ENV_URLS[process.env.E2E_TEST_ENV] || 'https://stage.firefoxmonitor.nonprod.cloudops.mozgcp.net'
×
21
}
22

23
export const getVerificationCode = async (testEmail, page, attempts = 10) => {
×
24
  if (attempts === 0) {
×
25
    throw new Error('Unable to retrieve restmail data')
×
26
  }
27

28
  const context = await request.newContext()
×
29
  const res = await context.get(
×
30
    `http://restmail.net/mail/${testEmail}`,
31
    {
32
      failOnStatusCode: false
33
    }
34
  )
35
  const resJson = await res.json()
×
36
  if (resJson.length) {
×
37
    const verificationCode = resJson[0].headers['x-verify-short-code']
×
38
    return verificationCode
×
39
  }
40

41
  await page.waitForTimeout(1000)
×
42
  return getVerificationCode(testEmail, page, attempts - 1)
×
43
}
44

45
const enterYourEmail = async (page) => {
×
46
  const maybeEmailInput = 'input[name="email"]'
×
47
  await page.waitForSelector(maybeEmailInput, { timeout: 2000 })
×
48
  const signInButton = page.locator('#submit-btn')
×
49
  await page.locator(maybeEmailInput).fill(process.env.E2E_TEST_ACCOUNT_EMAIL_FREE)
×
50
  await signInButton.click({ force: true })
×
51
  await page.waitForTimeout(500)
×
52
  await checkAuthState(page)
×
53
}
54

55
const enterYourPassword = async (page) => {
×
56
  await page.locator('#password').fill(process.env.E2E_TEST_ACCOUNT_PASSWORD)
×
57

58
  // using force here due to fxa issue with playwright
59
  await page.locator('#submit-btn').click()
×
60
  await page.waitForTimeout(500)
×
61
  await checkAuthState(page)
×
62
}
63

64
export const checkAuthState = async (page) => {
×
65
  try {
×
66
    const authStateTitleString = await page.locator('h1').textContent({ timeout: 4000 })
×
67
    const checkIfTitleContains = (potentialTitle) => {
×
68
      return authStateTitleString?.includes(potentialTitle)
×
69
    }
70

71
    switch (true) {
×
72
      case checkIfTitleContains('Enter your email'):
73
        await enterYourEmail(page)
×
74
        break
×
75
      case checkIfTitleContains('Enter your password'):
76
        await enterYourPassword(page)
×
77
        break
×
78
      // case checkIfTitleContains('Set your password'):
79
      //   await setYourPassword(page)
80
      //   break
81
      // case checkIfTitleContains('Enter confirmation code'):
82
      //   await enterConfirmationCode(page)
83
      //   break
84
      // case checkIfTitleContains('Sign in'):
85
      //   await signIn(page)
86
      //   break
87
      default:
88
        break
×
89
    }
90
  } catch {}
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc