npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

azure-devops-mocha-reporter

v2.1.2

Published

Run Azure Devops test cases from mocha tests

Downloads

19

Readme

azure-devops-mocha-reporter

Node.js CI CodeQL Node.js Package

Performs ADO (Azure DevOps) Test Run with output from Mocha integration tests, using Test Case IDs from your tests.

Generates reports & executes Test Points.

Developed for use with Cypress.io

Options

| option | type | default | description | | --- | --- | --- | --- | | pat | string | undefined | Pat token from Azure Devops* | | organisation | string | undefined | ORGANISATION from Azure Devops url: https://dev.azure.com/ORGANISATION/PROJECT | | project | string | undefined | PROJECT from Azure Devops url: https://dev.azure.com/ORGANISATION/PROJECT | | planId | number | undefined | Root Azure Test Plan id - reporter will find any Test Cases in this plan and all nested Test Suites | | runName | string | undefined | name given to Azure Test Run |

Usage

Cypress.io

npm i azure-devops-mocha-reporter

Cypress Options

| option | type | default | description | | --- | --- | --- | --- | | shouldAttachScreenShotsToTestResults | boolean | false | if Cypress tests create screenshots and are tagged with an Azure Test Case, attaches screenshot to Azure Test Result |

./package.json

{
  "scripts": {
    "cy:run:azure-report": "cypress run --headless --reporter azure-devops-mocha-reporter --reporterOptions pat={pat},organisation={organisation},project={project},planId={planId},runName={runName},shouldAttachScreenShotsToTestResults={shouldAttachScreenShotsToTestResults} --config defaultCommandTimeout=10000"
  }

cypress.config.js

const { defineConfig } = require('cypress');
const devopsPlugin =
  require("azure-devops-mocha-reporter/dist/cypress/plugin").default;
module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      devopsPlugin(on);
    },
    ... // other props
  },
});

or if you have custom code in setupNodeEvents:


const { defineConfig } = require('cypress');
const { beforeRunHook, afterRunHook } = require('azure-devops-mocha-reporter/dist/cypress');

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      on('before:run', async (details) => {
        console.log('override before:run');
        await beforeRunHook(details);
      });

      on('after:run', async (results) => {
        console.log('override after:run');
        await afterRunHook(results);
      });
    },
    ... //other props
  },
});

your-test.spec.js

it('C123, C321 url should include /users/1.edit', () => {
  cy.url().should('include', '/users/1/edit')
})

Mocha

npm i azure-devops-mocha-reporter

package.json

{
  "scripts": {
    "mocha": "mocha --reporter azure-devops-mocha-reporter --reporterOptions 'pat={pat},organisation={organisation},project={project},planId={planId},runName={runName}'"
  }
}

your-test.spec.js

  it("C123, C321 foo bar", () => {
    expect(true).to.equal(true);
  });

See the "Try it out" section for more info

Explanation

  • Gets all Test Suites from provided Test Plan ID
  • Gets all Test Points from all Test Suites
  • Filters Test Points by Test Case IDs provided in JS tests
  • Creates Azure DevOps Test Run, passing/failing matching Test Points

Test Case tag examples

  • C123
  • TC123
  • C123,C456
  • C123 C456

Try it out

Examples are provided in the ... ./examples directory, allowing you to test this locally against your ADO Test Plan:

  • cd examples/cypress-single-reporter
  • npm i
  • clone .env-sample and rename to .env
  • Replace .env values to match your own*
  • Update test/foo.spec.js with a matching Test Case ID from your plan
  • npm run mochaRun

*You'll need a PAT token with enough permissions. See Azure DevOps' docs to create one