From e8997d299cc4709fb844e00a1561cef44c647cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20S=C4=99dzik?= <30985766+SebastianSedzik@users.noreply.github.com> Date: Fri, 5 Jan 2024 15:29:36 +0100 Subject: [PATCH] chore: redact error messages thrown by custom decorators (#44) * docs: fix path to examples * docs: rephrase NotSuiteOrTestDecoratedMethod error message * chore: generate changeset --- .changeset/odd-peas-float.md | 5 +++++ README.md | 2 +- lib/custom.ts | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 .changeset/odd-peas-float.md diff --git a/.changeset/odd-peas-float.md b/.changeset/odd-peas-float.md new file mode 100644 index 0000000..73351ba --- /dev/null +++ b/.changeset/odd-peas-float.md @@ -0,0 +1,5 @@ +--- +'playwright-decorators': patch +--- + +Redact error messages thrown by custom decorators: `createSuiteDecorator`, `createTestDecorator`, `createSuiteAndTestDecorator` diff --git a/README.md b/README.md index ae79671..06c14dc 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ class MyTestSuite { ``` 1. To view all the available decorators, check the [docs](#-docs) section. 2. For guidance on creating custom decorators, refer to the [custom decorators](#custom-decorators) section. -3. Explore additional examples in the [examples](./examples) directory. +3. Explore additional examples in the [examples](./examples/tests) directory. ## 📖 Docs - [Creating a test suite: `@suite`](#creating-a-test-suite-suiteoptions) diff --git a/lib/custom.ts b/lib/custom.ts index 46f2a61..c8f14ae 100644 --- a/lib/custom.ts +++ b/lib/custom.ts @@ -6,11 +6,11 @@ export class NotSuiteDecoratedMethodError extends Error { constructor(decoratorName: string, method: TestClass) { 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: +Make sure ${method?.name} is marked with @suite, and that @${decoratorName} comes before @suite, like this: @${decoratorName} @suite() -${method?.name}() {}`) +class ${method?.name} {}`) } } @@ -18,7 +18,7 @@ export class NotTestDecoratedMethodError extends Error { constructor(decoratorName: string, method: TestMethod) { 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: +Make sure ${method?.name} is marked with @test, and that @${decoratorName} comes before @test, like this: @${decoratorName} @test() @@ -29,11 +29,17 @@ ${method?.name}() {}`) export class NotSuiteOrTestDecoratedMethodError extends Error { constructor(decoratorName: string, method: TestClass | TestMethod) { 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: +The @${decoratorName} decorator can only be used on classes with the @suite decorator or methods with the @test decorator. +Make sure ${method?.name} is marked with @suite or @test, and that @${decoratorName} comes before @suite or @test, like this: +for suite: @${decoratorName} -@suite() / @test() +@suite() +class ${method?.name} {} + +for test: +@${decoratorName} +@test() ${method?.name}() {} `) }