refactor(tests): improve fs interation variable naming

This commit is contained in:
Erica Marigold 2024-12-18 12:37:41 +00:00
parent d2c41e0d03
commit 6dd3f45f18
Signed by: DevComp
GPG key ID: 429EF1C337871656
4 changed files with 27 additions and 27 deletions

View file

@ -61,20 +61,20 @@ return function(test: typeof(frktest.test))
test.suite(
"Generates Argon sourcemaps for test projects successfully",
function()
for _, file in fs.readDir(TEST_PROJECTS_DIR) do
local testProject = `{TEST_PROJECTS_DIR}/{file}`
if not fs.isDir(testProject) or file == ".git" then
for _, entry in fs.readDir(TEST_PROJECTS_DIR) do
local path = `{TEST_PROJECTS_DIR}/{entry}`
if not fs.isDir(path) or entry == ".git" then
-- Skip files that are not project directories
continue
end
test.case(file, function()
test.case(entry, function()
-- If a file starts with `bad_` but not `bad_meta_`, we should expect a failure
-- Also, sorry about this shitty regex, regex-rs does not support look-around :(
local isBadMeta = regex.new(
"^bad_[^m]|^bad_m[^e]|^bad_me[^t]|^bad_met[^a]"
)
local expect = if isBadMeta:isMatch(file)
local expect = if isBadMeta:isMatch(entry)
then check.should_error
else check.should_not_error
@ -91,7 +91,7 @@ return function(test: typeof(frktest.test))
}
)()
return check.is_true(sourcemap(testProject))
return check.is_true(sourcemap(path))
end)
end)
end

View file

@ -10,16 +10,16 @@ local TEST_PROJECTS_DIR = "./test-files/argon"
return function(test: typeof(frktest.test))
test.suite("Generates valid Argon sync configs", function()
for _, dir in fs.readDir(TEST_PROJECTS_DIR) do
local fullPath = `{TEST_PROJECTS_DIR}/{dir}`
if not fs.isDir(fullPath) or dir == ".git" then
for _, entry in fs.readDir(TEST_PROJECTS_DIR) do
local path = `{TEST_PROJECTS_DIR}/{entry}`
if not fs.isDir(path) or entry == ".git" then
continue
end
test.case(`{dir}`, function()
test.case(`{entry}`, function()
local ok, config = syncConfig(
fullPath,
fs.readDir(fullPath),
path,
fs.readDir(path),
{ writeToFile = false, force = true }
)
check.is_true(ok)
@ -29,7 +29,7 @@ return function(test: typeof(frktest.test))
serde.decode("json", config),
serde.decode(
"json",
fs.readFile(`{fullPath}/default.project.json`)
fs.readFile(`{path}/default.project.json`)
)
check.table.contains(realConfig, generatedConfig)

View file

@ -67,20 +67,20 @@ return function(test: typeof(frktest.test))
test.suite(
"Generates Rojo sourcemaps for test projects successfully",
function()
for _, file in fs.readDir(TEST_PROJECTS_DIR) do
if table.find(TEST_PROJECT_EXCLUDES, file) then
for _, entry in fs.readDir(TEST_PROJECTS_DIR) do
if table.find(TEST_PROJECT_EXCLUDES, entry) then
-- It does not make sense to test sourcemap generation for some of the test projects
continue
end
local testProject = `{TEST_PROJECTS_DIR}/{file}`
test.case(file, function()
local path = `{TEST_PROJECTS_DIR}/{entry}`
test.case(entry, function()
-- If a file starts with `bad_` but not `bad_meta_`, we should expect a failure
-- Also, sorry about this shitty regex, regex-rs does not support look-around :(
local isBadMeta = regex.new(
"^bad_[^m]|^bad_m[^e]|^bad_me[^t]|^bad_met[^a]"
)
local expect = if isBadMeta:isMatch(file)
local expect = if isBadMeta:isMatch(entry)
then check.should_error
else check.should_not_error
@ -97,7 +97,7 @@ return function(test: typeof(frktest.test))
}
)()
return check.is_true(sourcemap(testProject))
return check.is_true(sourcemap(path))
end)
end)
end

View file

@ -13,13 +13,13 @@ local TEST_PROJECTS_DIRS = {
return function(test: typeof(frktest.test))
test.suite("Generates Rojo valid sync configs", function()
for _, dir in TEST_PROJECTS_DIRS do
for _, file in fs.readDir(dir) do
local fullPath = `{dir}/{file}`
test.case(`{file}`, function()
for _, entry in TEST_PROJECTS_DIRS do
for _, subEntry in fs.readDir(entry) do
local path = `{entry}/{subEntry}`
test.case(`{subEntry}`, function()
local ok, config = syncConfig(
fullPath,
fs.readDir(fullPath),
path,
fs.readDir(path),
{ writeToFile = false, force = true }
)
check.is_true(ok)
@ -29,7 +29,7 @@ return function(test: typeof(frktest.test))
serde.decode("json", config),
serde.decode(
"json",
fs.readFile(`{fullPath}/default.project.json`)
fs.readFile(`{path}/default.project.json`)
)
check.table.contains(realConfig, generatedConfig)