local c=require(script.Parent.TestPlanner)local O=require(script.Parent.TestRunner)local v=require(script.Parent.Reporters.TextReporter)local t={}local function u(c)return c:gsub("\037\046\115\112\101\099\036","")end local function P(c)return c:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")and c.Name:match("\037\046\115\112\101\099\036")end local function Y(c,O)O=O or game local v={}local t=c if t.Name=="\105\110\105\116\046\115\112\101\099"then t=t.Parent end while t~=nil and t~=O do table.insert(v,u(t.Name))t=t.Parent end table.insert(v,u(O.Name))return v end local function b(c)local O=""local v=true for c,t in ipairs(c)do if v then O=t v=false else O=t..(" "..O)end end return O end function t.getModulesImpl(t,c,O,v)O=O or{}v=v or c if P(v)then local t=require(v)local u=Y(v,c)local P=b(u)table.insert(O,{instance=v;method=t;path=u;pathStringForSorting=P:lower()})end end


local TestPlanner = require(script.Parent.TestPlanner)
local TestRunner = require(script.Parent.TestRunner)
local TextReporter = require(script.Parent.Reporters.TextReporter)

local TestBootstrap = {}

local function stripSpecSuffix(name)
	return (name:gsub("%.spec$", ""))
end
local function isSpecScript(aScript)
	return aScript:IsA("ModuleScript") and aScript.Name:match("%.spec$")
end

local function getPath(module, root)
	root = root or game

	local path = {}
	local last = module

	if last.Name == "init.spec" then
		-- Use the directory's node for init.spec files.
		last = last.Parent
	end

	while last ~= nil and last ~= root do
		table.insert(path, stripSpecSuffix(last.Name))
		last = last.Parent
	end
	table.insert(path, stripSpecSuffix(root.Name))

	return path
end

local function toStringPath(tablePath)
	local stringPath = ""
	local first = true
	for _, element in ipairs(tablePath) do
		if first then
			stringPath = element
			first = false
		else
			stringPath = element .. " " .. stringPath
		end
	end
	return stringPath
end

function TestBootstrap:getModulesImpl(root, modules, current)
	modules = modules or {}
	current = current or root

	if isSpecScript(current) then
		local method = require(current)
		local path = getPath(current, root)
		local pathString = toStringPath(path)

		table.insert(modules, {
			instance = current,
			method = method,
			path = path,
			pathStringForSorting = pathString:lower(),
		})
	end
end
