• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / jestronaut / 12214239123

07 Dec 2024 04:01PM UTC coverage: 72.291%. First build
12214239123

Pull #13

github

web-flow
Merge e4c588db6 into 98f7720fe
Pull Request #13: Async support (🚧WIP)

386 of 511 new or added lines in 13 files covered. (75.54%)

1568 of 2169 relevant lines covered (72.29%)

3855.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.46
/libs/jestronaut/environment/context.lua
1
--- @class TestContext
2
--- @field retrySettings? table
3
--- @field beforeAll? fun()
4
--- @field beforeEach? fun()
5
--- @field afterAll? fun()
6
--- @field afterEach? fun()
NEW
7
local LOCAL_STATE_META = {}
×
8

9
--- @type TestContext[]
NEW
10
local testFileContexts = {}
×
11

12
--- Returns the context local to the test file.
13
--- @param testFilePath string
14
--- @return TestContext
15
local function getTestFileContext(testFilePath)
16
    local fileContext = testFileContexts[testFilePath]
1,728✔
17

18
    if not fileContext then
1,728✔
19
        fileContext = {}
328✔
20
        testFileContexts[testFilePath] = fileContext
328✔
21
    end
22

23
    return fileContext
1,728✔
24
end
25

26
--- Traverses all test contexts up to the file. Useful for calling beforeAll and beforeEach functions.
27
--- If the callback returns a non-nil value, the traversal will stop and return that value.
28
--- @param describeOrTest DescribeOrTest
29
--- @param callback fun(context: TestContext, object: DescribeOrTest?): boolean?
30
--- @return boolean? # The result of the callback
31
local function traverseTestContexts(describeOrTest, callback)
32
    local relevantContexts = {}
844✔
33
    local parent = describeOrTest.parent
844✔
34

35
    table.insert(relevantContexts, {
1,688✔
36
        context = describeOrTest.context,
844✔
37
        object = describeOrTest,
844✔
38
    })
39

40
    while parent do
2,448✔
41
        if parent.context then
1,604✔
42
            table.insert(relevantContexts, {
3,208✔
43
                context = parent.context,
1,604✔
44
                object = parent,
1,604✔
45
            })
46
        end
47

48
        parent = parent.parent
2,448✔
49
    end
50

51
    table.insert(relevantContexts, {
1,688✔
52
        context = getTestFileContext(describeOrTest.filePath),
1,688✔
53
        object = nil,
54
    })
55

56
    -- Reverse the loop, so outer contexts are called first
57
    -- TODO: Is that what Jest does?
58
    -- for _, context in ipairs(relevantContexts) do
59
    for i = #relevantContexts, 1, -1 do
4,120✔
60
        local contextInfo = relevantContexts[i]
3,284✔
61
        local result = callback(contextInfo.context, contextInfo.object)
3,284✔
62

63
        if result ~= nil then
3,284✔
64
            return result
8✔
65
        end
66
    end
67
end
68

NEW
69
return {
×
70
    getTestFileContext = getTestFileContext,
71

72
    traverseTestContexts = traverseTestContexts,
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc