Skip to content

Commit

Permalink
stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal committed Mar 2, 2019
1 parent f17bcce commit afa46bc
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
12 changes: 10 additions & 2 deletions e2e/__tests__/declarationErrors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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',
);
});
21 changes: 17 additions & 4 deletions packages/jest-circus/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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},
),
);
}

Expand Down
21 changes: 17 additions & 4 deletions packages/jest-jasmine2/src/jasmine/Env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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$) {
Expand Down Expand Up @@ -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},
),
);
}

Expand Down

0 comments on commit afa46bc

Please sign in to comment.