All Projects → sskorol → ts-test-decorators

sskorol / ts-test-decorators

Licence: Apache-2.0 license
Write your tests in a Java-like annotation-driven manner via JS decorators

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to ts-test-decorators

mocha-allure2-example
Allure 2 Mocha examples
Stars: ✭ 18 (-51.35%)
Mutual labels:  mocha, decorators, allure
qa-automation-base
There are basic projects for automation frameworks based on Kotlin/Java and TypeScript for the backend, frontend, and mobile.
Stars: ✭ 45 (+21.62%)
Mutual labels:  mocha, allure
Tvrboreact
Dream starter project: React, Redux, React Router, Webpack
Stars: ✭ 13 (-64.86%)
Mutual labels:  mocha, decorators
TvrboReact
Dream starter project: React, Redux, React Router, Webpack
Stars: ✭ 13 (-64.86%)
Mutual labels:  mocha, decorators
Testdeck
Object oriented testing
Stars: ✭ 206 (+456.76%)
Mutual labels:  mocha, decorators
final-form-calculate
Decorator for calculating field values based on other field values in 🏁 Final Form
Stars: ✭ 111 (+200%)
Mutual labels:  decorators
parse-server-test-runner
A tool for programmatically starting Parse Server
Stars: ✭ 18 (-51.35%)
Mutual labels:  mocha
restgoose
Model-driven REST API framework using decorators
Stars: ✭ 28 (-24.32%)
Mutual labels:  decorators
MojimojiMemoji
웨일 브라우저 확장앱🐋 모지모지메모지📝
Stars: ✭ 17 (-54.05%)
Mutual labels:  mocha
floss
Unit-testing for those hard to reach places
Stars: ✭ 26 (-29.73%)
Mutual labels:  mocha
Online Travel Reservation
A replica of online travel booking site KAYAK(www.kayak.com) for cmpe-273. Visit ->
Stars: ✭ 37 (+0%)
Mutual labels:  mocha
mocha-simple-html-reporter
Simple HTML reporter for Mocha
Stars: ✭ 16 (-56.76%)
Mutual labels:  mocha
socket.io-react
A High-Order component to connect React and Socket.io easily
Stars: ✭ 67 (+81.08%)
Mutual labels:  decorators
gds-nodejs-boilerplate
A Node.js project boilerplate for production apps
Stars: ✭ 18 (-51.35%)
Mutual labels:  mocha
djburger
Framework for safe and maintainable web-projects.
Stars: ✭ 75 (+102.7%)
Mutual labels:  decorators
serialize
Serializers for typescript based on decorators
Stars: ✭ 14 (-62.16%)
Mutual labels:  decorators
deco
Minimalist Function Decorators for Elixir
Stars: ✭ 21 (-43.24%)
Mutual labels:  decorators
twc
TypeScript based, boilerplate-less, Polymer toolbox friendly Polymer Modules
Stars: ✭ 33 (-10.81%)
Mutual labels:  decorators
mutest
A BDD testing framework for C, inspired by Mocha
Stars: ✭ 22 (-40.54%)
Mutual labels:  mocha
seedpress-cms
A headless CMS built in Express for PostgresQL using Sequelize. Generally follows the Wordpress post and term schema.
Stars: ✭ 71 (+91.89%)
Mutual labels:  mocha

Test Decorators

Build Status codecov npm version

IMPORTANT NOTE: this functionality is already included into allure-js as a separate allure-decorators module So feel free to check it out if you already have Allure integration.

This project will help to smoothly migrate from Java to Javascript automation.

Let's say we have the following test written in Java:

public class AuthorizationTests {
    
    @Issue("42")
    @TmsLink("58")
    @Feature("Login")
    @Story("58")
    @Severity(SeverityLevel.BLOCKER)
    @Test(dataProvider = "testData")
    public void userShouldBeAbleToSignIn(User user) {
        open(LoginPage.class)
            .loginWith(user)
            .select(ProfilePage.class);
    
        verifyThat(at(ProfilePage.class))
            .fullNameIs(user.getFullName())
            .usernameIs(user.getUsername());
    }
    
    @DataSupplier
    public StreamEx testData() {
        return StreamEx.of(
          new User('stranger', '123456', 'Strange Person'),
          new User('test', '123456', 'Test User')
        );
    }    
}

Everyone in a Java world get used to strict types, classes and annotations. You may wonder how to achieve the same in JS?

The answer is using Typescript and decorators.

@testdeck/mocha will help us with core features. However, it has nothing to do with Allure. Moreover, there's no flexible DataProvider mechanism available.

This library fills these gaps, so that you can write your tests the following way:

import { Severity } from "allure2-js-commons"
import { suite, test } from '@testdeck/mocha'
import {
  assignPmsUrl,
  assignTmsUrl,
  decorate,
  data,
  description,
  feature,
  issue,
  owner,
  severity,
  story,
  tag,
  testCaseId
} from 'ts-test-decorators'
import { allure, MochaAllure } from 'allure-mocha/runtime'
      
@suite
class AuthorizationTests {
  static testData = () => {
    return new User('Test', 'User')
  }

  before() {
    const gitHubUrl: string = 'https://github.com/sskorol/ts-test-decorators/issues'
    assignPmsUrl(gitHubUrl)
    assignTmsUrl(gitHubUrl)
    decorate<MochaAllure>(allure)
  }
      
  @issue('42')
  @testCaseId('58')
  @severity(Severity.BLOCKER)
  @feature('Login')
  @story('58')
  @owner('skorol')
  @tag('smoke')
  @description('Basic authorization test.')
  @data(AuthorizationTests.testData)
  @data.naming((user: User) => `${user} should be able to sign`)
  @test
  userShouldBeAbleToSignIn(user: User) {
    open(LoginPage)
      .loginWith(user)
      .select(ProfilePage)
    
    verifyThat(atProfilePage)
      .fullNameIs(user.fullName)
      .usernameIs(user.username)
  }
}

Installation

npm i ts-test-decorators --save-dev

or via yarn:

yarn add ts-test-decorators --dev

As it's an extension to allure-js and testdeck, you have to install the following dependencies:

  • mocha
  • @testdeck/mocha
  • allure-mocha
  • allure-js-commons
  • source-map-support
  • typescript

Configuration

Either add allure-mocha into .mocharc.json:

{
  "require": "source-map-support/register",
  "reporter": "allure-mocha"
}

Or pass the same value via commandline / scripts:

mocha -R allure-mocha

tsconfig.json may look like the following:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "inlineSourceMap": true,
    "inlineSources": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "declaration": true,
    "lib": [
      "es7"
    ],
    "types": [
      "node",
      "mocha",
      "chai"
    ],
    "removeComments": true,
    "noImplicitAny": false,
    "baseUrl": ".",
    "paths": {
      "*": [ "./*" ],
      "src/*": ["./src/*"]
    },
    "typeRoots": [
      "node_modules/@types"
    ]
  },
  "include": [
    "./src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

Now you can use the following decorators:

  • attachment<T>(name: string, type: ContentType)
  • issue<T>(idFn: string | ((arg: T) => string))
  • testCaseId<T>(idFn: string | ((arg: T) => string))
  • feature<T>(featureFn: string | ((arg: T) => string))
  • story<T>(storyFn: string | ((arg: T) => string))
  • severity<T>(severityFn: Severity | string | ((arg: T) => string | Severity))
  • tag<T>(tagFn: string | ((arg: T) => string))
  • owner<T>(ownerFn: string | ((arg: T) => string))
  • epic<T>(epicFn: string | ((arg: T) => string))
  • description<T>(descriptionFn: string | ((arg: T) => string))
  • step<T>(nameFn: string | ((arg: T) => string))
  • data(params: any, name?: string)
  • data.naming(nameForTests: (parameters: any) => string)

To activate decorators you have to provide Allure implementation in runtime. You can do that the following way:

import { decorate } from 'ts-test-decorators';
import { allure, MochaAllure } from 'allure-mocha/runtime'
// ...
  before() {
    decorate<MochaAllure>(allure)
  }

If you want to set you own trackers' URLs, do the following:

import { assignPmsUrl, assignTmsUrl } from 'ts-test-decorators';
// ...
  before() {
    const gitHubUrl: string = 'https://github.com/sskorol/ts-test-decorators/issues'
    assignPmsUrl(gitHubUrl)
    assignTmsUrl(gitHubUrl)
  }

@data is not related to Allure. It's just a wrapper for testdeck @params decorator.

Also, be aware of @test and @data order. They should be always put before actual test method signature.

Examples

See mocha-allure2-example project, which is already configured to use latest Allure 2 features with decorators support.

Special Thanks

@srg-kostyrko for help and assistance.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].