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

View file

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

View file

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

View file

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