Skip to content

Commit

Permalink
chore: redact error messages thrown by custom decorators (#44)
Browse files Browse the repository at this point in the history
* docs: fix path to examples

* docs: rephrase NotSuiteOrTestDecoratedMethod error message

* chore: generate changeset
  • Loading branch information
SebastianSedzik committed Jan 5, 2024
1 parent 529059a commit e8997d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-peas-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playwright-decorators': patch
---

Redact error messages thrown by custom decorators: `createSuiteDecorator`, `createTestDecorator`, `createSuiteAndTestDecorator`
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 12 additions & 6 deletions lib/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ 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} {}`)
}
}

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()
Expand All @@ -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}() {}
`)
}
Expand Down

0 comments on commit e8997d2

Please sign in to comment.