Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mocked-mocha-runner

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mocked-mocha-runner

Helps to test Mocha reporters by simulating a test run without actually running Mocha

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

mocked-mocha-runner

This is a small class to mock the Mocha runner to help test custom reporters. Simply pass this into the constructor of a Mocha custom reporter and test the reporter without needing to run Mocha.

Installation

$ npm i mocked-mocha-runner --save-dev

Usage Example

Below is an example that instantiates the MockedMochaRunner, creates some reporterOptions, and passes the options and the mockedRunner into the reporter.

The reporter's events are triggered by calling Mocha runner events using the mockedRunner methods.

 it('should report some results', () => {
        const mockedRunner = new MockedMochaRunner();
        const reporterOptionsWrapper = {
            "reporterOptions": {
                "option1": "value1",
                "option2": "value2",
                "logger": console
            }
        }
        const reporter = new TestEsmReporter(mockedRunner, reporterOptionsWrapper);

        const mochaEvents = [
            EVENT_RUN_BEGIN,
            EVENT_SUITE_BEGIN,
            EVENT_TEST_PASS,
            EVENT_TEST_PASS,
            EVENT_TEST_FAIL,
            EVENT_TEST_PASS,
            EVENT_TEST_PENDING,
            EVENT_SUITE_END,
            EVENT_RUN_END
        ];
        mochaEvents.forEach((mochaEvent) => {
            mockedRunner.fireEvent(mochaEvent);
        });

        expect(mockedRunner.hasEnded).to.equal(true);
    });

License

Copyright (c) James Mortensen, 2023 MIT License

FAQs

Package last updated on 03 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc