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

allure-decorators

Package Overview
Dependencies
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allure-decorators

Write your tests in a Java-like annotation-driven manner via JS decorators.

  • 2.15.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Allure Decorators

Testdeck decorators integration for Allure framework

Allure Report logo


Installation based on allure-mocha reporter

npm i allure-js-commons allure-decorators allure-mocha @testdeck/mocha mocha @types/mocha mocha-multi-reporters source-map-support --save-dev

or via yarn:

yarn add allure-js-commons allure-decorators allure-mocha @testdeck/mocha mocha @types/mocha mocha-multi-reporters source-map-support --dev

Usage

Create the following .mocharc.json:

{
  "require": "source-map-support/register",
  "spec": "./src/tests/**/*.js",
  "reporter": "mocha-multi-reporters",
  "reporter-option": "configFile=reporterConfig.json"
}

And the reporterConfig.json:

{
  "reporterEnabled": "allure-mocha, list",
  "allureMochaReporterOptions": {
    "resultsDir": "./allure-results"
  }
}

Note that there are known issues with Mocha 8+ parallel test execution. So try to avoid using this flag at the moment.

Your tsconfig.json must include the following compiler options:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true
  }
}

Now your test may look like the following:

import { suite, test } from '@testdeck/mocha'
import {
  assignPmsUrl,
  assignTmsUrl,
  data,
  decorate,
  description,
  epic,
  feature,
  issue,
  owner,
  severity,
  story,
  tag,
  testCaseId
} from 'allure-decorators'
import { ContentType, Severity } from 'allure-js-commons'
import { allure, MochaAllure } from 'allure-mocha/runtime'
// the other imports

@suite
class AuthorizationTests {

  public static testData = (): User[] => {
    return [User.dummy(), User.dummy1()]
  }

  @issue('11')
  @testCaseId('10')
  @severity(Severity.BLOCKER)
  @epic('User Authentication')
  @feature('Login')
  @story('Authorization')
  @owner('skorol')
  @tag('smoke')
  @description('Basic authorization test.')
  @data(AuthorizationTests.testData)
  @data.naming(user => `${user} should be able to sign`)
  @test
  public userShouldBeAbleToSignIn(user: User) {
    open(LoginPage)
      .loginWith(user)
      .select(ProfilePage)

    verifyThat(atProfilePage)
      .fullNameIs(user.fullName)
      .usernameIs(user.username)
  }

  public before() {
    decorate<MochaAllure>(allure)
    assignTmsUrl(process.env.TMS_URL)
    assignPmsUrl(process.env.PMS_URL)
  }

  public after() {
    allure.attachment('Test attachment', 'test attachment content', ContentType.TEXT)
  }
}

You should pay attention to the following line:

decorate<MochaAllure>(allure)

To be able to use decorators, you have to call decorate function explicitly and set your reporter's instance in before hook. This was done intentionally to allow clients decide which reporter they want to use with decorators module.

Note that data is a testdeck specific extension which allows injecting parameters into Allure scope. At the moment, testdeck supports only Mocha, Jest and Jasmine frameworks. If you want to add the other integration, feel free to contact Allure team to discuss the potential design options.

ToDo
  • Update mocha-allure2-example with new allure-decorators dependency.
  • Explore potential data decorator extension for the other frameworks.

Keywords

FAQs

Package last updated on 08 Apr 2024

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