Skip to content

Commit

Permalink
test: push all new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmesrje committed Jan 26, 2025
1 parent 90e1122 commit f7e2042
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 373 deletions.
20 changes: 14 additions & 6 deletions src/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ local InitiatedProviders: { Types.Provider<any> } = {}
-- Adds the the callback from the provider to the lifecycle listeners
local function StartLifecycles(provider: Provider<any>)
for _, lifecycle in AddedLifecycles do
if (provider :: any)[lifecycle.Name] then -- Check if the provider has a lifecycle
if (provider :: any)[lifecycle.Name] and type((provider :: any)[lifecycle.Name]) == "function" then -- Check if the provider has a lifecycle
-- Add the lifecycle callback to the listeners of it
table.insert(lifecycle.Listeners, (provider :: any)[lifecycle.Name])
end
Expand All @@ -50,7 +50,7 @@ end

-- Inits a provider
local function InitProvider(provider: Provider<any>)
if provider.Init then
if provider.Init and not table.find(InitiatedProviders, provider) then
-- Ensure prop is the correct type
local argType = type(provider.Init)
assert(argType == "function", "InvalidType", "function", argType)
Expand Down Expand Up @@ -103,6 +103,10 @@ local function Lifecycle<T...>(name: string, callback: ((self: Lifecycle<T...>,
Spawn(listener, ...)
end
end,
Disconnect = function(self: Lifecycle<T...>)
table.clear(self.Listeners)
table.freeze(self.Listeners)
end,
})
table.insert(AddedLifecycles, Lifecycle)
return Lifecycle
Expand Down Expand Up @@ -159,12 +163,12 @@ end
[Open Documentation](https://lumin-org.github.io/framework/api/#start)
]=]
local function Start(config: { profiling: boolean? }?)
local function Start(config: { Profiling: boolean? }?)
assert(not Started, "AlreadyStarted")

if config then
-- Set configurations
Profiling = config.profiling or Profiling
Profiling = config.Profiling or Profiling
end

-- Sort by load order, least to greatest
Expand Down Expand Up @@ -203,9 +207,13 @@ export type Lifecycle<T...> = Types.Lifecycle<T...>

-- Module

return table.freeze({
return table.freeze(setmetatable({
Start = Start,
Add = Add,
New = New,
Lifecycle = Lifecycle,
})
}, {
__call = function<T>(_, members: T): Provider<T>
return New(members :: any)
end,
}))
File renamed without changes.
21 changes: 0 additions & 21 deletions tests/client/Modules/Announcement.luau

This file was deleted.

10 changes: 0 additions & 10 deletions tests/client/init.client.luau

This file was deleted.

10 changes: 10 additions & 0 deletions tests/lifecycles/callback/consumer.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)

local function LifecycleCallback(args)
print(args)
end

return Framework {
LifecycleCallback = LifecycleCallback,
}
17 changes: 17 additions & 0 deletions tests/lifecycles/callback/lifecycle.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "LIFECYCLE-TEST"

local RunService = game:GetService("RunService")
local Lifecycle = Framework.Lifecycle("LifecycleCallback", function(self, ...)
for _, listener in self.Listeners do
print(`{TEST_NAME}: Lifecycle custom listener`)
listener(...)
end
end)

RunService.Heartbeat:Connect(function()
Lifecycle:Fire(TEST_NAME)
end)

return {}
10 changes: 10 additions & 0 deletions tests/lifecycles/consumer.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
local Packages = script.Parent.Parent.Parent
local Framework = require(Packages.framework.src)

local function LifecycleTest(arg)
print(`{arg}: Default listener`)
end

return Framework {
LifecycleTest = LifecycleTest,
}
12 changes: 12 additions & 0 deletions tests/lifecycles/lifecycle.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local Packages = script.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "LIFECYCLE-TEST"

local RunService = game:GetService("RunService")
local Lifecycle = Framework.Lifecycle("LifecycleTest")

RunService.Heartbeat:Connect(function()
Lifecycle:Fire(TEST_NAME)
end)

return {}
14 changes: 14 additions & 0 deletions tests/providers/dependencies/dep1.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "DEPENDENCIES-TEST"

local Dep2 = require(script.Parent.dep2)

local function Init()
print(`{TEST_NAME}: Dependency 1, using Dependency 2 (second)`)
end

return Framework {
Init = Init,
Uses = { Dep2 }
}
11 changes: 11 additions & 0 deletions tests/providers/dependencies/dep2.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "DEPENDENCIES-TEST"

local function Init()
print(`{TEST_NAME}: Dependency 2 (first)`)
end

return Framework {
Init = Init,
}
14 changes: 14 additions & 0 deletions tests/providers/dependencies/module.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "DEPENDENCIES-TEST"

local Dep1 = require(script.Parent.dep1)

local function Init()
print(`{TEST_NAME}: Module (third)`)
end

return Framework {
Init = Init,
Uses = { Dep1 }
}
12 changes: 12 additions & 0 deletions tests/providers/order/mod1.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "ORDER-TEST"

local function Init()
print(`{TEST_NAME}: First`)
end

return Framework {
Init = Init,
Order = -3,
}
12 changes: 12 additions & 0 deletions tests/providers/order/mod2.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "ORDER-TEST"

local function Init()
print(`{TEST_NAME}: Second`)
end

return Framework {
Init = Init,
Order = -2,
}
12 changes: 12 additions & 0 deletions tests/providers/order/mod3.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local Packages = script.Parent.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "ORDER-TEST"

local function Init()
print(`{TEST_NAME}: Third`)
end

return Framework {
Init = Init,
Order = -1,
}
17 changes: 17 additions & 0 deletions tests/providers/provider.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local Packages = script.Parent.Parent.Parent
local Framework = require(Packages.framework.src)
local TEST_NAME = "PROVIDER-TEST"

local function Init()
print(`{TEST_NAME}: Init (first)`)
end

local function Start()
print(`{TEST_NAME}: Start (second)`)
end

return Framework {
Init = Init,
Start = Start,
Name = "provider-custom",
}
42 changes: 0 additions & 42 deletions tests/server/Modules/KillPart.luau

This file was deleted.

55 changes: 0 additions & 55 deletions tests/server/Modules/SpleefPart.luau

This file was deleted.

Loading

0 comments on commit f7e2042

Please sign in to comment.