{"id":16689215,"url":"https://github.com/sskorol/ts-test-decorators","last_synced_at":"2025-04-13T07:55:35.531Z","repository":{"id":33183548,"uuid":"154035893","full_name":"sskorol/ts-test-decorators","owner":"sskorol","description":"Write your tests in a Java-like annotation-driven manner via JS decorators","archived":false,"fork":false,"pushed_at":"2024-08-24T08:17:47.000Z","size":421,"stargazers_count":40,"open_issues_count":4,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-13T07:55:29.591Z","etag":null,"topics":["allure","decorators","mocha","mocha-typescript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sskorol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-21T17:47:04.000Z","updated_at":"2024-05-16T16:30:15.000Z","dependencies_parsed_at":"2023-01-14T23:49:04.241Z","dependency_job_id":"9447ca80-287a-4216-a93b-ba1267047a5b","html_url":"https://github.com/sskorol/ts-test-decorators","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":0.48,"last_synced_commit":"c45387ed2454b2da57f182d41b2f9ed2055605fc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sskorol%2Fts-test-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sskorol%2Fts-test-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sskorol%2Fts-test-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sskorol%2Fts-test-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sskorol","download_url":"https://codeload.github.com/sskorol/ts-test-decorators/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681491,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["allure","decorators","mocha","mocha-typescript","typescript"],"created_at":"2024-10-12T15:47:31.204Z","updated_at":"2025-04-13T07:55:35.502Z","avatar_url":"https://github.com/sskorol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test Decorators\n\n[![Build Status](https://travis-ci.com/sskorol/ts-test-decorators.svg?branch=master)](https://travis-ci.com/sskorol/ts-test-decorators)\n[![codecov](https://codecov.io/gh/sskorol/ts-test-decorators/branch/master/graph/badge.svg)](https://codecov.io/gh/sskorol/ts-test-decorators)\n[![npm version](https://badge.fury.io/js/ts-test-decorators.svg)](https://badge.fury.io/js/ts-test-decorators)\n\n**IMPORTANT NOTE**: this functionality is already included into [allure-js](https://github.com/allure-framework/allure-js) as a separate `allure-decorators` module So feel free to check it out if you already have Allure integration.\n\nThis project will help to smoothly migrate from Java to Javascript automation.\n\nLet's say we have the following test written in Java:\n\n```java\npublic class AuthorizationTests {\n    \n    @Issue(\"42\")\n    @TmsLink(\"58\")\n    @Feature(\"Login\")\n    @Story(\"58\")\n    @Severity(SeverityLevel.BLOCKER)\n    @Test(dataProvider = \"testData\")\n    public void userShouldBeAbleToSignIn(User user) {\n        open(LoginPage.class)\n            .loginWith(user)\n            .select(ProfilePage.class);\n    \n        verifyThat(at(ProfilePage.class))\n            .fullNameIs(user.getFullName())\n            .usernameIs(user.getUsername());\n    }\n    \n    @DataSupplier\n    public StreamEx testData() {\n        return StreamEx.of(\n          new User('stranger', '123456', 'Strange Person'),\n          new User('test', '123456', 'Test User')\n        );\n    }    \n}\n```\n\nEveryone in a Java world get used to strict types, classes and annotations.\nYou may wonder how to achieve the same in JS?\n\nThe answer is using Typescript and decorators.\n\n[@testdeck/mocha](https://www.npmjs.com/package/@testdeck/mocha) will help us with core features.\nHowever, it has nothing to do with [Allure](https://github.com/allure-framework/allure-js).\nMoreover, there's no flexible [DataProvider](https://github.com/sskorol/test-data-supplier) mechanism available. \n\nThis library fills these gaps, so that you can write your tests the following way:\n\n```typescript\nimport { Severity } from \"allure2-js-commons\"\nimport { suite, test } from '@testdeck/mocha'\nimport {\n  assignPmsUrl,\n  assignTmsUrl,\n  decorate,\n  data,\n  description,\n  feature,\n  issue,\n  owner,\n  severity,\n  story,\n  tag,\n  testCaseId\n} from 'ts-test-decorators'\nimport { allure, MochaAllure } from 'allure-mocha/runtime'\n      \n@suite\nclass AuthorizationTests {\n  static testData = () =\u003e {\n    return new User('Test', 'User')\n  }\n\n  before() {\n    const gitHubUrl: string = 'https://github.com/sskorol/ts-test-decorators/issues'\n    assignPmsUrl(gitHubUrl)\n    assignTmsUrl(gitHubUrl)\n    decorate\u003cMochaAllure\u003e(allure)\n  }\n      \n  @issue('42')\n  @testCaseId('58')\n  @severity(Severity.BLOCKER)\n  @feature('Login')\n  @story('58')\n  @owner('skorol')\n  @tag('smoke')\n  @description('Basic authorization test.')\n  @data(AuthorizationTests.testData)\n  @data.naming((user: User) =\u003e `${user} should be able to sign`)\n  @test\n  userShouldBeAbleToSignIn(user: User) {\n    open(LoginPage)\n      .loginWith(user)\n      .select(ProfilePage)\n    \n    verifyThat(atProfilePage)\n      .fullNameIs(user.fullName)\n      .usernameIs(user.username)\n  }\n}\n``` \n## Installation\n\n```bash\nnpm i ts-test-decorators --save-dev\n```\nor via yarn:\n```bash\nyarn add ts-test-decorators --dev\n```\n\nAs it's an extension to [allure-js](https://github.com/allure-framework/allure-js) and [testdeck](https://www.npmjs.com/package/@testdeck/mocha), you have to install the following dependencies:\n\n - mocha\n - @testdeck/mocha\n - allure-mocha\n - allure-js-commons\n - source-map-support\n - typescript\n\n## Configuration\n\nEither add **allure-mocha** into **.mocharc.json**:\n\n```json\n{\n  \"require\": \"source-map-support/register\",\n  \"reporter\": \"allure-mocha\"\n}\n```\n\nOr pass the same value via commandline / scripts:\n\n```bash\nmocha -R allure-mocha\n```\n\n**tsconfig.json** may look like the following:\n```json\n{\n  \"compilerOptions\": {\n    \"target\": \"es2017\",\n    \"module\": \"commonjs\",\n    \"inlineSourceMap\": true,\n    \"inlineSources\": true,\n    \"emitDecoratorMetadata\": true,\n    \"experimentalDecorators\": true,\n    \"declaration\": true,\n    \"lib\": [\n      \"es7\"\n    ],\n    \"types\": [\n      \"node\",\n      \"mocha\",\n      \"chai\"\n    ],\n    \"removeComments\": true,\n    \"noImplicitAny\": false,\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"*\": [ \"./*\" ],\n      \"src/*\": [\"./src/*\"]\n    },\n    \"typeRoots\": [\n      \"node_modules/@types\"\n    ]\n  },\n  \"include\": [\n    \"./src/**/*.ts\"\n  ],\n  \"exclude\": [\n    \"node_modules\"\n  ]\n}\n```\n\nNow you can use the following decorators:\n\n - `attachment\u003cT\u003e(name: string, type: ContentType)`\n - `issue\u003cT\u003e(idFn: string | ((arg: T) =\u003e string))`\n - `testCaseId\u003cT\u003e(idFn: string | ((arg: T) =\u003e string))`\n - `feature\u003cT\u003e(featureFn: string | ((arg: T) =\u003e string))`\n - `story\u003cT\u003e(storyFn: string | ((arg: T) =\u003e string))`\n - `severity\u003cT\u003e(severityFn: Severity | string | ((arg: T) =\u003e string | Severity))`\n - `tag\u003cT\u003e(tagFn: string | ((arg: T) =\u003e string))`\n - `owner\u003cT\u003e(ownerFn: string | ((arg: T) =\u003e string))`\n - `epic\u003cT\u003e(epicFn: string | ((arg: T) =\u003e string))`\n - `description\u003cT\u003e(descriptionFn: string | ((arg: T) =\u003e string))`\n - `step\u003cT\u003e(nameFn: string | ((arg: T) =\u003e string))`\n - `data(params: any, name?: string)`\n - `data.naming(nameForTests: (parameters: any) =\u003e string)`\n\nTo activate decorators you have to provide Allure implementation in runtime. You can do that the following way:\n```typescript\nimport { decorate } from 'ts-test-decorators';\nimport { allure, MochaAllure } from 'allure-mocha/runtime'\n// ...\n  before() {\n    decorate\u003cMochaAllure\u003e(allure)\n  }\n```\n\nIf you want to set you own trackers' URLs, do the following:\n```typescript\nimport { assignPmsUrl, assignTmsUrl } from 'ts-test-decorators';\n// ...\n  before() {\n    const gitHubUrl: string = 'https://github.com/sskorol/ts-test-decorators/issues'\n    assignPmsUrl(gitHubUrl)\n    assignTmsUrl(gitHubUrl)\n  }\n```\n\n**@data** is not related to Allure. It's just a wrapper for testdeck **@params** decorator.\n\nAlso, be aware of **@test** and **@data** order. They should be always put before actual test method signature.\n\n## Examples\n\nSee [mocha-allure2-example](https://github.com/sskorol/mocha-allure2-example) project, which is already configured to use latest Allure 2 features with decorators support.\n\n## Special Thanks\n\n[@srg-kostyrko](https://github.com/srg-kostyrko) for help and assistance.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsskorol%2Fts-test-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsskorol%2Fts-test-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsskorol%2Fts-test-decorators/lists"}