-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,539 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,82 @@ | ||
# Jestronaut - Garry's Mod Addon` | ||
|
||
## Installation | ||
|
||
1. Download the addon from the latest Jestronaut release from the | ||
[releases page](https://github.com/luttje/jestronaut/releases). | ||
|
||
2. Extract the contents of the `gmod-addon.zip` file to your Garry's Mod `addons` folder. | ||
|
||
3. Restart Garry's Mod if it was running. | ||
|
||
## Usage | ||
|
||
1. Create some test files in your project, for example: | ||
|
||
```lua | ||
-- lua/tests/print_test.lua | ||
|
||
describe("print", function() | ||
it("should print 'Hello, World!'", function() | ||
local mockFn = jestronaut:fn() | ||
|
||
expect(mockFn)['not']:toHaveBeenCalled() | ||
mockFn("Hello, World!") | ||
|
||
expect(mockFn):toHaveBeenCalledWith("Hello, World!") | ||
end) | ||
end) | ||
``` | ||
|
||
2. Create a runner script in your project, for example: | ||
|
||
```lua | ||
-- lua/run-all-tests.lua | ||
|
||
include("gmod-jestronaut.lua"):withGlobals() | ||
|
||
jestronaut | ||
:configure({ | ||
roots = { | ||
-- Where your tests are located, needed for the reporter to find the source files: | ||
"lua/tests/", | ||
}, | ||
|
||
-- Prints to console: | ||
reporter = GmodReporter | ||
}) | ||
:registerTests(function() | ||
include("tests/print_test.lua") | ||
end) | ||
:runTests() | ||
``` | ||
|
||
3. Run the runner script in Garry's Mod: | ||
|
||
``` | ||
lua_openscript run-all-tests.lua | ||
Running script run-all-tests.lua... | ||
🚀 Starting 2 tests at 17:26:02... | ||
|
||
STARTED: o root | ||
|
||
STARTED: o print | ||
|
||
STARTED: o should print 'Hello, World!' | ||
|
||
FINISHED: ✓ should print 'Hello, World!' | ||
|
||
FINISHED: ✓ print | ||
|
||
FINISHED: ✓ root | ||
|
||
|
||
🎉 All tests passed. Great job! | ||
|
||
Tests: 2 passed, 2 total | ||
Time: 0.0019999999999527s | ||
|
||
Ran all test suites. | ||
``` | ||
|
||
*Note that the emoji icons are displayed as `□□` in the Garry's Mod console due to insufficient Unicode support.* |
This file contains 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,37 @@ | ||
-- Gmod's require doesn't return any values, so we replace require with include while loading jestronaut | ||
-- This is a hacky way to make jestronaut work with Gmod | ||
function callWithRequireCompat(func) | ||
local oldRequire = require | ||
local alreadyRequired = {} | ||
|
||
package.path = package.path or "" | ||
|
||
require = function(path) | ||
if (alreadyRequired[path] == nil) then | ||
if (file.Exists(path .. ".lua", "LUA")) then | ||
alreadyRequired[path] = {include(path .. ".lua")} | ||
else | ||
Msg("Could not find file: " .. path) | ||
return false | ||
end | ||
end | ||
|
||
return unpack(alreadyRequired[path]) | ||
end | ||
|
||
local result = func() | ||
|
||
require = oldRequire | ||
|
||
return result | ||
end | ||
|
||
local jestronaut = callWithRequireCompat(function() | ||
local jestronaut = include("jestronaut.lua") | ||
|
||
GmodReporter = include("gmod-reporter.lua").GmodReporter | ||
|
||
return jestronaut | ||
end) | ||
|
||
return jestronaut |
Oops, something went wrong.