Skip to content

Commit

Permalink
docs: Align docs with community tools and expectations (#5)
Browse files Browse the repository at this point in the history
* feat: Update README.md

* docs: Replace Jest Roblox references with Jest Lua

* ci: Setup docs deployment

* docs: Update version

* docs: Align with community
  • Loading branch information
grilme99 committed Mar 4, 2024
1 parent 257ae54 commit 1cd25c7
Show file tree
Hide file tree
Showing 27 changed files with 12,023 additions and 241 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Docs

on:
push:
branches:
- main

permissions:
contents: write

jobs:
deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
cache: yarn

- name: Install dependencies
run: yarn install --frozen-lockfile
working-directory: ./docs
- name: Build website
run: yarn build
working-directory: ./docs

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/build
user_name: github-actions[bot]
user_email: 41898282+github-actions[bot]@users.noreply.github.com
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Packages/*
/docs/.docusaurus
/docs/build
/docs/node_modules
/docs/yarn.lock

# Selene
roblox.toml
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Jest Roblox Changelog
# Jest Lua Changelog

## Unreleased Changes

Expand Down Expand Up @@ -209,7 +209,7 @@
* Added `toMatchSnapshot` matcher
* Added `toThrowErrorMatchingSnapshot` matcher
* Added custom snapshot matchers and property matchers, refer to the "Snapshot Testing" section of the documentation for more info
* Added `UPDATESNAPSHOT` flag for updating snapshots, the value can either be `all` (by default), or `new` to only add new snapshots, this can be enabled with an `--updateSnapshot` flag in Jest Roblox CLI
* Added `UPDATESNAPSHOT` flag for updating snapshots, the value can either be `all` (by default), or `new` to only add new snapshots, this can be enabled with an `--updateSnapshot` flag in Jest Lua CLI
* :rotating_light: Removed colon syntax alias for initializing mock functions
* :hammer_and_wrench: `--fastFlags.overrides "UseDateTimeType3=true"` removed as it is no longer needed
* :bug: Fix issue with CoreScriptConverter and the Modules directory ([#79](https://github.com/Roblox/jest-roblox-internal/pull/79))
Expand Down Expand Up @@ -269,7 +269,7 @@ expect().toReturnWith() also aliased as expect().toHaveReturnedWith()
* :sparkles: Added `expect().toThrow()` ([#30](https://github.com/Roblox/jest-roblox-internal/pull/30))
## 0.5.0 (2021-01-29)
* :sparkles: Initial release of Jest Roblox, TestEZ has been rebranded as of this release.
* :sparkles: Initial release of Jest Lua, TestEZ has been rebranded as of this release.
* :sparkles: Added `expect` aligned to [Jest's expect (26.5.3)](https://jestjs.io/docs/en/26.5/expect)
* Requires an explicit `require` from [`JestRoblox.Globals`](https://jestjs.io/docs/en/26.5/api) to use
* Refer to the Jest documentation on expect for usage documentation. Refer to the `README.md` in `src/Modules/expect` for details on deviations from upstream
Expand Down
12 changes: 6 additions & 6 deletions Docs.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Jest Roblox Docs
# Jest Lua Docs

The Jest Roblox API is similar to [the API used by JavaScript Jest.](https://jestjs.io/docs/27.x/api)
The Jest Lua API is similar to [the API used by JavaScript Jest.](https://jestjs.io/docs/27.x/api)

# Usage

Jest Roblox doesn't inject any global variables. Every jest functionality needs to be imported from `JestGlobals`. For example:
Jest Lua doesn't inject any global variables. Every jest functionality needs to be imported from `JestGlobals`. For example:

```lua
local JestGlobals = require(Packages.Dev.JestGlobals)
local JestGlobals = require("@DevPackages/JestGlobals")

local describe = JestGlobals.describe
local expect = JestGlobals.expect
Expand Down Expand Up @@ -444,13 +444,13 @@ Should be the same taking into account [not supported matchers](#expect)

### [Promises](https://jestjs.io/docs/27.x/asynchronous#promises)

Tests can return a [Promise](https://github.com/evaera/roblox-lua-promise) and Jest Roblox will wait for the promise to resolve.
Tests can return a [Promise](https://github.com/evaera/roblox-lua-promise) and Jest Lua will wait for the promise to resolve.

> **Note:** It is also worth noting that tests can ONLY return either a `Promise` or `nil`.
### [Callbacks](https://jestjs.io/docs/27.x/asynchronous#callbacks)

Jest Roblox supports `done` callback as a second param to the test function
Jest Lua supports `done` callback as a second param to the test function
eg.

```lua
Expand Down
52 changes: 24 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
<h1 align="center">Jest Roblox</h1>
<div align="center">
<a href="https://github.com/Roblox/jest-roblox-internal/actions?query=workflow%3ACI">
<img src="https://github.com/Roblox/jest-roblox-internal/workflows/CI/badge.svg" alt="GitHub Actions Build Status" />
</a>
<a href="https://roblox.github.io/jest-roblox-internal/">
<img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
</a>
<a href='https://coveralls.io/github/Roblox/jest-roblox-internal'>
<img src='https://coveralls.io/repos/github/Roblox/jest-roblox-internal/badge.svg?t=4czPqO&kill_cache=1' alt='Coverage Status' />
</a>
</div>
<img src="https://raw.githubusercontent.com/jsdotlua/branding/main/Logo.png" align="right" height="128"/>

<div align="center">
Lovely Lua Testing
</div>
# Jest Lua

<div>&nbsp;</div>
<h3>Delightful Lua Testing.</h3>

Jest Roblox can run within Roblox itself, as well as inside roblox-cli for testing on CI systems.
[![Tests](https://github.com/jsdotlua/jest-lua/actions/workflows/test.yml/badge.svg)](https://github.com/jsdotlua/jest-lua/actions/workflows/test.yml)
<!-- [![Coverage Status](https://coveralls.io/repos/github/Roblox/roact-alignment/badge.svg?branch=master&t=TvTSze)](https://coveralls.io/github/Roblox/roact-alignment?branch=master) -->
[![Docs](https://img.shields.io/badge/docs-website-green.svg)](https://jsdotlua.github.io/jest-lua/)

We use Jest Roblox at Roblox for testing our apps, in-game core scripts, built-in Roblox Studio plugins, as well as libraries like [Roact Navigation](https://github.com/Roblox/roact-navigation).
---

Jest Lua can currently only run inside of Roblox. Help is wanted to get it running in other Lua environments, such as [Lune](https://lune.gitbook.io/lune/) or [Luvit](https://luvit.io/). See issue [#2](https://github.com/jsdotlua/jest-lua/issues/2).

Roblox uses Jest Lua internally for testing their apps, in-game core scripts, built-in Roblox Studio plugins, as well as libraries like [Roact Navigation](https://github.com/Roblox/roact-navigation). This library should be considered battle-tested and ready for production use.

---

Add this package to your `dev_dependencies` in your `rotriever.toml`, for example:
```
JestGlobals = "github.com/Roblox/jest-roblox@2.2.0"
# Installation

Add this package to your `dev-dependencies` in your `wally.toml`, for example:

```toml
JestGlobals = "jsdotlua/jest-globals@3.6.1-rc.2"
```

Then, require anything you need from `JestGlobals`:
```
local JestGlobals = require(Packages.JestGlobals)

```lua
local JestGlobals = require("@Packages/JestGlobals")
local expect = JestGlobals.expect
```

---

## Inspiration and Prior Work
Jest Roblox is a Roblox port of the open source JavaScript testing framework [Jest](https://github.com/facebook/jest). Modules in the `modules` directory are aligned to [v27.4.7](https://github.com/facebook/jest/tree/v27.4.7) of Jest.

---
Jest Lua is a Lua port of the open source JavaScript testing framework [Jest](https://github.com/facebook/jest). Modules in the `modules` directory are aligned to [v27.4.7](https://github.com/facebook/jest/tree/v27.4.7) of Jest.

## Contributing

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for information.

## License
Jest Roblox is available under the MIT license. See [LICENSE](LICENSE) for details.

Jest Lua is available under the MIT license. See [LICENSE](LICENSE) for details.
33 changes: 0 additions & 33 deletions docs/README.md

This file was deleted.

11 changes: 6 additions & 5 deletions docs/docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ title: runCLI Options
---
<p><a href='https://jestjs.io/docs/27.x/cli' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a></p> <img alt='Deviation' src='img/deviation.svg'/>

The `Jest` packages exports `runCLI`, which is the main entrypoint to run Jest Roblox tests. In your entrypoint script, import `runCLI` from the `Jest` package. A basic entrypoint script can look like the following:
The `Jest` packages exports `runCLI`, which is the main entrypoint to run Jest Lua tests. In your entrypoint script, import `runCLI` from the `Jest` package. A basic entrypoint script can look like the following:

```lua title="spec.lua"
local Packages = script.Parent.YourProject.Packages
local runCLI = require(Packages.Dev.Jest).runCLI
local runCLI = require("@Packages/Jest").runCLI

local processServiceExists, ProcessService = pcall(function()
return game:GetService("ProcessService")
Expand Down Expand Up @@ -35,7 +36,7 @@ end
return nil
```

The first argument to `runCLI` is the root directory of your project, the second argument is a list of [options](#options), and the third argument is a list of projects (directories with a `jest.config.lua`) for Jest Roblox to discover.
The first argument to `runCLI` is the root directory of your project, the second argument is a list of [options](#options), and the third argument is a list of projects (directories with a `jest.config.lua`) for Jest Lua to discover.

## Options

Expand All @@ -50,7 +51,7 @@ import TOCInline from "@theme/TOCInline";
### `ci` \[boolean]
<a href='https://jestjs.io/docs/27.x/cli#--ci' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='Aligned' src='img/aligned.svg'/>

When this option is provided, Jest Roblox will assume it is running in a CI environment. This changes the behavior when a new snapshot is encountered. Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest Roblox to be run with `updateSnapshot`.
When this option is provided, Jest Lua will assume it is running in a CI environment. This changes the behavior when a new snapshot is encountered. Instead of the regular behavior of storing a new snapshot automatically, it will fail the test and require Jest Lua to be run with `updateSnapshot`.

### `clearMocks` \[boolean]
<a href='https://jestjs.io/docs/27.x/cli#--clearmocks' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='Aligned' src='img/aligned.svg'/>
Expand All @@ -75,7 +76,7 @@ Prints the test results in JSON. This mode will send all other test output and u
### `listTests` \[boolean]
<a href='https://jestjs.io/docs/27.x/cli#--listtests' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='Aligned' src='img/aligned.svg'/>

Lists all test files that Jest Roblox will run given the arguments, and exits.
Lists all test files that Jest Lua will run given the arguments, and exits.

### `noStackTrace` \[boolean]
<a href='https://jestjs.io/docs/27.x/cli#--nostacktrace' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='Aligned' src='img/aligned.svg'/>
Expand Down
34 changes: 17 additions & 17 deletions docs/docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Configuring Jest
---
<p><a href='https://jestjs.io/docs/27.x/configuration' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a></p>

The Jest Roblox philosophy is to work great by default, but sometimes you just need more configuration power.
The Jest Lua philosophy is to work great by default, but sometimes you just need more configuration power.

<img alt='deviation' src='img/deviation.svg'/>

Expand Down Expand Up @@ -56,7 +56,7 @@ return {
}
```

Alternatively, a table with the keys `name` and `color` can be passed. This allows for a custom configuration of the background color of the displayName. `displayName` defaults to white when its value is a string. Jest Roblox uses [`chalk-lua`](https://github.com/Roblox/chalk-lua) to provide the color. As such, all of the valid options for colors supported by `chalk-lua` are also supported by Jest Roblox.
Alternatively, a table with the keys `name` and `color` can be passed. This allows for a custom configuration of the background color of the displayName. `displayName` defaults to white when its value is a string. Jest Lua uses [`chalk-lua`](https://github.com/Roblox/chalk-lua) to provide the color. As such, all of the valid options for colors supported by `chalk-lua` are also supported by Jest Lua.

```lua
return {
Expand All @@ -72,15 +72,15 @@ return {

Default: `nil`

When the `projects` configuration is provided with an array of instances, Jest Roblox will run tests in all of the specified projects at the same time. This is great for monorepos or when working on multiple projects at the same time.
When the `projects` configuration is provided with an array of instances, Jest Lua will run tests in all of the specified projects at the same time. This is great for monorepos or when working on multiple projects at the same time.

```lua
return {
projects = { Workspace.ProjectB, Workspace.ProjectB },
}
```

This example configuration will run Jest Roblox in the `ProjectA` as well as the `ProjectB` directories. You can have an unlimited amount of projects running in the same Jest Roblox instance.
This example configuration will run Jest Lua in the `ProjectA` as well as the `ProjectB` directories. You can have an unlimited amount of projects running in the same Jest Lua instance.

:::tip

Expand All @@ -98,13 +98,13 @@ Automatically restore mock state and implementation before every test. Equivalen
### `rootDir` \[Instance]
<a href='https://jestjs.io/docs/27.x/configuration#rootdir-string' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='API change' src='img/apichange.svg'/>

Default: The root of the directory containing your Jest Roblox [config file](#).
Default: The root of the directory containing your Jest Lua [config file](#).

The root directory that Jest Roblox should scan for tests and modules within.
The root directory that Jest Lua should scan for tests and modules within.

Oftentimes, you'll want to set this to your main workspace, corresponding to where in your repository the code is stored.

<!-- The root directory that Jest Roblox should scan for tests and modules within. If you put your Jest config inside your `package.json` and want the root directory to be the root of your repo, the value for this config param will default to the directory of the `package.json`.
<!-- The root directory that Jest Lua should scan for tests and modules within. If you put your Jest config inside your `package.json` and want the root directory to be the root of your repo, the value for this config param will default to the directory of the `package.json`.
Oftentimes, you'll want to set this to `'src'` or `'lib'`, corresponding to where in your repository the code is stored.
Expand All @@ -119,9 +119,9 @@ Using `'<rootDir>'` as a string token in any other path-based configuration sett

Default: `{<rootDir>}`

A list of paths to directories that Jest Roblox should use to search for files in.
A list of paths to directories that Jest Lua should use to search for files in.

There are times where you only want Jest Roblox to search in a single sub-directory (such as cases where you have a `src/` directory in your repo), but prevent it from accessing the rest of the repo.
There are times where you only want Jest Lua to search in a single sub-directory (such as cases where you have a `src/` directory in your repo), but prevent it from accessing the rest of the repo.

### `setupFiles` \[array&lt;ModuleScript&gt;]
<a href='https://jestjs.io/docs/27.x/configuration#setupfiles-array' target="_blank"><img alt='Jest' src='img/jestjs.svg'/></a> <img alt='API change' src='img/apichange.svg'/>
Expand All @@ -139,7 +139,7 @@ A list of ModuleScripts that run some code to configure or set up the testing fr

In other words, `setupFilesAfterEnv` modules are meant for code which is repeating in each test file. Having the test framework installed makes Jest [globals](api), [`jest` object](jest-object) and [`expect`](expect) accessible in the modules. For example, you can add [extra matchers](expect#expectextendmatchers) or call [setup and teardown](setup-teardown) hooks:
```lua title="setupJest.lua"
local JestGlobals = require(Packages.JestGlobals)
local JestGlobals = require("@DevPackages/JestGlobals")
local jest = JestGlobals.jest
local expect = JestGlobals.expect
local afterEach = JestGlobals.afterEach
Expand Down Expand Up @@ -208,9 +208,9 @@ TextLabel {

Default: `{}`

A list of snapshot serializers Jest Roblox should use for snapshot testing.
A list of snapshot serializers Jest Lua should use for snapshot testing.

Jest Roblox has default serializers for built-in Lua types, Roblox types and Instances, and React Roblox elements.
Jest Lua has default serializers for built-in Lua types, Roblox types and Instances, and React Roblox elements.

```lua title="customSerializer.lua"
local function serialize(val, config, indentation, depth, refs, printer)
Expand All @@ -230,7 +230,7 @@ return {

`printer` is a function that serializes a value using existing plugins.

Add `customSerializer` to your Jest Roblox configuration:
Add `customSerializer` to your Jest Lua configuration:
```lua
return {
snapshotSerializers = { Workspace.customSerializer }
Expand Down Expand Up @@ -267,11 +267,11 @@ More about serializers API can be found [here](https://github.com/facebook/jest/

Default: `1`

The exit code Jest Roblox returns on test failure.
The exit code Jest Lua returns on test failure.

:::info

This does not change the exit code in the case of Jest Roblox errors (e.g. invalid configuration).
This does not change the exit code in the case of Jest Lua errors (e.g. invalid configuration).

:::

Expand All @@ -280,7 +280,7 @@ This does not change the exit code in the case of Jest Roblox errors (e.g. inval

Default: `{ "**/__tests__/**/*", "**/?(*.)+(spec|test)" }`

The glob patterns Jest Roblox uses to detect test files.
The glob patterns Jest Lua uses to detect test files.
By default it looks for `.spec` or `.test` files inside of `__tests__` folders, as well as any files with a suffix of `.test` or `.spec` (e.g. `Component.test.lua` or `Component.spec.lua`). It will also find files called `test.lua` or `spec.lua`.

See the [micromatch](https://github.com/micromatch/micromatch) package for details of the patterns you can specify.
Expand All @@ -307,7 +307,7 @@ An array of regexp pattern strings that are matched against all test paths befor

Default: `{}`

The pattern or patterns Jest Roblox uses to detect test files. See also [`testMatch` [array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.
The pattern or patterns Jest Lua uses to detect test files. See also [`testMatch` [array&lt;string&gt;]](#testmatch-arraystring), but note that you cannot specify both options.

:::info

Expand Down
Loading

0 comments on commit 1cd25c7

Please sign in to comment.