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 1 commit
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
Next
Next commit
Update Documentation and add an Example Game
Documentation now provides clear instructions on how to use Jest Lua
- Loading branch information
commit 1ef2056243ee87102b922328d60f42e1b530af01
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,4 +39,3 @@ roblox.toml | |
| # Editor files | ||
| .vscode/launch.json | ||
| .idea | ||
| .vscode | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,10 @@ The Jest Lua API is similar to [the API used by JavaScript Jest.](https://jestjs | |
|
|
||
| Jest Lua currently requires [`run-in-roblox`](https://github.com/rojo-rbx/run-in-roblox) to run from the command line. It can also be run directly inside of Roblox Studio. See issue [#2](https://github.com/jsdotlua/jest-lua/issues/2) for more. | ||
|
|
||
| :::tip | ||
| Checkout the [example game](https://github.com/jsdotlua/jest-lua/tree/main/example-game) to see a full setup of Jest-Lua for a Roblox Library. | ||
| ::: | ||
|
|
||
| Add the `JestGlobals` and `Jest` packages to your `dev-dependencies` in your `wally.toml`. | ||
|
|
||
| ```yaml title="wally.toml" | ||
|
|
@@ -18,7 +22,7 @@ JestGlobals = "jsdotlua/[email protected]" | |
|
|
||
| Run `wally install` to install Jest Lua. | ||
|
|
||
| Create a `default.project.json` to set up your project structure and include the `Packages` directory created by `wally`. | ||
| Create a `default.project.json` to set up your project structure and include the `Packages` and `DevPackages` directories created by `wally`. | ||
|
|
||
| ```json title="default.project.json" | ||
| { | ||
|
|
@@ -30,6 +34,9 @@ Create a `default.project.json` to set up your project structure and include the | |
| "Project": { | ||
| "$path": "src" | ||
| } | ||
| }, | ||
| "DevPackages": { | ||
| "$path": "DevPackages" | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -39,31 +46,20 @@ Create a `run-tests.lua` to point the test runner to the correct directory with | |
|
|
||
| ```lua title="run-tests.lua" | ||
| local ReplicatedStorage = game:GetService("ReplicatedStorage") | ||
| local Packages = ReplicatedStorage.Packages | ||
|
|
||
| local runCLI = require("@DevPackages/Jest").runCLI | ||
|
|
||
| local processServiceExists, ProcessService = pcall(function() | ||
| return game:GetService("ProcessService") | ||
| end) | ||
| local Jest = require("@DevPackages/Jest") | ||
|
|
||
| local status, result = runCLI(ReplicatedStorage.Packages.Project, { | ||
| local runCLIOptions = { | ||
| verbose = false, | ||
| ci = false | ||
| }, { ReplicatedStorage.Packages.Project }):awaitStatus() | ||
|
|
||
| if status == "Rejected" then | ||
| print(result) | ||
| end | ||
| ci = false, | ||
| } | ||
|
|
||
| if status == "Resolved" and result.results.numFailedTestSuites == 0 and result.results.numFailedTests == 0 then | ||
| if processServiceExists then | ||
| ProcessService:ExitAsync(0) | ||
| end | ||
| end | ||
| local projects = { | ||
| Packages.Project, | ||
| } | ||
|
|
||
| if processServiceExists then | ||
| ProcessService:ExitAsync(1) | ||
| end | ||
| Jest.runCLI(script, runCLIOptions, projects):await() | ||
|
|
||
| return nil | ||
| ``` | ||
|
|
@@ -72,7 +68,13 @@ Inside `src`, create a basic [configuration](configuration) file. | |
|
|
||
| ```lua title="jest.config.lua" | ||
| return { | ||
| testMatch = { "**/*.spec" } | ||
| testMatch = { | ||
| "**/__tests__/*.(spec|test)", | ||
| }, | ||
| testPathIgnorePatterns = { | ||
| "Packages", | ||
| "DevPackages", | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -105,13 +107,15 @@ Any functionality needed _must_ be explicitly required from `JestGlobals`, see [ | |
|
|
||
| Before you can run your tests, you need to enable the `debug.loadmodule` API. To do this, you must enable the `FFlagEnableLoadModule` flag. See issue [#3](https://github.com/jsdotlua/jest-lua/issues/3) for more. | ||
|
|
||
| To manage FastFlags for Studio, it is recommended that you use [Roblox Studio Mod Manager](https://github.com/MaximumADHD/Roblox-Studio-Mod-Manager) to set the `FFlagEnableLoadModule` FFlag to true. Or, you can edit your `ClientAppSettings.json` yourself. | ||
|
|
||
| ```json title="ClientAppSettings.json" | ||
| { | ||
| "FFlagEnableLoadModule": true | ||
| } | ||
| ``` | ||
|
|
||
| Finally, run your project using Roblox Studio or `run-in-roblox` to run the tests and your tests should pass! | ||
| Finally, run your project using Roblox Studio or use [run-in-roblox](https://github.com/rojo-rbx/run-in-roblox) to run the tests and your tests should pass! | ||
|
|
||
| ```bash | ||
| run-in-roblox --place test-place.rbxl --script scripts/run-tests.lua | ||
|
|
||
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,15 @@ | ||
| { | ||
| "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.require.directoryAliases": { | ||
| "@Project": "src/", | ||
| "@DevPackages": "DevPackages/" | ||
| }, | ||
| "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/[email protected]" | ||
| run-in-roblox = "rojo-rbx/[email protected]" | ||
| wally = "upliftGames/[email protected]" | ||
| darklua = "seaofvoices/[email protected]" |
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 --watch src/ dist/src \ | ||
| & darklua process --config .darklua.json --watch 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 |
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.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.