local s=require(script.Parent.TestPlanner)local Z=require(script.Parent.TestRunner)local e=require(script.Parent.Reporters.TextReporter)local W={}local function X(s)return s:gsub("\037\046\115\112\101\099\036","")end local function P(s)return s:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")and s.Name:match("\037\046\115\112\101\099\036")end local function c(s,Z)Z=Z or game local e={}local W=s if W.Name=="\105\110\105\116\046\115\112\101\099"then W=W.Parent end while W~=nil and W~=Z do table.insert(e,X(W.Name))W=W.Parent end table.insert(e,X(Z.Name))return e end local function b(s)local Z=""local e=true for s,W in ipairs(s)do if e then Z=W e=false else Z=W..(" "..Z)end end return Z end function W.getModulesImpl(W,s,Z,e)Z=Z or{}e=e or s if P(e)then local W=require(e)local X=c(e,s)local P=b(X)table.insert(Z,{instance=e,method=W;path=X;pathStringForSorting=P:lower()})end end
--[[
	Provides an interface to quickly run and report tests from a given object.
]]

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
