forked from Roblox/jest-roblox
-
Notifications
You must be signed in to change notification settings - Fork 7
Update setup instructions to be clear and add an example project #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YetAnotherClown
wants to merge
6
commits into
jsdotlua:main
Choose a base branch
from
YetAnotherClown:update-docs-add-example-game
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1ef2056
Update Documentation and add an Example Game
YetAnotherClown 4ea0890
Rename `example-game` to `example-project`
YetAnotherClown e913607
Fix `test.sh` script running tests before Darklua finished processing
YetAnotherClown 2f6f7b5
Remove `--watch` flag in `test.sh` for Darklua commands
YetAnotherClown 2c991d8
Merge branch 'main' of https://github.com/jsdotlua/jest-lua into upda…
YetAnotherClown 4ce171b
Migrate aliases to .luaurc
YetAnotherClown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you change the example project to not be using Darklua? It complicates a minimal example and we'll also eventually be moving away from it for most Roblox code thanks to native string requires (though Jest doesn't support this yet.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"process": [ | ||
{ | ||
"rule": "convert_require", | ||
"current": { | ||
"name": "path", | ||
"sources": { | ||
"@Project": "src/", | ||
"@DevPackages": "DevPackages/" | ||
} | ||
}, | ||
"target": { | ||
"name": "roblox", | ||
"rojo_sourcemap": "sourcemap.json", | ||
"indexing_style": "wait_for_child" | ||
} | ||
}, | ||
{ | ||
"rule": "inject_global_value", | ||
"identifier": "NOCOLOR", | ||
"env": "NOCOLOR" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*.rbxlx.lock | ||
/*.rbxl.lock | ||
/*.rbxl | ||
/*.rbxm | ||
|
||
DevPackages/ | ||
dist/ | ||
|
||
sourcemap.json | ||
wally.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"aliases": { | ||
"Project": "src/", | ||
"DevPackages": "DevPackages/" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"luau-lsp.completion.imports.enabled": true, | ||
"luau-lsp.completion.imports.suggestServices": true, | ||
"luau-lsp.completion.imports.suggestRequires": false, | ||
"luau-lsp.require.mode": "relativeToFile", | ||
"luau-lsp.ignoreGlobs": [ | ||
"DevPackages/*", | ||
"dist/*", | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Example Project | ||
|
||
This is an example of how to use Jest-Lua to create unit tests for a library. | ||
|
||
For a setup guide, see the [Getting Started](https://jsdotlua.github.io/jest-lua/) documentation page. | ||
|
||
## Running Tests | ||
|
||
This example has [run-in-roblox](https://github.com/rojo-rbx/run-in-roblox) setup to allow you to run tests from the CLI. | ||
To do so, run the `scripts/test.sh` script and it will open up studio and run your tests. | ||
|
||
If you do not wish to use `run-in-roblox`, you can serve the project with Rojo by running the `scripts/dev.sh`. | ||
Your tests will run and output the results when you run the server in Studio. | ||
|
||
## Project Structure | ||
|
||
You can find our `run-tests.luau` script in the `scripts` folder. | ||
This is where we define our runCLI Options and our project directories for Jest. | ||
|
||
The `jest.config.luau` file can be found in `src`, this is where we tell Jest what should be considered a test and other options. | ||
|
||
The rest of the project has been setup for use with Darklua and String Requires, and provides scripts to make it simple to use. | ||
The structure is based on [roblox-project-template](https://github.com/grilme99/roblox-project-template), | ||
which provides a setup for a Roblox experience with Darklua and more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "JestLuaProject", | ||
"tree": { | ||
"$path": "dist/src" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "JestLuaProject", | ||
"tree": { | ||
"$className": "DataModel", | ||
"ReplicatedStorage": { | ||
"DevPackages": { | ||
"$path": "DevPackages" | ||
}, | ||
"Packages": { | ||
"$className": "Folder", | ||
"Project": { | ||
"$path": "src" | ||
} | ||
} | ||
}, | ||
"ServerScriptService": { | ||
"run-tests": { | ||
"$path": "scripts/run-tests.server.luau" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "JestLuaProject", | ||
"tree": { | ||
"$className": "DataModel", | ||
"ReplicatedStorage": { | ||
"DevPackages": { | ||
"$path": "DevPackages" | ||
}, | ||
"Packages": { | ||
"$className": "Folder", | ||
"Project": { | ||
"$path": "dist/src" | ||
} | ||
} | ||
}, | ||
"ServerScriptService": { | ||
"run-tests": { | ||
"$path": "dist/run-tests.server.luau" | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file lists tools managed by Rokit, a toolchain manager for Roblox projects. | ||
# For more information, see https://github.com/rojo-rbx/rokit | ||
|
||
# New tools can be added by running `rokit add <tool>` in a terminal. | ||
|
||
[tools] | ||
rojo = "rojo-rbx/rojo@7.4.4" | ||
run-in-roblox = "rojo-rbx/run-in-roblox@0.3.0" | ||
wally = "upliftGames/wally@0.3.2" | ||
darklua = "seaofvoices/darklua@0.13.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# If Packages aren't installed, install them. | ||
if [ ! -d "DevPackages" ]; then | ||
sh scripts/install-packages.sh | ||
fi | ||
|
||
rojo sourcemap default.project.json -o sourcemap.json | ||
|
||
darklua process --config .darklua.json src/ dist/src | ||
rojo build build.project.json -o JestLuaProject.rbxm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
# If Packages aren't installed, install them. | ||
if [ ! -d "DevPackages" ]; then | ||
sh scripts/install-packages.sh | ||
fi | ||
|
||
rojo serve dev.project.json \ | ||
& rojo sourcemap default.project.json -o sourcemap.json --watch \ | ||
& darklua process --config .darklua.json --watch src/ dist/src \ | ||
& NOCOLOR=1 darklua process --config .darklua.json --watch scripts/run-tests.server.luau dist/run-tests.server.luau |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
wally install |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
_G.NOCOLOR = _G.NOCOLOR | ||
|
||
local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
local Packages = ReplicatedStorage.Packages | ||
|
||
local Jest = require("@DevPackages/Jest") | ||
|
||
local runCLIOptions = { | ||
verbose = false, | ||
ci = false, | ||
} | ||
|
||
local projects = { | ||
Packages.Project, | ||
} | ||
|
||
Jest.runCLI(script, runCLIOptions, projects):await() | ||
|
||
return nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
OUTPUT=JestLuaProject.rbxl | ||
|
||
# If Packages aren't installed, install them. | ||
if [ ! -d "DevPackages" ]; then | ||
sh scripts/install-packages.sh | ||
fi | ||
|
||
darklua process --config .darklua.json src/ dist/src \ | ||
&& darklua process --config .darklua.json scripts/run-tests.server.luau dist/run-tests.server.luau \ | ||
&& rojo build dev.project.json --output $OUTPUT \ | ||
&& run-in-roblox --place $OUTPUT --script dist/run-tests.server.luau |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
std = "selene_definitions" | ||
|
||
[rules] | ||
global_usage = "allow" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
base: roblox | ||
name: selene_defs | ||
globals: | ||
# override Roblox require style with string requires | ||
require: | ||
args: | ||
- type: string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
return function(a, b) | ||
return a + b | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local JestGlobals = require("@DevPackages/JestGlobals") | ||
|
||
local it = JestGlobals.it | ||
local expect = JestGlobals.expect | ||
|
||
local sum = require("@Project/Sum") | ||
|
||
it("adds 1 + 2 to equal 3", function() | ||
expect(sum(1, 2)).toBe(3) | ||
end) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't technically related to your PR, but
debug.loadmodule
is no longer necessary to run Jest, so that whole line can just be removed. Alternatively, you could add an info block that it is necessary in older versions.run-in-roblox
also isn't necessary anymore thanks to Open Cloud execution. Not sure if this is the best time to change that line though since we don't have a good out-of-the-box story for running Jest in Open Cloud yet. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's cool. I didn't know
debug.loadmodule
was no longer needed, I guess I need to update my dependencies.As for
run-in-roblox
, I think we leave it for now and decide again on this in the future. I do think we could expand the documentation and provide the different options users have for running Jest in the future though.