Skip to content

chore: bump mocha to 8.0.1 #31495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"methods": "1.1.2",
"mime": "^3.0.0",
"minimatch": "3.1.2",
"mocha": "7.2.0",
"mocha": "8.0.1",
"multer": "1.4.4",
"ordinal": "1.0.3",
"react-15.6.1": "npm:[email protected]",
Expand Down
880 changes: 0 additions & 880 deletions packages/driver/patches/mocha+7.2.0.dev.patch

This file was deleted.

85 changes: 85 additions & 0 deletions packages/driver/patches/mocha+8.0.1.dev.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
diff --git a/node_modules/mocha/assets/growl/error.png b/node_modules/mocha/assets/growl/error.png
deleted file mode 100644
index a07a1ba..0000000
Binary files a/node_modules/mocha/assets/growl/error.png and /dev/null differ
diff --git a/node_modules/mocha/assets/growl/ok.png b/node_modules/mocha/assets/growl/ok.png
deleted file mode 100644
index b3623a5..0000000
Binary files a/node_modules/mocha/assets/growl/ok.png and /dev/null differ
diff --git a/node_modules/mocha/lib/runner.js b/node_modules/mocha/lib/runner.js
index 22e7bb9..9143aa3 100644
--- a/node_modules/mocha/lib/runner.js
+++ b/node_modules/mocha/lib/runner.js
@@ -758,9 +758,42 @@ Runner.prototype.runTests = function(suite, fn) {
}
self.emit(constants.EVENT_TEST_END, test);
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
- } else if (err) {
+ } else if (err || test.hasAttemptPassed) {
+ if(test.hasAttemptPassed){
+ // Currently, to get passing attempts to rerun in mocha,
+ // we signal to mocha that we MIGHT need to retry a passed test attempt.
+ // If the test is run and there are no errors present, we assume a
+ // passed test attempt(set in ./driver/src/cypress/runner.ts)
+ test.state = STATE_PASSED
+ } else {
+ // Otherwise, we can assume the test attempt failed as 'err' would have to be present here.
+ test.state = STATE_FAILED
+ }
+ // Evaluate if the test should continue based on 'calculateTestStatus'.
+ // This is a custom method added by Cypress in ./driver/src/cypress/mocha.ts
+ var testStatusInfo = test.calculateTestStatus()
+
+ if(!testStatusInfo.shouldAttemptsContinue){
+ // If the test has met the exit condition, we need to grab the metadata from
+ // 'calculateTestStatus' in order to display and interpret the test outerStatus correctly.
+ test._cypressTestStatusInfo = testStatusInfo
+
+ if(testStatusInfo.attempts > 1) {
+ // If the test has been run AT LEAST twice (i.e. we are retrying), and the exit condition is met,
+ // modify mocha '_retries' to be the max retries made in order to possibly short circuit a suite
+ // if a hook has failed on every attempt (which we may not know at this stage of the test run).
+
+ // We will need the original retries to 'reset' the possible retries
+ // if the test attempt passes and fits the exit condition, BUT an 'afterEach' hook fails.
+ // In this case, we need to know how many retries we can reapply to satisfy the config.
+ test._maxRetries = test._retries
+ test._retries = test._currentRetry
+ }
+ }
+
var retry = test.currentRetry();
- if (retry < test.retries()) {
+ // requeue the test if we have retries and haven't satisfied our retry configuration.
+ if (retry < test.retries() && testStatusInfo.shouldAttemptsContinue) {
var clonedTest = test.clone();
clonedTest.currentRetry(retry + 1);
tests.unshift(clonedTest);
@@ -770,8 +803,25 @@ Runner.prototype.runTests = function(suite, fn) {
// Early return + hook trigger so that it doesn't
// increment the count wrong
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
- } else {
- self.fail(test, err);
+ } else if(testStatusInfo.outerStatus === STATE_FAILED) {
+ // However, if we have fit the exit condition and the outerStatus of the test is marked as 'failed'.
+
+ // We need to check the state of the last test attempt.
+ // In this case, if the strategy is "detect-flake-but-always-fail",
+ // has an outerStatus of 'failed', but the last test attempt passed, we still want to call the 'fail' hooks on the test, but keep
+ // the test attempt marked as passed.
+
+ // However, since the test might have afterEach/after hooks that mutate the state of the test
+ // (from passed to failed), the hooks might actually affect how many retries are actually run in order to satisfy the config.
+ // In this case, we want to delay failing as long as possible to make sure the test is settled, all attempts are run, and hooks
+ // can no longer retry. For this edge case specifically, the failing of the test in the runner lives in ./driver/src/cypress/runner.ts
+ if(test.state === STATE_FAILED){
+ self.fail(test, err)
+ }
+ } else if (testStatusInfo?.outerStatus === STATE_PASSED){
+ // There is no case where a test can 'pass' and the last test attempt be a failure,
+ // meaning we can assume a 'passed' outerStatus has a final passed test attempt.
+ self.emit(constants.EVENT_TEST_PASS, test);
}
self.emit(constants.EVENT_TEST_END, test);
return self.hookUp(HOOK_TYPE_AFTER_EACH, next);
10 changes: 4 additions & 6 deletions packages/server/lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const { stackUtils } = require('@packages/errors')
// mocha-* is used to allow us to have later versions of mocha specified in devDependencies
// and prevents accidentally upgrading this one
// TODO: look into upgrading this to version in driver
const Mocha = require('mocha-7.2.0')
const mochaReporters = require('mocha-7.2.0/lib/reporters')
const mochaCreateStatsCollector = require('mocha-7.2.0/lib/stats-collector')
const Mocha = require('mocha-8.0.1')
const mochaReporters = require('mocha-8.0.1/lib/reporters')
const mochaCreateStatsCollector = require('mocha-8.0.1/lib/stats-collector')
const mochaColor = mochaReporters.Base.color
const mochaSymbols = mochaReporters.Base.symbols

Expand All @@ -16,7 +16,7 @@ const { overrideRequire } = require('./override_require')

// override calls to `require('mocha*')` when to always resolve with a mocha we control
// otherwise mocha will be resolved from project's node_modules and might not work with our code
const customReporterMochaPath = path.dirname(require.resolve('mocha-7.2.0'))
const customReporterMochaPath = path.dirname(require.resolve('mocha-8.0.1'))

const buildAttemptMessage = (currentRetry, totalRetries) => {
return `(Attempt ${currentRetry} of ${totalRetries})`
Expand Down Expand Up @@ -413,8 +413,6 @@ class Reporter {
// eslint-disable-next-line no-console
console.log(finalMessaging, test.title, test.duration)
}

this.runner.ignoreLeaks = true
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"mime-db": "1.45.0",
"minimatch": "3.1.2",
"minimist": "1.2.8",
"mocha-7.2.0": "npm:mocha@7.2.0",
"mocha-8.0.1": "npm:mocha@8.0.1",
"mocha-junit-reporter": "2.2.0",
"mocha-teamcity-reporter": "3.0.0",
"morgan": "1.9.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/binary/binary-cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const getDependencyPathsToKeep = async (buildAppDir) => {
'node_modules/webpack-dev-server/lib/Server.js',
'node_modules/html-webpack-plugin-4/index.js',
'node_modules/html-webpack-plugin-5/index.js',
'node_modules/mocha-7.2.0/index.js',
'node_modules/mocha-8.0.1/index.js',
'packages/server/node_modules/webdriver/build/index.js',
// dependencies needed for geckodriver when running firefox in the binary
'node_modules/pump/index.js',
Expand Down
4 changes: 2 additions & 2 deletions tooling/v8-snapshot/src/setup/force-no-rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export default [
'node_modules/stream-parser/node_modules/debug/src/node.js',
'node_modules/@cypress/commit-info/node_modules/debug/src/node.js',
'node_modules/@cypress/get-windows-proxy/node_modules/debug/src/node.js',
'node_modules/mocha-7.2.0/node_modules/debug/src/node.js',
'node_modules/mocha-8.0.1/node_modules/debug/src/node.js',
'node_modules/tcp-port-used/node_modules/debug/src/node.js',
'packages/data-context/node_modules/debug/src/node.js',
'packages/graphql/node_modules/debug/src/node.js',
'packages/net-stubbing/node_modules/debug/src/node.js',
'packages/server/node_modules/mocha/node_modules/debug/src/node.js',
'node_modules/minimatch/minimatch.js',
'node_modules/mocha-7.2.0/node_modules/glob/node_modules/minimatch/minimatch.js',
'node_modules/mocha-8.0.1/node_modules/glob/node_modules/minimatch/minimatch.js',
'packages/data-context/node_modules/minimatch/minimatch.js',
'packages/network/node_modules/minimatch/minimatch.js',
'packages/server/node_modules/glob/node_modules/minimatch/minimatch.js',
Expand Down
Loading
Loading