Skip to content

Commit

Permalink
feat: drop old Jest integrations
Browse files Browse the repository at this point in the history
BREAKING CHANGE: please upgrade to jest-circus
https://wix.github.io/Detox/docs/guide/jest/
  • Loading branch information
noomorph committed Apr 1, 2022
1 parent 85883d2 commit e3a6e85
Show file tree
Hide file tree
Showing 39 changed files with 204 additions and 620 deletions.
3 changes: 1 addition & 2 deletions detox/local-cli/templates/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ const firstTestContent = require('./firstTestContent');
const runnerConfig = `{
"maxWorkers": 1,
"testEnvironment": "./environment",
"testRunner": "jest-circus/runner",
"testTimeout": 120000,
"testRegex": "\\\\.e2e\\\\.js$",
"reporters": ["detox/runners/jest/streamlineReporter"],
"reporters": ["detox/runners/jest-circus/reporter"],
"verbose": true
}
`;
Expand Down
9 changes: 4 additions & 5 deletions detox/runners/jest-circus/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const SpecReporterCircus = require('../jest/SpecReporterCircus');
const WorkerAssignReporterCircus = require('../jest/WorkerAssignReporterCircus');

const DetoxCircusEnvironment = require('./environment');
const SpecReporter = require('./listeners/SpecReporter');
const WorkerAssignReporter = require('./listeners/WorkerAssignReporter');

module.exports = {
DetoxCircusEnvironment,
SpecReporter: SpecReporterCircus,
WorkerAssignReporter: WorkerAssignReporterCircus,
SpecReporter,
WorkerAssignReporter,
};
2 changes: 1 addition & 1 deletion detox/runners/jest-circus/listeners/DetoxCoreListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
onTestDone,
onRunDescribeFinish,
} = require('../../integration').lifecycle;
const { getFullTestName, hasTimedOut } = require('../../jest/utils');
const { getFullTestName, hasTimedOut } = require('../utils');

const RETRY_TIMES = Symbol.for('RETRY_TIMES');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const chalk = require('chalk').default;

const log = require('../../src/utils/logger').child();

const { traceln } = require('./utils/stdout');
const log = require('../../../src/utils/logger').child();
const { traceln } = require('../utils/stdout');

const RESULT_SKIPPED = chalk.yellow('SKIPPED');
const RESULT_FAILED = chalk.red('FAIL');
Expand All @@ -16,12 +15,50 @@ class SpecReporter {
this._suitesDesc = '';
}

onSuiteStart({ description }) {
run_describe_start(event) {
if (event.describeBlock.parent !== undefined) {
this._onSuiteStart({
description: event.describeBlock.name,
});
}
}

run_describe_finish(event) {
if (event.describeBlock.parent !== undefined) {
this._onSuiteEnd();
}
}

test_start(event) {
const { test } = event;
this._onTestStart({
description: test.name,
invocations: test.invocations,
});
}

test_done(event) {
const { test } = event;
const testInfo = {
description: test.name,
invocations: test.invocations,
};
this._onTestEnd(testInfo, test.errors.length ? 'failed' : 'success');
}

test_skip(event) {
const testInfo = {
description: event.test.name,
};
this._onTestEnd(testInfo, 'skipped');
}

_onSuiteStart({ description }) {
this._suites.push({ description });
this._regenerateSuitesDesc();
}

onSuiteEnd() {
_onSuiteEnd() {
this._suites.pop();
this._regenerateSuitesDesc();

Expand All @@ -30,11 +67,11 @@ class SpecReporter {
}
}

onTestStart({ description, invocations = 1 }) {
_onTestStart({ description, invocations = 1 }) {
this._traceTest({ description, invocations });
}

onTestEnd({ description, invocations = 1 }, result) {
_onTestEnd({ description, invocations = 1 }, result) {
let status;
switch (result) {
case 'skipped': status = RESULT_SKIPPED; break;
Expand Down Expand Up @@ -68,4 +105,6 @@ class SpecReporter {
}
}

module.exports = SpecReporter;
module.exports = process.env.DETOX_REPORT_SPECS === 'true'
? SpecReporter
: class {};
33 changes: 33 additions & 0 deletions detox/runners/jest-circus/listeners/WorkerAssignReporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');

const chalk = require('chalk').default;
const _ = require('lodash');

const log = require('../../../src/utils/logger').child();

class WorkerAssignReporter {
constructor({ detox, env }) {
this._detox = detox;
this._env = env;
}

run_start() {
log.info({ event: 'WORKER_ASSIGN' }, `${this._formatTestName()} is assigned to ${this._formatDeviceName()}`);
}

_formatDeviceName() {
const deviceName = _.attempt(() => this._detox.device.name);
const formattedDeviceName = _.isError(deviceName)
? chalk.redBright('undefined')
: chalk.blueBright(deviceName);

return formattedDeviceName;
}

_formatTestName() {
const testName = path.basename(this._env.testPath);
return chalk.whiteBright(testName);
}
}

module.exports = WorkerAssignReporter;
1 change: 1 addition & 0 deletions detox/runners/jest-circus/reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./reporters/DetoxReporter');
16 changes: 16 additions & 0 deletions detox/runners/jest-circus/reporters/DetoxReporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const DetoxStreamlineJestReporter = require('./DetoxStreamlineJestReporter');
const FailingTestsReporter = require('./FailingTestsReporter');

class DetoxReporter extends DetoxStreamlineJestReporter {
constructor(globalConfig) {
super(globalConfig);
this._failingTestsReporter = new FailingTestsReporter();
}

async onRunComplete(contexts, results) {
await super.onRunComplete(contexts, results);
await this._failingTestsReporter.onRunComplete(contexts, results);
}
}

module.exports = DetoxReporter;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-nocheck
const { VerboseReporter: JestVerboseReporter } = require('@jest/reporters'); // eslint-disable-line node/no-extraneous-require

const DetoxRuntimeError = require('../../src/errors/DetoxRuntimeError');
const DetoxRuntimeError = require('../../../src/errors/DetoxRuntimeError');

class DetoxStreamlineJestReporter extends JestVerboseReporter {

Expand Down Expand Up @@ -30,7 +29,7 @@ class DetoxStreamlineJestReporter extends JestVerboseReporter {
*
* 1. Jest suite-level lifecycle logging, typically done by the super-class' impl.
* Note: Jest does not notify spec-level events to reporters.
* 2. Jasmine real-time, spec-level lifecycle logging.
* 2. Jest Circus real-time, spec-level lifecycle logging.
* 3. User in-test logging (e.g. for debugging).
*
* It's easy to see that this cannot be done while stderr and stdout are not of equal priority.
Expand Down Expand Up @@ -67,7 +66,7 @@ class DetoxStreamlineJestReporter extends JestVerboseReporter {
_assertConfig() {
if (!this._isVerboseEnabled()) {
// Non-verbose mode makes Jest swizzle 'console' with a buffered output impl, which prevents
// user and detox' jasmine-lifecycle logs from showing in real time.
// from showing logs (from the user and Detox) in real time.
throw new DetoxRuntimeError({
message: 'Cannot run properly unless Jest is in verbose mode',
hint: 'See https://jestjs.io/docs/en/configuration#verbose-boolean for more details',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');

const { saveLastFailedTests } = require('../../src/utils/lastFailedTests');
const { saveLastFailedTests } = require('../../../src/utils/lastFailedTests');

class FailingTestsReporter {
async onRunComplete(_contexts, { testResults }) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
60 changes: 0 additions & 60 deletions detox/runners/jest/DetoxAdapterCircus.js

This file was deleted.

81 changes: 0 additions & 81 deletions detox/runners/jest/DetoxAdapterImpl.js

This file was deleted.

Loading

0 comments on commit e3a6e85

Please sign in to comment.