Skip to content

[FEATURE] New API #315

@silkentrance

Description

@silkentrance

See https://github.com/testdeck/testdeck/tree/315-revamp-api for the actual code.

New Public API

I would like to propose a new API for @testdeck. See also the PR #316

Note that this issue is a successor of #314.

  • all support for the done callback has been dropped, so it is either Promises or sync
  • the new API no longer mimics the describe, it from the underlying testing framework
    one has to either import these or use the available globals
  • all decorators have been streamlined so that they always require a call expression, e.g. @After() vs @After
  • one can now have multiple @Before() and @After() hooks, both static and instance
  • the instance of the test suite will be created once only and not before each test as was the case before.
  • @Params(...) no longer replaces @Test(...)
  • one can have multiple @Params(...) on a test method
  • the condition for skip, pending, only on suite and test can now be either a boolean or a function that returns a boolean
  • Only was renamed to Focus as it communicates the purpose more clearly

The new public API will be like this

@Suite(options?: SuiteOptions)
@Suite.Skip(options?: ConditionalSuiteOptions)
@Suite.Pending(options?: ConditionalSuiteOptions)
@Suite.Focus(options?: ConditionalSuiteOptions)

@Test(options?: TestOptions)
@Test.Skip(options?: ConditionalTestOptions)
@Test.Pending(options?: ConditionalTestOptions)
@Test.Focus(options?: ConditionalTestOptions)

@Params(params: unknown, options?: ParamsOptions)

@Before(options?: HookOptions)
@After(options?: HookOptions)

interface ExecutionOptions {
  timeout?: number;
  retry?: number;
  slow?: number;
}

interface SuiteOptions extends ExecutionOptions {
}

interface ConditionalSuiteOptions extends ExecutionOptions {
  condition?: boolean | (() => boolean);
}

interface TestOptions extends ExecutionOptions {
  name?: string;
}

interface ConditionalTestOptions extends TestOptions {
  condition?: boolean | (() => boolean);
}

interface ParamsOptions {
  name: string | ((params: unknown) => string);
}

interface HookOptions extends ExecutionOptions {
}

Internals

  • The existing code was rewritten and made more simple
    The code should now be much easier to understand so that others might want
    to chime in and contribute to the project as well
  • We are now using ESLINT. Existing code was made type safe and all linter errors have been resolved
  • Test coverage gets collected and reported
  • extraneous index.d.ts have been removed in favor of automatically generated ones
  • jasmine tests now use the jasmine assertions framework as chai will not work with jasmine
  • core tests have been rewritten, following the general structure of the old tests,
    "intercepting" on decorator creation and so on, providing us with more information so that
    we can assert upon internal features as well, e.g. which kind of symbols have been set and so on
  • this allows us to do more focused testing in individual test suites and to increase overall test coverage
  • test coverage for @testdeck/jasmine is at 100% (timeout still needs some tests)
  • test coverage for @testdeck/jest is at 100% (timeout still needs some tests)
  • test coverage for @testdeck/vitest is at 100% (timeout, retry still needs some tests)
  • test coverage for @testdeck/mocha is at 100%
  • test coverage for @testdeck/di-typedi is at 100%
  • test coverage for @testdeck/core is not at a 100% but only a few lines and branches have not been tested, yet

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions