Skip to content

A Node.js testing framework using Mocha, Chai, and Sinon. Modular, scalable, and ready for integration with React and MongoDB. Ideal for robust JavaScript application testing.

Notifications You must be signed in to change notification settings

Indefy/testing-framework

Repository files navigation

Testing Framework

Installation

To set up the project locally, follow these steps:

  1. Clone the repository
git clone https://github.com/yourusername/projectname.git
  1. Navigate to the project directory cd projectname

Install dependencies

npm install
  1. Usage To use the project, follow these steps:

Start the application

npm start
  1. Testing Running Tests To run all tests, use the following command:
npm test
  1. To run a specific test, use the following command:
npx mocha tests/unit/test_example.mjs

Testing Framework

We use the following tools for testing:

Mocha: A feature-rich JavaScript test framework running on Node.js. Chai: A BDD / TDD assertion library. Sinon: A library used to create spies, stubs, and mocks for JavaScript. Writing Tests All test files are located in the tests directory. Unit tests are in the tests/unit subdirectory.

Here's an example of a unit test for the fetchDataWrapper function:

import { expect } from 'chai';
import sinon from 'sinon';
import utilsWrapper from '../../framework/utilsWrapper.js';
import logger from '../../framework/logger.mjs';

describe('Advanced Test Suite', () => {
  it('should fetch data from API and log the result', async () => {
    const fetchDataStub = sinon.stub(utilsWrapper, 'fetchDataWrapper').resolves({ data: 'mocked data' });
    const logSpy = sinon.spy(logger, 'info');

    const result = await utilsWrapper.fetchDataWrapper('sample-endpoint');
    logger.info(`Fetched data: ${JSON.stringify(result)}`);

    expect(result).to.eql({ data: 'mocked data' });
    expect(fetchDataStub.calledOnce).to.be.true;
    expect(logSpy.calledOnce).to.be.true;
    expect(logSpy.calledWith('Fetched data: {"data":"mocked data"}')).to.be.true;

    fetchDataStub.restore();
    logSpy.restore();
  });
});

Project Structure

Here's an overview of the project structure:

  • /projectname
    • /framework
    • config.mjs <----- # Configuration module
      • logger.mjs <----- # Logger setup using Winston
      • utilsWrapper.js <----- # Wrapper for utility functions
    • /tests
      • /unit <----- # Unit tests
        • test_example.mjs <----- # Example test file
    • package.json <----- # Project dependencies and scripts
    • README.md <----- # Project documentation
    • .gitignore <----- # Git ignore file

Contributing

We welcome contributions! Here's how you can contribute:

Fork the repository.

  • Create a new branch: git checkout -b feature/your-feature-name.
  • Make your changes and commit them: git commit -m 'Add some feature'.
  • Push to the branch: git push origin feature/your-feature-name.
  • Submit a pull request.
  • License

This project is licensed under the MIT License.

This version includes more detailed instructions and clearer formatting. It also includes

About

A Node.js testing framework using Mocha, Chai, and Sinon. Modular, scalable, and ready for integration with React and MongoDB. Ideal for robust JavaScript application testing.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published