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

plenary.test_harness setup & teardown methods #214

Open
chipsenkbeil opened this issue Aug 14, 2021 · 2 comments
Open

plenary.test_harness setup & teardown methods #214

chipsenkbeil opened this issue Aug 14, 2021 · 2 comments

Comments

@chipsenkbeil
Copy link
Contributor

I was trying to find an issue that is tracking support for setup and teardown methods, but couldn't find anything thus far. Any particular reason those two methods aren't supported? Any chance they would be on a roadmap for plenary?

My use case is that I have a series of end-to-end tests that have really expensive setup costs. Today, I'm performing the same setup and teardown for each of my individual it(...) tests, which involves communicating over a network and creating a directory structure. My fixtures don't change, but I do need them to be dynamically generated within my tests.

As a result, this slows down my tests by a lot. Here's what I've got today in case there's a better way to stand up my driver that performs network calls and tear it down once all tests have finished for the given describe block:

local driver, root

before_each(function()
    driver = Driver:setup()

    -- TODO: This is really expensive, but plenary doesn't offer setup/teardown
    --       functions that we could use to limit this to the the entire
    --       describe block
    --
    --       Because we don't know when the last it(...) would finish, we cannot
    --       support manually creating a fixture and unloading it as it would
    --       get unloaded while other it blocks are still using it
    root = driver:new_dir_fixture({items = {
        'dir1/',
        'dir1/dir1-file1',
        'dir1/dir1-file2',

        'dir1/sub1/',
        'dir1/sub1/dir1-sub1-file1',

        'dir1/sub2/',

        'dir2/',
        'dir2/dir2-file1',
        'dir2/dir2-file2',

        'file1',
        'file2',
    }})
end)

after_each(function()
    driver:teardown()
end)
@matu3ba
Copy link
Contributor

matu3ba commented Oct 3, 2021

This is related to how busted works now:
see describe what describe calls and what gets evaluated.
see format_results how simple outputs are generated.
And see the Makefile how they are called (per file).

One would need to make lua test files "known to lua" to build abstractions on that kinda how you define things for packer.nvim with function bodies calling files.
If this should be done as simple as possible:

  1. collect all files in tests in a table to check for completeness of 1.
  2. annotate functions to filenames with how the table should be evaluated (ie order etc)
  3. collect results of 1. for overall output including elapsed time per test
  4. print results (each test file and finally the summary table)

busted is very minimal on top of the language lua and calls each test file individually without any overall testing strategy.

@Conni2461
Copy link
Collaborator

You can do this to only set it up once per file. Files are executed sequentially

local driver = Driver:setup()
local root = driver:new_dir_fixture({items = {
  'dir1/',
  'dir1/dir1-file1',
  'dir1/dir1-file2',

  'dir1/sub1/',
  'dir1/sub1/dir1-sub1-file1',

  'dir1/sub2/',

  'dir2/',
  'dir2/dir2-file1',
  'dir2/dir2-file2',

  'file1',
  'file2',
}})

describe("asdf", function()
end)

-- ...

describe("asdf asdf", function()
end)

driver:teardown()

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

No branches or pull requests

3 participants