Skip to content

Commit

Permalink
prevent system tests from running in CI if set to run exclusively wit…
Browse files Browse the repository at this point in the history
…h it.only(...)
  • Loading branch information
brian-mann committed Feb 18, 2022
1 parent a4d8c1c commit 233dec0
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions system-tests/lib/system-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const snapshot = require('snap-shot-it')
import { SpawnOptions } from 'child_process'
import { expect } from './spec_helper'

const isCi = require('is-ci')

require('mocha-banner').register()
const chalk = require('chalk').default
const _ = require('lodash')
Expand Down Expand Up @@ -525,7 +527,7 @@ const copy = function () {
}
}

const getMochaItFn = function (only, skip, browser, specifiedBrowser) {
const getMochaItFn = function (title, only, skip, browser, specifiedBrowser) {
// if we've been told to skip this test
// or if we specified a particular browser and this
// doesn't match the one we're currently trying to run...
Expand All @@ -535,6 +537,12 @@ const getMochaItFn = function (only, skip, browser, specifiedBrowser) {
}

if (only) {
if (isCi) {
// fixes the problem where systemTests can accidentally by skipped using systemTests.it.only(...)
// https://github.com/cypress-io/cypress/pull/20276
throw new Error(`the system test: "${chalk.yellow(title)}" has been set to run with an it.only() which is not allowed in CI environments.\n\nPlease remove the it.only()`)
}

return it.only
}

Expand Down Expand Up @@ -605,7 +613,7 @@ const localItFn = function (title: string, opts: ItOptions) {
const browsersToTest = getBrowsers(options.browser)

const browserToTest = function (browser) {
const mochaItFn = getMochaItFn(options.only, options.skip, browser, specifiedBrowser)
const mochaItFn = getMochaItFn(title, options.only, options.skip, browser, specifiedBrowser)

const testTitle = `${title} [${browser}]`

Expand Down

0 comments on commit 233dec0

Please sign in to comment.