Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): add context to beforeEach and afterEach hooks #6201

Closed
wants to merge 3 commits into from

Conversation

Mr-Duda
Copy link

@Mr-Duda Mr-Duda commented Nov 22, 2024

Fixes #6189

This allows the beforeEach and afterEach methods to use the data provided in each test context object.

I wanna build a small decorator based test framework on top of deno testing. The usecase is the following:

  • before each test /path/TestCaseTest/testFileNotExistsThrowsError/{in,out} folders are created if needed
  • it
    • reads some files from .../testFileNotExistsThrowsError/in
    • creates some files in .../testFileNotExistsThrowsError/out using a custom context wrapper
  • after each test the .../testFileNotExistsThrowsError/out is cleaned up to prevent unwanted outputs
@TestSuite
class TestCaseTest extends TestCase {

    @Test
    public testFileNotExistsThrowsError(context: iTestContext) {
        // Read files...
        context.createFile("./dummy.txt", "dummy")
        return this.assertThrows(() => this.assertFileNotExists("./dummy.txt", context))
    }
}

Currently the beforeEach and afterEach don't have access to the test name and it's somehow difficult to get this information.
The test source file would also be needed at some point and i would't use __filename since it's also provided in the test context.

@CLAassistant
Copy link

CLAassistant commented Nov 22, 2024

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.57%. Comparing base (93e0cd6) to head (7ca8dfd).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6201      +/-   ##
==========================================
+ Coverage   96.56%   96.57%   +0.01%     
==========================================
  Files         532      532              
  Lines       40819    40819              
  Branches     6111     6111              
==========================================
+ Hits        39416    39421       +5     
+ Misses       1360     1356       -4     
+ Partials       43       42       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@kt3k
Copy link
Member

kt3k commented Nov 22, 2024

Why not just use native Deno.test() and t.step()? These APIs should be more flexible than @std/testing/bdd and they should be more suitable for building testing framework on top of

@Mr-Duda Mr-Duda closed this Nov 25, 2024
@Mr-Duda
Copy link
Author

Mr-Duda commented Nov 25, 2024

I shitched to using the Deno namespace and it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing: add Deno.TestContext as a parameter to beforeEach and afterEach
3 participants