Uh oh!
There was an error while loading. Please reload this page.
- 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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1ef20564ea0890e9136072f6f7b52c991d84ce171bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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.) |
| 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" | ||
| } | ||
| ] | ||
| } |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "aliases": { | ||
| "Project": "src/", | ||
| "DevPackages": "DevPackages/" | ||
| } | ||
| } |
| 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/*", | ||
| ] | ||
| } |
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "JestLuaProject", | ||
| "tree": { | ||
| "$path": "dist/src" | ||
| } | ||
| } |
| 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" | ||
| } | ||
| } | ||
| } | ||
| } |
| 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" | ||
| } | ||
| } | ||
| } | ||
| } |
| 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" |
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/sh | ||
| set -e | ||
| wally install |
| 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 |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| std = "selene_definitions" | ||
| [rules] | ||
| global_usage = "allow" |
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| return function(a, b) | ||
| return a + b | ||
| end |
| 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) |
Uh oh!
There was an error while loading. Please reload this page.
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.loadmoduleis 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-robloxalso 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.loadmodulewas 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.