Skip to content

Failed step causes previous steps to be marked "pending" as well as "passed" #34

@ETMayberry

Description

@ETMayberry

When running the following test suite, the failed middle step causes all tests, including previously passed tests, to be marked "pending". This behavior seems unintentional, or at least ambiguous. Am I using this library correctly? Also, I can fix the JSON output programmatically by checking for test.pass && test.pending then setting test.pending = false, but fixing the mochawesome HTML report in the same way is annoying because the test results are embedded and url-encoded.

    describe("Steps Sample", function () {

        // This step succeeds
        step('1 should equal 1', function () {
            expect(1).to.equal(1);
        });

        // This step should fail
        step('2 should equal 2', function () {
            expect(2).to.equal(0);
        });

        // This step is skipped due to an earlier failure
        step('3 should equal 3', function () {
            expect(3).to.equal(3);
        });

    });

Here is the JSON result:

{
  "stats": {
    "suites": 1,
    "tests": 3,
    "passes": 1,
    "pending": 1,
    "failures": 1,
    "start": "2021-04-16T00:57:36.700Z",
    "end": "2021-04-16T00:57:36.714Z",
    "duration": 14,
    "testsRegistered": 3,
    "passPercent": 50,
    "pendingPercent": 33.33333333333333,
    "other": 0,
    "hasOther": false,
    "skipped": 0,
    "hasSkipped": false
  },
  "results": [
    {
      "uuid": "e0be6bcc-2868-429e-b26c-7395209fee91",
      "title": "",
      "fullFile": "",
      "file": "",
      "beforeHooks": [],
      "afterHooks": [],
      "tests": [],
      "suites": [
        {
          "uuid": "55ff9b71-7e98-4549-9298-a82a56f26087",
          "title": "Steps Sample",
          "fullFile": "C:\\projects\\test\\index.ts",
          "file": "\\test\\index.ts",
          "beforeHooks": [],
          "afterHooks": [],
          "tests": [
            {
              "title": "1 should equal 1",
              "fullTitle": "Steps Sample 1 should equal 1",
              "timedOut": false,
              "duration": 1,
              "state": "passed",
              "speed": "fast",
              "pass": true,               // expected
              "fail": false,
              "pending": true,            // not expected
              "context": null,
              "code": "",
              "err": {},
              "uuid": "0b90cbec-2050-4932-b689-40e7544d4f7e",
              "parentUUID": "55ff9b71-7e98-4549-9298-a82a56f26087",
              "isHook": false,
              "skipped": false
            },
            {
              "title": "2 should equal 2",
              "fullTitle": "Steps Sample 2 should equal 2",
              "timedOut": false,
              "duration": 0,
              "state": "failed",
              "speed": null,
              "pass": false,
              "fail": true,
              "pending": false,
              "context": null,
              "code": "",
              "err": {
                "message": "AssertionError: expected 2 to equal 0",
                "estack": "AssertionError: expected 2 to equal 0\n    at Context.<anonymous> (test\\index.ts:22:22)\n    at Context.sync (node_modules\\mocha-steps\\lib\\step.js:29:24)\n    at processImmediate (internal/timers.js:456:21)\n    at process.topLevelDomainCallback (domain.js:137:15)",
                "diff": "- 2\n+ 0\n"
              },
              "uuid": "bf09e5ec-ce3c-48df-b88e-b75be50131b3",
              "parentUUID": "55ff9b71-7e98-4549-9298-a82a56f26087",
              "isHook": false,
              "skipped": false
            },
            {
              "title": "3 should equal 3",
              "fullTitle": "Steps Sample 3 should equal 3",
              "timedOut": false,
              "duration": 0,
              "state": "pending",
              "speed": null,
              "pass": false,
              "fail": false,
              "pending": true,
              "context": null,
              "code": "",
              "err": {},
              "uuid": "b598469d-daa7-40d5-a3dd-b65542318b8c",
              "parentUUID": "55ff9b71-7e98-4549-9298-a82a56f26087",
              "isHook": false,
              "skipped": false
            }
          ],
          "suites": [],
          "passes": [
            "0b90cbec-2050-4932-b689-40e7544d4f7e"
          ],
          "failures": [
            "bf09e5ec-ce3c-48df-b88e-b75be50131b3"
          ],
          "pending": [
            "0b90cbec-2050-4932-b689-40e7544d4f7e",          // not expected
            "b598469d-daa7-40d5-a3dd-b65542318b8c"
          ],
          "skipped": [],
          "duration": 1,
          "root": false,
          "rootEmpty": false,
          "_timeout": 2000
        }
      ],
      "passes": [],
      "failures": [],
      "pending": [],
      "skipped": [],
      "duration": 0,
      "root": true,
      "rootEmpty": true,
      "_timeout": 2000
    }
  ],
  "meta": {
    "mocha": {
      "version": "8.3.2"
    },
    "mochawesome": {
      "options": {
        "quiet": false,
        "reportFilename": "test-results",
        "saveHtml": true,
        "saveJson": true,
        "consoleReporter": "spec",
        "useInlineDiffs": false,
        "code": false
      },
      "version": "6.2.2"
    },
    "marge": {
      "options": {
        "reportDir": "artifacts",
        "reportFilename": "test-results",
        "code": "false",
        "charts": "true",
        "reportTitle": "Tests",
        "reportPageTitle": "Tests",
        "saveJson": "true",
        "html": "true"
      },
      "version": "5.2.0"
    }
  }
}

And here is my list of package versions in the project:

  "dependencies": {
    "chai": "^4.3.4",
    "dotenv": "^8.2.0",
    "mocha": "^8.3.2",
    "mocha-steps": "^1.3.0",
    "mochawesome": "^6.2.2",
    "replace": "^1.2.1",
    "supertest": "^6.1.3",
    "ts-node": "^9.1.1",
    "typescript": "^4.2.4"
  },
  "devDependencies": {
    "@types/chai": "^4.2.16",
    "@types/mocha": "^8.2.2",
    "@types/node": "^14.14.37",
    "@types/supertest": "^2.0.11"
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions