• 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

25.86
/libs/jestronaut/environment/init.lua
1
local makeIndexableFunction = require "jestronaut/utils/metatables".makeIndexableFunction
×
2
local describeLib = require "jestronaut/environment/describe"
×
NEW
3
local runnerLib = require "jestronaut/environment/runner"
×
4
local stateLib = require "jestronaut/environment/state"
×
5
local testLib = require "jestronaut/environment/test"
×
6
local eachLib = require "jestronaut/each"
×
7

8
local fileTestTimeouts = {}
×
9

10
-- Set the default timeout interval (in milliseconds) for all tests and before/after hooks in the test file. This only affects the test file from which this function is called. The default timeout interval is 5 seconds if this method is not called.
11
local function setTimeout(timeout)
12
    local file = debug.getinfo(2, "S").source:sub(2)
4✔
13
    fileTestTimeouts[file] = timeout
4✔
14
end
15

16
--- Exposes the environment functions to the global environment.
17
--- @param targetEnvironment table
18
local function exposeTo(targetEnvironment)
19
    targetEnvironment.afterAll = stateLib.afterAll
×
20
    targetEnvironment.afterEach = stateLib.afterEach
×
21

22
    targetEnvironment.beforeAll = stateLib.beforeAll
×
23
    targetEnvironment.beforeEach = stateLib.beforeEach
×
24

NEW
25
    targetEnvironment.describe = makeIndexableFunction(
×
26
        function(blockName, blockFn)
27
            return describeLib.describe(blockName, blockFn)
156✔
28
        end
29
    )
30

NEW
31
    targetEnvironment.describe.only = makeIndexableFunction(
×
32
        function(mainDescribe, blockName, blockFn)
33
            return describeLib.describeOnly(mainDescribe, blockName, blockFn)
16✔
34
        end
35
    )
NEW
36
    targetEnvironment.describe.skip = makeIndexableFunction(
×
37
        function(mainDescribe, blockName, blockFn)
38
            return describeLib.describeSkip(mainDescribe, blockName, blockFn)
16✔
39
        end
40
    )
41

42
    eachLib.bindTo(targetEnvironment.describe)
×
43
    eachLib.bindTo(targetEnvironment.describe.only, targetEnvironment.describe)
×
44
    eachLib.bindTo(targetEnvironment.describe.skip, targetEnvironment.describe)
×
45

46
    -- Refactored so both test and it can be used
NEW
47
    local aliases = { 'test', 'it', 'testAsync', 'itAsync' }
×
48

49
    for _, alias in ipairs(aliases) do
×
NEW
50
        local isAsync = alias:sub(-5) == 'Async'
×
51

52
        local function wrapIfNeeded(blockFn)
53
            if isAsync then
924✔
54
                return testLib.wrapAsyncTest(blockFn)
36✔
55
            end
56

57
            return blockFn
888✔
58
        end
59

NEW
60
        targetEnvironment[alias] = makeIndexableFunction(
×
61
            function(blockName, blockFn, timeout)
62
                return testLib.test(blockName, wrapIfNeeded(blockFn), timeout)
1,608✔
63
            end
64
        )
NEW
65
        targetEnvironment[alias].concurrent = makeIndexableFunction(
×
66
            function(self, blockName, blockFn, timeout)
NEW
67
                return testLib.testConcurrent(self, blockName, wrapIfNeeded(blockFn), timeout)
×
68
            end
69
        )
NEW
70
        targetEnvironment[alias].concurrent.only = makeIndexableFunction(
×
71
            function(self, blockName, blockFn, timeout)
NEW
72
                return testLib.testConcurrentOnly(self, blockName, wrapIfNeeded(blockFn), timeout)
×
73
            end
74
        )
NEW
75
        targetEnvironment[alias].concurrent.skip = makeIndexableFunction(
×
76
            function(self, blockName, blockFn, timeout)
NEW
77
                return testLib.testConcurrentSkip(self, blockName, wrapIfNeeded(blockFn), timeout)
×
78
            end
79
        )
NEW
80
        targetEnvironment[alias].failing = makeIndexableFunction(
×
81
            function(self, blockName, blockFn, timeout)
82
                return testLib.testFailing(self, blockName, wrapIfNeeded(blockFn), timeout)
152✔
83
            end
84
        )
NEW
85
        targetEnvironment[alias].failing.only = makeIndexableFunction(
×
86
            function(self, blockName, blockFn, timeout)
87
                return testLib.testFailingOnly(self, blockName, wrapIfNeeded(blockFn), timeout)
8✔
88
            end
89
        )
NEW
90
        targetEnvironment[alias].failing.skip = makeIndexableFunction(
×
91
            function(self, blockName, blockFn, timeout)
92
                return testLib.testFailingSkip(self, blockName, wrapIfNeeded(blockFn), timeout)
8✔
93
            end
94
        )
NEW
95
        targetEnvironment[alias].only = makeIndexableFunction(
×
96
            function(self, blockName, blockFn, timeout)
97
                return testLib.testOnly(self, blockName, wrapIfNeeded(blockFn), timeout)
32✔
98
            end
99
        )
NEW
100
        targetEnvironment[alias].skip = makeIndexableFunction(
×
101
            function(self, blockName, blockFn, timeout)
102
                return testLib.testSkip(self, blockName, wrapIfNeeded(blockFn), timeout)
40✔
103
            end
104
        )
NEW
105
        targetEnvironment[alias].todo = function(self, blockName, blockFn)
×
106
            return testLib.testTodo(self, blockName, blockFn)
8✔
107
        end
108

109
        eachLib.bindTo(targetEnvironment[alias])
×
110
        eachLib.bindTo(targetEnvironment[alias].concurrent, targetEnvironment[alias])
×
111
        eachLib.bindTo(targetEnvironment[alias].concurrent.only, targetEnvironment[alias])
×
112
        eachLib.bindTo(targetEnvironment[alias].concurrent.skip, targetEnvironment[alias])
×
113
        eachLib.bindTo(targetEnvironment[alias].failing, targetEnvironment[alias])
×
114
        eachLib.bindTo(targetEnvironment[alias].failing.only, targetEnvironment[alias])
×
115
        eachLib.bindTo(targetEnvironment[alias].failing.skip, targetEnvironment[alias])
×
116
        eachLib.bindTo(targetEnvironment[alias].only, targetEnvironment[alias])
×
117
        eachLib.bindTo(targetEnvironment[alias].skip, targetEnvironment[alias])
×
118
    end
119
end
120

121
return {
×
122
    resetEnvironment = stateLib.resetEnvironment,
123

124
    setRoots = stateLib.setRoots,
125
    registerTests = stateLib.registerTests,
126
    runTests = stateLib.runTests,
127

128
    setTimeout = setTimeout,
129
    exposeTo = exposeTo,
130

131
    retryTimes = stateLib.retryTimes,
132

133
    newRunner = runnerLib.newRunner,
134
}
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