Description
🚀 Feature Proposal
A change to the way that malformed tests are handled (e.g. don't have expected arguments) by running as much of the code as possible to provide the user as much useful information about what went wrong and how to fix it.
Motivation
This is dealing with an edge case, where tests have not been implemented correctly. This typically is due to missing arguments, or using the wrong argument types. Currently the tests stop executing at the first error that is encountered in a test file. I think it would be more helpful to the user if they had feedback on all potential issues in a single test run, rather than only being directed to the first issue.
Example
Here are some examples of malformed tests:
describe("tests with missing callbacks", () => {
test("test with missing callback")
// make sure that multiple tests are processed.
test("test with missing callback 2")
})
describe("describe with missing callback")
// make sure that multiple describes are processed.
describe("describe with missing callback 2")
// this doesn't emit anything. Probably acceptable for now.
describe("describe no tests", () => {
})
// confirm that can still process valid tests.
describe("describe with callback and tests", () => {
it("test should pass", () => {})
it("test should pass 2", () => {})
})
This is the current output:
yarn run v1.19.1
$ jest
FAIL src/__tests__/newTest.test.ts
● Test suite failed to run
Missing second argument. It must be a callback function.
5 | })
6 |
> 7 | describe("describe with missing callback")
| ^
8 |
9 | // make sure that multiple describes are processed.
10 | describe("describe with missing callback 2")
at Env.describe (../../Documents/source/jest/packages/jest-jasmine2/build/jasmine/Env.js:390:19)
at Object.describe (src/__tests__/newTest.test.ts:7:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 6.592s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Pitch
Notice how the execution of the tests is halted at the first error in the file. Personally I would like it if it ran as much of the code as possible, highlighting all the areas that there are issues. Obviously this excludes failures in syntax (missing braces/parens etc).
Here is the output with my proposed changes applied (same test code):
yarn run v1.19.1
$ jest
FAIL src/__tests__/newTest.test.ts
tests with missing callbacks
× test with missing callback (4ms)
× test with missing callback 2 (11ms)
describe with missing callback
× encountered a declaration exception (1ms)
describe with missing callback 2
× encountered a declaration exception (1ms)
describe with callback and tests
√ test should pass
√ test should pass 2
● tests with missing callbacks › test with missing callback
Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.
1 | describe("tests with missing callbacks", () => {
> 2 | test("test with missing callback")
| ^
3 | // make sure that multiple tests are processed.
4 | test("test with missing callback 2")
5 | })
at Env.it (../../Documents/source/jest/packages/jest-jasmine2/build/jasmine/Env.js:586:21)
at Suite.test (src/__tests__/newTest.test.ts:2:5)
at Object.describe (src/__tests__/newTest.test.ts:1:1)
● tests with missing callbacks › test with missing callback 2
Missing second argument. It must be a callback function. Perhaps you want to use `test.todo` for a test placeholder.
2 | test("test with missing callback")
3 | // make sure that multiple tests are processed.
> 4 | test("test with missing callback 2")
| ^
5 | })
6 |
7 | describe("describe with missing callback")
at Env.it (../../Documents/source/jest/packages/jest-jasmine2/build/jasmine/Env.js:586:21)
at Suite.test (src/__tests__/newTest.test.ts:4:5)
at Object.describe (src/__tests__/newTest.test.ts:1:1)
● describe with missing callback › encountered a declaration exception
Missing second argument. It must be a callback function.
5 | })
6 |
> 7 | describe("describe with missing callback")
| ^
8 |
9 | // make sure that multiple describes are processed.
10 | describe("describe with missing callback 2")
at Env.describe (../../Documents/source/jest/packages/jest-jasmine2/build/jasmine/Env.js:391:21)
at Object.describe (src/__tests__/newTest.test.ts:7:1)
● describe with missing callback 2 › encountered a declaration exception
Missing second argument. It must be a callback function.
8 |
9 | // make sure that multiple describes are processed.
> 10 | describe("describe with missing callback 2")
| ^
11 |
12 | // this doesn't emit anything. Probably acceptable for now.
13 | describe("describe no tests", () => {
at Env.describe (../../Documents/source/jest/packages/jest-jasmine2/build/jasmine/Env.js:391:21)
at Object.describe (src/__tests__/newTest.test.ts:10:1)
Test Suites: 1 failed, 1 total
Tests: 4 failed, 2 passed, 6 total
Snapshots: 0 total
Time: 5.242s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.