chore(tests): include test runner powered by lune

This commit is contained in:
Erica Marigold 2024-03-27 18:13:03 +05:30
parent e50a64797a
commit 46b7949422
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
3 changed files with 58 additions and 2 deletions

57
.lune/tests.lua Normal file
View file

@ -0,0 +1,57 @@
local process = require("@lune/process")
local fs = require("@lune/fs")
local stdio = require("@lune/stdio")
local OK = stdio.color("green")
.. stdio.style("bold")
.. " OK"
.. stdio.style("reset")
.. stdio.color("reset")
.. "\n"
.. ""
local FAILED = stdio.color("red")
.. stdio.style("bold")
.. " FAILED"
.. stdio.style("reset")
.. stdio.color("reset")
.. "\n"
-- Adapted from https://github.com/4x8Matrix/Package-Index/blob/Master/.lune/type-check.luau#L10
local function execute(exe, ...): (boolean, string, string)
local res = process.spawn(exe, { ... }, {
stdio = "default",
})
return res.ok, res.stdout, res.stderr
end
function main()
local results = {
passed = 0,
failed = 0,
}
for _, test in fs.readDir("tests/") do
stdio.write(`Running wg::{test:gsub(".luau", "")}...`)
local ok, _out, err = execute("lune", "run", "tests/" .. test)
if ok then
stdio.write(OK)
results.passed += 1
else
stdio.write(FAILED)
print(err:split("\n")[1])
results.failed += 1
end
end
print(`\nResults: passed: {results.passed}; failed: {results.failed}`)
if results.failed > 0 then
process.exit(1)
end
end
return main()

View file

@ -10,6 +10,7 @@
"check_fmt": "prettier -c src/", "check_fmt": "prettier -c src/",
"check": "pnpm lint && pnpm check_fmt", "check": "pnpm lint && pnpm check_fmt",
"fmt": "prettier -w src/", "fmt": "prettier -w src/",
"test": "lune run tests",
"postinstall": "patch -f node_modules/@rbxts/types/include/roblox.d.ts < lune_require_patch.diff", "postinstall": "patch -f node_modules/@rbxts/types/include/roblox.d.ts < lune_require_patch.diff",
"prepublishOnly": "pnpm run build" "prepublishOnly": "pnpm run build"
}, },

View file

@ -19,8 +19,6 @@ export const wireguard: Wireguard = {
const privateKey = generatePrivateKey(); const privateKey = generatePrivateKey();
const publicKey = generatePublicKey(privateKey); const publicKey = generatePublicKey(privateKey);
print(privateKey);
return { return {
publicKey: atob(publicKey), publicKey: atob(publicKey),
privateKey: atob(privateKey), privateKey: atob(privateKey),