mirror of
https://github.com/AmberGraceRblx/luau-promise.git
synced 2025-04-24 15:50:01 +00:00
Start implementing tests, add lemur and testez dependencies
This commit is contained in:
parent
8b1573ce41
commit
a25ad236ae
6 changed files with 119 additions and 19 deletions
6
.gitmodules
vendored
Normal file
6
.gitmodules
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
[submodule "modules/testez"]
|
||||
path = modules/testez
|
||||
url = https://github.com/Roblox/testez.git
|
||||
[submodule "modules/lemur"]
|
||||
path = modules/lemur
|
||||
url = https://github.com/LPGhatguy/lemur.git
|
19
.luacheckrc
19
.luacheckrc
|
@ -1,23 +1,6 @@
|
|||
stds.roblox = {
|
||||
globals = {
|
||||
"game"
|
||||
},
|
||||
read_globals = {
|
||||
-- Roblox globals
|
||||
"script",
|
||||
|
||||
-- Extra functions
|
||||
"tick", "warn", "spawn",
|
||||
"wait", "settings", "typeof",
|
||||
|
||||
-- Types
|
||||
"Vector2", "Vector3",
|
||||
"Color3",
|
||||
"UDim", "UDim2",
|
||||
"Rect",
|
||||
"CFrame",
|
||||
"Enum",
|
||||
"Instance",
|
||||
"script", "spawn", "warn", "Instance",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1,41 @@
|
|||
local Promise = require(script.Parent.Promise)
|
||||
return function()
|
||||
local Promise = require(script.Parent.Promise)
|
||||
|
||||
describe("Promise.new", function()
|
||||
it("should pass resolve and reject to the callback", function()
|
||||
local promiseResolve
|
||||
local promiseReject
|
||||
local callCount = 0
|
||||
|
||||
local promise = Promise.new(function(resolve, reject)
|
||||
callCount = callCount + 1
|
||||
promiseResolve = resolve
|
||||
promiseReject = reject
|
||||
end)
|
||||
|
||||
expect(promise).to.be.ok()
|
||||
expect(promiseResolve).to.be.a("function")
|
||||
expect(promiseReject).to.be.a("function")
|
||||
expect(callCount).to.equal(1)
|
||||
end)
|
||||
|
||||
it("should resolve synchronously", function()
|
||||
local promiseResolve
|
||||
local callCount = 0
|
||||
|
||||
local promise = Promise.new(function(resolve)
|
||||
callCount = callCount + 1
|
||||
promiseResolve = resolve
|
||||
end)
|
||||
|
||||
expect(promise._status).to.equal(Promise.Status.Started)
|
||||
|
||||
promiseResolve(6)
|
||||
|
||||
expect(promise._status).to.equal(Promise.Status.Resolved)
|
||||
expect(promise._value).to.be.a("table")
|
||||
expect(#promise._value).to.equal(1)
|
||||
expect(promise._value[1]).to.equal(6)
|
||||
end)
|
||||
end)
|
||||
end
|
1
modules/lemur
Submodule
1
modules/lemur
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 3b295421315081168db63c00bbb4e6c070ac7634
|
1
modules/testez
Submodule
1
modules/testez
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 3c42175897f7133d10fdc269c040df98a55906d6
|
69
spec.lua
Normal file
69
spec.lua
Normal file
|
@ -0,0 +1,69 @@
|
|||
--[[
|
||||
Loads our library and all of its dependencies, then runs tests using TestEZ.
|
||||
]]
|
||||
|
||||
-- If you add any dependencies, add them to this table so they'll be loaded!
|
||||
local LOAD_MODULES = {
|
||||
{"lib", "Library"},
|
||||
{"modules/testez/lib", "TestEZ"},
|
||||
}
|
||||
|
||||
-- This makes sure we can load Lemur and other libraries that depend on init.lua
|
||||
package.path = package.path .. ";?/init.lua"
|
||||
|
||||
-- If this fails, make sure you've run `lua bin/install-dependencies.lua` first!
|
||||
local lemur = require("modules.lemur")
|
||||
|
||||
--[[
|
||||
Collapses ModuleScripts named 'init' into their parent folders.
|
||||
|
||||
This is the same result as the collapsing mechanism from Rojo.
|
||||
]]
|
||||
local function collapse(root)
|
||||
local init = root:FindFirstChild("init")
|
||||
if init then
|
||||
init.Name = root.Name
|
||||
init.Parent = root.Parent
|
||||
|
||||
for _, child in ipairs(root:GetChildren()) do
|
||||
child.Parent = init
|
||||
end
|
||||
|
||||
root:Destroy()
|
||||
root = init
|
||||
end
|
||||
|
||||
for _, child in ipairs(root:GetChildren()) do
|
||||
if child:IsA("Folder") then
|
||||
collapse(child)
|
||||
end
|
||||
end
|
||||
|
||||
return root
|
||||
end
|
||||
|
||||
-- Create a virtual Roblox tree
|
||||
local habitat = lemur.Habitat.new()
|
||||
|
||||
-- We'll put all of our library code and dependencies here
|
||||
local Root = lemur.Instance.new("Folder")
|
||||
Root.Name = "Root"
|
||||
|
||||
-- Load all of the modules specified above
|
||||
for _, module in ipairs(LOAD_MODULES) do
|
||||
local container = lemur.Instance.new("Folder", Root)
|
||||
container.Name = module[2]
|
||||
habitat:loadFromFs(module[1], container)
|
||||
end
|
||||
|
||||
collapse(Root)
|
||||
|
||||
-- Load TestEZ and run our tests
|
||||
local TestEZ = habitat:require(Root.TestEZ)
|
||||
|
||||
local results = TestEZ.TestBootstrap:run(Root.Library, TestEZ.Reporters.TextReporter)
|
||||
|
||||
-- Did something go wrong?
|
||||
if results.failureCount > 0 then
|
||||
os.exit(1)
|
||||
end
|
Loading…
Reference in a new issue