Skip to content

Commit 9831585

Browse files
committed
only console.warn for now
1 parent 5f5fd06 commit 9831585

9 files changed

Lines changed: 73 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
- `[jest-config]` Print error information on preset normalization error ([#7935](https://github.com/facebook/jest/pull/7935))
1212
- `[jest-haste-map]` Add `skipPackageJson` option ([#7778](https://github.com/facebook/jest/pull/7778))
1313
- `[jest-get-type]` Add `isPrimitive` function ([#7708](https://github.com/facebook/jest/pull/7708))
14-
- `[jest-circus/jest-jasmine2]` Fail test suite if describe returns a Promise ([#7852](https://github.com/facebook/jest/pull/7852))
14+
- `[jest-circus/jest-jasmine2]` Warn if describe returns a value ([#7852](https://github.com/facebook/jest/pull/7852))
1515
- `[jest-util]` Add `isPromise` ([#7852](https://github.com/facebook/jest/pull/7852))
1616

1717
### Fixes
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import runJest from '../runJest';
9+
10+
it('warns if describe returns a Promise', () => {
11+
const result = runJest('declaration-errors', [
12+
'describeReturnPromise.test.js',
13+
]);
14+
15+
expect(result.status).toBe(0);
16+
expect(result.stdout).toMatch(/Tests must be defined synchronously/);
17+
});
18+
19+
it('warns if describe returns something', () => {
20+
const result = runJest('declaration-errors', [
21+
'describeReturnSomething.test.js',
22+
]);
23+
24+
expect(result.status).toBe(0);
25+
expect(result.stdout).toMatch(/"describe" callback must not return a value/);
26+
});

e2e/__tests__/jasmineAsync.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ describe('async jasmine', () => {
8383
expect(json.numPendingTests).toBe(1);
8484
});
8585

86-
it('fails if describe returns a Promise', () => {
87-
const result = runJest('jasmine-async', ['promiseDescribeFails.test.js']);
88-
89-
expect(result.status).toBe(1);
90-
expect(result.stderr).toMatch(/Tests must be defined synchronously/);
91-
});
92-
9386
it('throws when not a promise is returned', () => {
9487
const result = runWithJson('jasmine-async', ['returningValues.test.js']);
9588
const json = result.json;

e2e/jasmine-async/__tests__/promiseDescribeFails.test.js renamed to e2e/declaration-errors/__tests__/describeReturnPromise.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
'use strict';
1010

1111
// TODO after dropping Node 6: Convert to async-await
12-
// describe('Promise describe fails', async () => {
12+
// describe('Promise describe warns', async () => {
13+
// it('t', () => {});
1314
// await Promise.resolve();
14-
// it('not declared', () => {});
1515
// });
1616

17-
describe('Promise describe fails', () =>
18-
Promise.resolve().then(() => {
19-
it('not declared', () => {});
20-
}));
17+
describe('Promise describe warns', () => {
18+
it('t', () => {});
19+
return Promise.resolve();
20+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
*/
8+
9+
'use strict';
10+
11+
describe('describe return warns', () => {
12+
it('t', () => {});
13+
return 42;
14+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"jest": {
3+
"testEnvironment": "node"
4+
}
5+
}

packages/jest-circus/src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ const _dispatchDescribe = (
6464
name: 'start_describe_definition',
6565
});
6666
const describeReturn = blockFn();
67+
68+
// TODO throw in Jest 25
6769
if (isPromise(describeReturn)) {
68-
throw new ErrorWithStack(
69-
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
70-
describeFn,
70+
console.warn(
71+
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
72+
'Returning a value from "describe" will fail the test in a future version of Jest.',
73+
);
74+
} else if (describeReturn !== undefined) {
75+
console.warn(
76+
'A "describe" callback must not return a value.\n' +
77+
'Returning a value from "describe" will fail the test in a future version of Jest.',
7178
);
7279
}
80+
7381
dispatch({blockName, mode, name: 'finish_describe_definition'});
7482
};
7583

packages/jest-jasmine2/src/jasmine/Env.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,16 @@ export default function(j$) {
376376
declarationError = e;
377377
}
378378

379+
// TODO throw in Jest 25: declarationError = new Error
379380
if (isPromise(describeReturnValue)) {
380-
declarationError = new Error(
381-
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.',
381+
console.warn(
382+
'Returning a Promise from "describe" is not supported. Tests must be defined synchronously.\n' +
383+
'Returning a value from "describe" will fail the test in a future version of Jest.',
384+
);
385+
} else if (describeReturnValue !== undefined) {
386+
console.warn(
387+
'A "describe" callback must not return a value.\n' +
388+
'Returning a value from "describe" will fail the test in a future version of Jest.',
382389
);
383390
}
384391

yarn.lock

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,14 +1784,6 @@
17841784
"@types/prop-types" "*"
17851785
csstype "^2.2.0"
17861786

1787-
"@types/readable-stream@^2.3.0":
1788-
version "2.3.1"
1789-
resolved "https://registry.yarnpkg.com/@types/readable-stream/-/readable-stream-2.3.1.tgz#59d458b51c84c585caea06e296e2225057c9ea8e"
1790-
integrity sha512-Dp6t95yGEOm2y669mQrSl0kUg+oL+bJEiCWMyDv0Yq+FcVvjzNRLTAqJks2LDBYYrazZXNI7lZXq3lp7MOvt4A==
1791-
dependencies:
1792-
"@types/node" "*"
1793-
safe-buffer "*"
1794-
17951787
"@types/resolve@*":
17961788
version "0.0.8"
17971789
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
@@ -11516,7 +11508,7 @@ rxjs@^6.4.0:
1151611508
dependencies:
1151711509
tslib "^1.9.0"
1151811510

11519-
safe-buffer@*, safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
11511+
safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
1152011512
version "5.1.2"
1152111513
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
1152211514
integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==

0 commit comments

Comments
 (0)