local N=require(script.Parent.TestPlanner)local p=require(script.Parent.TestRunner)local f=require(script.Parent.Reporters.TextReporter)local B={}local function P(N)return N:gsub("\037\046\115\112\101\099\036","")end local function y(N)return N:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")and N.Name:match("\037\046\115\112\101\099\036")end local function M(N,p)p=p or game local f={}local B=N if B.Name=="\105\110\105\116\046\115\112\101\099"then B=B.Parent end while B~=nil and B~=p do table.insert(f,P(B.Name))B=B.Parent end table.insert(f,P(p.Name))return f end local function J(N)local p=""local f=true for N,B in ipairs(N)do if f then p=B f=false else p=B..(" "..p)end end return p end function B.getModulesImpl(B,N,p,f)p=p or{}f=f or N if y(f)then local B=require(f)local P=M(f,N)local y=J(P)table.insert(p,{method=B,path=P,pathStringForSorting=y: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, {
			method = method,
			path = path,
			pathStringForSorting = pathString:lower()
		})
	end
end
