diff --git a/e2e/__tests__/declarationErrors.test.ts b/e2e/__tests__/declarationErrors.test.ts index 5aa52099d538..f0614b6fa72d 100644 --- a/e2e/__tests__/declarationErrors.test.ts +++ b/e2e/__tests__/declarationErrors.test.ts @@ -13,7 +13,10 @@ it('warns if describe returns a Promise', () => { ]); expect(result.status).toBe(0); - expect(result.stdout).toMatch(/Tests must be defined synchronously/); + expect(result.stdout).toContain('Tests must be defined synchronously'); + expect(result.stdout).toContain( + 'at Object.describe (__tests__/describeReturnPromise.test.js', + ); }); it('warns if describe returns something', () => { @@ -22,5 +25,10 @@ it('warns if describe returns something', () => { ]); expect(result.status).toBe(0); - expect(result.stdout).toMatch(/"describe" callback must not return a value/); + expect(result.stdout).toContain( + '"describe" callback must not return a value', + ); + expect(result.stdout).toContain( + 'at Object.describe (__tests__/describeReturnSomething.test.js', + ); }); diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index eaf0dd64d10a..2280ed522faa 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -6,6 +6,7 @@ */ import {bind as bindEach} from 'jest-each'; +import {formatExecError} from 'jest-message-util'; import {ErrorWithStack, isPromise} from 'jest-util'; import {Global} from '@jest/types'; import { @@ -68,13 +69,25 @@ const _dispatchDescribe = ( // TODO throw in Jest 25 if (isPromise(describeReturn)) { console.warn( - 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' + - 'Returning a value from "describe" will fail the test in a future version of Jest.', + formatExecError( + new Error( + 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' + + 'Returning a value from "describe" will fail the test in a future version of Jest.', + ), + {rootDir: '', testMatch: []}, + {noStackTrace: false}, + ), ); } else if (describeReturn !== undefined) { console.warn( - 'A "describe" callback must not return a value.\n' + - 'Returning a value from "describe" will fail the test in a future version of Jest.', + formatExecError( + new Error( + 'A "describe" callback must not return a value.\n' + + 'Returning a value from "describe" will fail the test in a future version of Jest.', + ), + {rootDir: '', testMatch: []}, + {noStackTrace: false}, + ), ); } diff --git a/packages/jest-jasmine2/src/jasmine/Env.js b/packages/jest-jasmine2/src/jasmine/Env.js index bf48b0346870..5daefd4355e0 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.js +++ b/packages/jest-jasmine2/src/jasmine/Env.js @@ -35,6 +35,7 @@ import queueRunner from '../queueRunner'; import treeProcessor from '../treeProcessor'; import isError from '../isError'; import assertionErrorMessage from '../assertionErrorMessage'; +import {formatExecError} from 'jest-message-util'; import {ErrorWithStack, isPromise} from 'jest-util'; export default function(j$) { @@ -379,13 +380,25 @@ export default function(j$) { // TODO throw in Jest 25: declarationError = new Error if (isPromise(describeReturnValue)) { console.warn( - 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' + - 'Returning a value from "describe" will fail the test in a future version of Jest.', + formatExecError( + new Error( + 'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' + + 'Returning a value from "describe" will fail the test in a future version of Jest.', + ), + {rootDir: '', testMatch: []}, + {noStackTrace: false}, + ), ); } else if (describeReturnValue !== undefined) { console.warn( - 'A "describe" callback must not return a value.\n' + - 'Returning a value from "describe" will fail the test in a future version of Jest.', + formatExecError( + new Error( + 'A "describe" callback must not return a value.\n' + + 'Returning a value from "describe" will fail the test in a future version of Jest.', + ), + {rootDir: '', testMatch: []}, + {noStackTrace: false}, + ), ); }