Skip to content

Commit 26ec964

Browse files
authored
Merge pull request #544 from Quenty/users/unrooot/unit-testing
ci: Create workflow to execute Jest unit tests with Roblox open cloud
2 parents af926ec + 96485ff commit 26ec964

34 files changed

Lines changed: 1506 additions & 1046 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: run-tests
2+
on: [push]
3+
jobs:
4+
run-tests:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout repository
8+
uses: actions/checkout@v4
9+
with:
10+
fetch-depth: 0
11+
12+
- name: Setup node
13+
uses: actions/setup-node@v2
14+
with:
15+
cache-dependency-path: package.json
16+
node-version: "18"
17+
18+
- name: Install GitHub CLI
19+
run: |
20+
sudo apt update
21+
sudo apt install gh -y
22+
23+
- name: Setup npm for GitHub Packages
24+
run: |
25+
echo -e "\n//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" >> .npmrc
26+
echo -e "\n//npm.pkg.github.com/:_authToken=$GITHUB_TOKEN" >> ~/.npmrc
27+
echo -e "\n//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc
28+
echo -e "\n//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
32+
33+
- name: Install package dependencies
34+
run: |
35+
echo "Installing package dependencies..."
36+
npx lerna exec -- npm install --no-audit
37+
PACKAGES=$(npx lerna ls --since origin/main --json | jq -r '.[] | select(.name != "@quenty/nevermore-cli") | .location' | tr '\n' ' ')
38+
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
39+
40+
- name: Setup test place project
41+
run: |
42+
echo "Setting up test place project from template..."
43+
cp -r tests/test-place-template tests/bin
44+
cd tests/bin
45+
46+
echo "Installing changed packages..."
47+
npm i ${{ env.PACKAGES }}
48+
49+
echo "Installing Jest"
50+
npm i https://github.com/quentystudios/jest-lua.git
51+
52+
- name: Setup Aftman
53+
uses: ok-nick/setup-aftman@v0.4.2
54+
with:
55+
path: tests/bin
56+
version: 'v0.3.0'
57+
token: ${{ secrets.GITHUB_TOKEN }}
58+
59+
- name: Generate test place file
60+
run: rojo build default.project.json -o testBuild.rbxl
61+
working-directory: tests/bin
62+
63+
- name: Publish test place to Roblox and run tests
64+
run: lune run cloud/publish-test-place.luau bin/testBuild.rbxl cloud/run-tests.luau
65+
working-directory: tests
66+
env:
67+
ROBLOX_UNIT_TEST_API_KEY: ${{ secrets.ROBLOX_UNIT_TEST_API_KEY }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ dist
1414
# Normally it's a good idea to commit this. However, in this mono-repo scenario with linking
1515
# it adds a ton of noise and no real gain. Also we have seen no gains from reproducing
1616
# builds so we don't have a strict need for this right now.
17-
package-lock.json
17+
package-lock.json
18+
tests/bin

aftman.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ selene = "Kampfkarren/selene@0.28.0"
99
moonwave-extractor = "UpliftGames/moonwave@1.3.0"
1010
mantle = "blake-mealey/mantle@0.10.7"
1111
remodel = "rojo-rbx/remodel@0.9.1"
12-
luau-lsp = "JohnnyMorganz/luau-lsp@1.27.1"
12+
luau-lsp = "JohnnyMorganz/luau-lsp@1.27.1"
13+
lune = "lune-org/lune@0.8.9"
14+
run-in-roblox = "rojo-rbx/run-in-roblox@0.3.0"

src/binder/src/Shared/BinderProvider.spec.lua

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,42 @@
44

55
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
66

7-
local BinderProvider = require("BinderProvider")
87
local Binder = require("Binder")
8+
local BinderProvider = require("BinderProvider")
9+
local Jest = require("Jest")
910

10-
return function()
11-
describe("BinderProvider.new()", function()
12-
local provider
13-
local initialized = false
11+
local describe = Jest.Globals.describe
12+
local expect = Jest.Globals.expect
13+
local it = Jest.Globals.it
1414

15-
it("should execute immediately", function()
16-
provider = BinderProvider.new("BinderServiceName", function(self, arg)
17-
initialized = true
18-
assert(arg == 12345, "Bad arg")
15+
describe("BinderProvider.new()", function()
16+
local provider
17+
local initialized = false
1918

20-
self:Add(Binder.new("Test", function()
21-
return { Destroy = function() end; }
22-
end))
23-
end)
19+
it("should execute immediately", function()
20+
provider = BinderProvider.new("BinderServiceName", function(self, arg)
21+
initialized = true
22+
assert(arg == 12345, "Bad arg")
2423

25-
expect(provider).to.be.a("table")
24+
self:Add(Binder.new("Test", function()
25+
return { Destroy = function() end; }
26+
end))
2627
end)
2728

28-
it("should initialize", function()
29-
expect(initialized).to.equal(false)
30-
provider:Init(12345)
31-
expect(initialized).to.equal(true)
32-
end)
29+
expect(provider).toEqual(expect.any("table"))
30+
end)
3331

34-
it("should contain the binder", function()
35-
expect(provider.Test).to.be.a("table")
36-
end)
32+
it("should initialize", function()
33+
expect(initialized).toEqual(false)
34+
provider:Init(12345)
35+
expect(initialized).toEqual(true)
36+
end)
3737

38-
provider:Destroy()
38+
it("should contain the binder", function()
39+
expect(provider.Test).toEqual(expect.any("table"))
3940
end)
4041

41-
end
42+
if provider then
43+
provider:Destroy()
44+
end
45+
end)

src/brio/src/Shared/BrioUtils.spec.lua

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,75 @@
44

55
local require = require(game:GetService("ServerScriptService"):FindFirstChild("LoaderUtils", true).Parent).bootstrapStory(script)
66

7-
local BrioUtils = require("BrioUtils")
87
local Brio = require("Brio")
8+
local BrioUtils = require("BrioUtils")
9+
local Jest = require("Jest")
910

10-
return function()
11-
describe("BrioUtils.flatten({})", function()
12-
local brio = BrioUtils.flatten({})
11+
local describe = Jest.Globals.describe
12+
local expect = Jest.Globals.expect
13+
local it = Jest.Globals.it
1314

14-
describe("should return a brio that", function()
15-
it("is a brio", function()
16-
expect(brio).to.be.a("table")
17-
expect(Brio.isBrio(brio)).to.equal(true)
18-
end)
15+
describe("BrioUtils.flatten({})", function()
16+
local brio = BrioUtils.flatten({})
1917

20-
it("is alive", function()
21-
expect(not brio:IsDead()).to.equal(true)
22-
end)
18+
describe("should return a brio that", function()
19+
it("is a brio", function()
20+
expect(brio).toEqual(expect.any("table"))
21+
expect(Brio.isBrio(brio)).toEqual(true)
22+
end)
23+
24+
it("is alive", function()
25+
expect(not brio:IsDead()).toEqual(true)
26+
end)
2327

24-
it("contains a table", function()
25-
expect(brio:GetValue()).to.be.a("table")
26-
end)
28+
it("contains a table", function()
29+
expect(brio:GetValue()).toEqual(expect.any("table"))
30+
end)
2731

28-
it("contains a table with nothing in it", function()
29-
expect(next(brio:GetValue())).to.equal(nil)
30-
end)
32+
it("contains a table with nothing in it", function()
33+
expect(next(brio:GetValue())).toEqual(nil)
3134
end)
3235
end)
36+
end)
3337

34-
describe("BrioUtils.flatten with out a brio in it", function()
35-
local brio = BrioUtils.flatten({
36-
value = 5;
37-
})
38+
describe("BrioUtils.flatten with out a brio in it", function()
39+
local brio = BrioUtils.flatten({
40+
value = 5;
41+
})
3842

39-
describe("should return a brio that", function()
40-
it("is a brio", function()
41-
expect(brio).to.be.a("table")
42-
expect(Brio.isBrio(brio)).to.equal(true)
43-
end)
43+
describe("should return a brio that", function()
44+
it("is a brio", function()
45+
expect(brio).toEqual(expect.any("table"))
46+
expect(Brio.isBrio(brio)).toEqual(true)
47+
end)
4448

45-
it("is alive", function()
46-
expect(not brio:IsDead()).to.equal(true)
47-
end)
49+
it("is alive", function()
50+
expect(not brio:IsDead()).toEqual(true)
51+
end)
4852

49-
it("contains a table", function()
50-
expect(brio:GetValue()).to.be.a("table")
51-
end)
53+
it("contains a table", function()
54+
expect(brio:GetValue()).toEqual(expect.any("table"))
55+
end)
5256

53-
it("contains a table with value", function()
54-
expect(brio:GetValue().value).to.equal(5)
55-
end)
57+
it("contains a table with value", function()
58+
expect(brio:GetValue().value).toEqual(5)
5659
end)
5760
end)
61+
end)
5862

59-
describe("BrioUtils.flatten a dead brio in it", function()
60-
local brio = BrioUtils.flatten({
61-
value = Brio.DEAD;
62-
})
63+
describe("BrioUtils.flatten a dead brio in it", function()
64+
local brio = BrioUtils.flatten({
65+
value = Brio.DEAD;
66+
})
6367

64-
describe("should return a brio that", function()
65-
it("is a brio", function()
66-
expect(brio).to.be.a("table")
67-
expect(Brio.isBrio(brio)).to.equal(true)
68-
end)
68+
describe("should return a brio that", function()
69+
it("is a brio", function()
70+
expect(brio).toEqual(expect.any("table"))
71+
expect(Brio.isBrio(brio)).toEqual(true)
72+
end)
6973

70-
it("is dead", function()
71-
expect(brio:IsDead()).to.equal(true)
72-
end)
74+
it("is dead", function()
75+
expect(brio:IsDead()).toEqual(true)
7376
end)
7477
end)
75-
end
78+
end)

0 commit comments

Comments
 (0)