Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Make sure that init.spec.lua runs before any of its children. #99

Open
MagiMaster opened this issue May 16, 2020 · 0 comments
Open

Make sure that init.spec.lua runs before any of its children. #99

MagiMaster opened this issue May 16, 2020 · 0 comments

Comments

@MagiMaster
Copy link
Collaborator

MagiMaster commented May 16, 2020

One case we want to support for TestEZ is allowing configuration to be done per test suite. init.spec.lua was added to provide a place to run such configuration code. But to be useful, it has to run before any of the spec files under it, which isn't currently guaranteed. An additional wrinkle here is that while it intuitively makes the most sense to do this inside a beforeAll block, that will mean the configuration definitely won't get set for any describe blocks under it, though it will currently work for any it blocks.

For example, if you want to set the global config of a library for all tests inside the foo directory, you should be able to put the following in foo/init.spec.lua

return function()
    local originalThing
    beforeAll(function()
        originalThing = myLibrary.config.useNewThing
        myLibrary.config.useNewThing = true
    end)
    afterAll(function()
        myLibrary.config.useNewThing = originalThing
    end)
end

While the use of beforeAll and afterAll are intuitively the way to go, we at least need to make sure there's some solution that's guaranteed to work.

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

No branches or pull requests

2 participants