diff --git a/.changeset/funny-pugs-kick.md b/.changeset/funny-pugs-kick.md new file mode 100644 index 0000000..c8dd35f --- /dev/null +++ b/.changeset/funny-pugs-kick.md @@ -0,0 +1,8 @@ +--- +'playwright-decorators': patch +--- + +- Display `reason` from `@skip` decorator. +- Show tags from `@skip` tests. +- Provide more detailed info in error messages. +- Cosmetic changes in readme file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e5b6030..c050bef 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,4 +1,4 @@ -name: Tests +name: PR on: pull_request: diff --git a/README.md b/README.md index 2360df0..921e2db 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ TypeScript's decorators for writing Playwright based tests. [![npm version](https://badge.fury.io/js/playwright-decorators.svg)](https://www.npmjs.com/package/playwright-decorators) -[![package tests](https://github.com/SebastianSedzik/playwright-decorators/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/SebastianSedzik/playwright-decorators/actions/workflows/tests.yml) +[![package tests](https://github.com/SebastianSedzik/playwright-decorators/actions/workflows/master.yml/badge.svg?branch=master)](https://github.com/SebastianSedzik/playwright-decorators/actions/workflows/master.yml) ## 🌱 Installation ```sh @@ -13,19 +13,19 @@ npm i playwright-decorators ## 🏗️ Usage Declare tests using `@suite` and `@test` decorators ```ts -import { suite, test, slow, annotation } from 'playwright-decorators'; +import { suite, test, slow, tag } from 'playwright-decorators'; @suite() // <-- Decorate class with @suite class MyTestSuite { - @test() - async myTest({ page }) { // <-- Decorate test method with @test + @test() // <-- Decorate test method with @test + async myTest({ page }) { // ... } - @annotation(['team-x']) // <-- Add custom annotation to test - @slow('Processing a new user takes a long time') // <-- Mark test as "slow" + @tag(['team-x']) + @slow('Response from pasword reset service takes a long time') @test() - async userCreation({ page }) { + async userShouldBeAbleToResetPassword({ page }) { // ... } diff --git a/lib/errors.ts b/lib/errors.ts index 06c2ea4..d39295e 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -1,17 +1,37 @@ export class NotSuiteDecoratedMethodError extends Error { constructor(decoratorName: string ,method: any) { - super(`${decoratorName} decorator can be applied only to methods decorated by @suite. ${method?.name} is not decorated by @suite`); + super(` +The @${decoratorName} decorator can only be used on class that also have the @suite decorator. +Make sure ${method?.name} is marked with @suite, and that ${decoratorName} comes before @suite, like this: + +@${decoratorName} +@suite() +${method?.name}() {}`); } } export class NotTestDecoratedMethodError extends Error { constructor(decoratorName: string, method: any) { - super(`${decoratorName} decorator can be applied only to methods decorated by @test. ${method?.name} is not decorated by @test`); + super(` +The @${decoratorName} decorator can only be used on methods that also have the @test decorator. +Make sure ${method?.name} is marked with @test, and that ${decoratorName} comes before @test, like this: + +@${decoratorName} +@test() +${method?.name}() {}` + ); } } export class NotSuiteOrTestDecoratedMethodError extends Error { constructor(decoratorName: string, method: any) { - super(`${decoratorName} decorator can be applied only to methods decorated by @test or classes decorated by @suite. ${method?.name} is not decorated by any of them`); + super(` +The @${decoratorName} decorator can only be used on classes/methods that also have the @suite or @test decorator. +Make sure ${method?.name} is marked with @suite or @test, and that ${decoratorName} comes before @suite or @test, like this: + +@${decoratorName} +@suite() / @test() +${method?.name}() {} + `); } } diff --git a/lib/suite.decorator.ts b/lib/suite.decorator.ts index facf2be..48472fb 100644 --- a/lib/suite.decorator.ts +++ b/lib/suite.decorator.ts @@ -68,10 +68,10 @@ export class SuiteDecorator implements SuiteDecoratorOptions { return; } - if (typeof this.skip === 'string') { - return playwright.slow(true, this.skip); + if (typeof this.slow === 'string') { + return playwright.slow(true, this.slow); } - + return playwright.slow(); } diff --git a/lib/test.decorator.ts b/lib/test.decorator.ts index 8e41ddf..b634272 100644 --- a/lib/test.decorator.ts +++ b/lib/test.decorator.ts @@ -74,11 +74,11 @@ export class TestDecorator implements TestDecoratorOptions { if (this.slow === false) { return; } - - if (typeof this.skip === 'string') { - return playwright.slow(true, this.skip); + + if (typeof this.slow === 'string') { + return playwright.slow(true, this.slow); } - + return playwright.slow(); } @@ -125,11 +125,11 @@ export class TestDecorator implements TestDecoratorOptions { */ run(executionContext: any) { const decoratedTest: TestDecoratorFunction = (testFunction) => async (...args) => { + this.handleAnnotations(); this.handleSkip(); this.handleSlow(); this.handleFail(); this.handleFixme(); - this.handleAnnotations(); await this.handleBeforeTestHooks(); // set correct executionContext (test class)