@isentinel/jest-roblox 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +299 -0
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +1364 -10
- package/dist/{game-output-DO5fOpW3.mjs → game-output-lpY5mxJ_.mjs} +428 -145
- package/dist/index.d.mts +28 -4
- package/dist/index.mjs +2 -2
- package/dist/{schema-ua9HqdbX.d.mts → schema-CG-f4OUB.d.mts} +23 -1
- package/package.json +24 -8
- package/plugin/JestRobloxRunner.rbxm +0 -0
- package/plugin/out/shared/runner.luau +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# jest-roblox-cli
|
|
2
|
+
|
|
3
|
+
Run your TypeScript and Luau tests inside Roblox, then see the results in your
|
|
4
|
+
terminal.
|
|
5
|
+
|
|
6
|
+
jest-roblox-cli takes your test files, builds a Roblox place, runs the tests
|
|
7
|
+
in Roblox, and brings the results back to you. It works with both roblox-ts
|
|
8
|
+
(TypeScript) and pure Luau projects. For TypeScript projects, it maps errors
|
|
9
|
+
back to your original source.
|
|
10
|
+
|
|
11
|
+
## Why use this?
|
|
12
|
+
|
|
13
|
+
Roblox code needs Roblox to run. You can't test it with normal tools because
|
|
14
|
+
the Roblox API only exists inside the engine. This tool runs your tests in a
|
|
15
|
+
real Roblox session, then reports results in your terminal.
|
|
16
|
+
|
|
17
|
+
- Works with roblox-ts and pure Luau projects
|
|
18
|
+
- For TypeScript projects, maps Luau errors back to your `.ts` files
|
|
19
|
+
- Collects code coverage so you know which lines your tests touch
|
|
20
|
+
- Supports two backends: Roblox Open Cloud (remote) and Roblox Studio (local)
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @isentinel/jest-roblox
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
Create a config file in your project root.
|
|
31
|
+
|
|
32
|
+
**roblox-ts project** (`jest.config.ts`):
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { defineConfig } from "@isentinel/jest-roblox";
|
|
36
|
+
|
|
37
|
+
export default defineConfig({
|
|
38
|
+
placeFile: "./game.rbxl",
|
|
39
|
+
projects: ["ReplicatedStorage/shared"],
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Luau project** (`jest.config.json`):
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"luauRoots": ["./src"],
|
|
48
|
+
"placeFile": "./game.rbxl",
|
|
49
|
+
"projects": ["ReplicatedStorage/shared"]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Then run your tests:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
jest-roblox
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Run all tests
|
|
63
|
+
jest-roblox
|
|
64
|
+
|
|
65
|
+
# Run one file (TypeScript or Luau)
|
|
66
|
+
jest-roblox src/player.spec.ts
|
|
67
|
+
jest-roblox src/player.spec.luau
|
|
68
|
+
|
|
69
|
+
# Filter by test name
|
|
70
|
+
jest-roblox -t "should spawn"
|
|
71
|
+
|
|
72
|
+
# Filter by file path
|
|
73
|
+
jest-roblox --testPathPattern player
|
|
74
|
+
|
|
75
|
+
# Use a specific backend
|
|
76
|
+
jest-roblox --backend studio
|
|
77
|
+
jest-roblox --backend open-cloud
|
|
78
|
+
|
|
79
|
+
# Collect coverage
|
|
80
|
+
jest-roblox --coverage
|
|
81
|
+
|
|
82
|
+
# Output JSON results
|
|
83
|
+
jest-roblox --json --outputFile results.json
|
|
84
|
+
|
|
85
|
+
# Short output for AI tools
|
|
86
|
+
jest-roblox --compact
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
You can put your config in any of these formats (c12 discovers them
|
|
92
|
+
automatically):
|
|
93
|
+
|
|
94
|
+
- `jest.config.ts` / `jest.config.js` / `jest.config.mjs` / `jest.config.cjs`
|
|
95
|
+
- `jest.config.json` / `jest.config.yaml` / `jest.config.toml`
|
|
96
|
+
|
|
97
|
+
CLI flags always win over config file values. Config file values always win over
|
|
98
|
+
built-in defaults.
|
|
99
|
+
|
|
100
|
+
### Config fields
|
|
101
|
+
|
|
102
|
+
| Field | What it does | Default |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| `projects` | Where to look for tests in the DataModel | **required** |
|
|
105
|
+
| `backend` | `"auto"`, `"open-cloud"`, or `"studio"` | `"auto"` |
|
|
106
|
+
| `placeFile` | Path to your `.rbxl` file | `"./game.rbxl"` |
|
|
107
|
+
| `timeout` | Max time for tests to run (ms) | `300000` (5 min) |
|
|
108
|
+
| `sourceMap` | Map Luau errors back to TypeScript (roblox-ts only) | `true` |
|
|
109
|
+
| `port` | WebSocket port for Studio backend | `3001` |
|
|
110
|
+
| `testMatch` | Glob patterns that find test files | `**/*.spec.ts`, `**/*.test.ts`, etc. |
|
|
111
|
+
| `testPathIgnorePatterns` | Patterns to skip | `/node_modules/`, `/dist/` |
|
|
112
|
+
| `rojoProject` | Path to your Rojo project file | auto |
|
|
113
|
+
| `jestPath` | Where Jest lives in the DataModel | auto |
|
|
114
|
+
| `setupFiles` | Scripts to run before the test environment loads | — |
|
|
115
|
+
| `setupFilesAfterEnv` | Scripts to run after the test environment loads | — |
|
|
116
|
+
|
|
117
|
+
### Coverage fields
|
|
118
|
+
|
|
119
|
+
| Field | What it does | Default |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `collectCoverage` | Turn on coverage | `false` |
|
|
122
|
+
| `coverageDirectory` | Where to write coverage reports | `"coverage"` |
|
|
123
|
+
| `coverageReporters` | Which report formats to use | `["text", "lcov"]` |
|
|
124
|
+
| `coverageThreshold` | Minimum coverage to pass | — |
|
|
125
|
+
| `coveragePathIgnorePatterns` | Files to leave out of coverage | test files, node_modules |
|
|
126
|
+
| `collectCoverageFrom` | Globs for files to include in coverage | — |
|
|
127
|
+
| `luauRoots` | Where Luau files live (auto from tsconfig `outDir` for roblox-ts, or set by hand for pure Luau) | auto |
|
|
128
|
+
|
|
129
|
+
### Full example (roblox-ts)
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { defineConfig } from "@isentinel/jest-roblox";
|
|
133
|
+
|
|
134
|
+
export default defineConfig({
|
|
135
|
+
backend: "open-cloud",
|
|
136
|
+
collectCoverage: true,
|
|
137
|
+
coverageThreshold: {
|
|
138
|
+
branches: 70,
|
|
139
|
+
functions: 80,
|
|
140
|
+
statements: 80,
|
|
141
|
+
},
|
|
142
|
+
jestPath: "ReplicatedStorage/Packages/Jest",
|
|
143
|
+
placeFile: "./game.rbxl",
|
|
144
|
+
projects: ["ReplicatedStorage/client", "ServerScriptService/server"],
|
|
145
|
+
timeout: 60000,
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Full example (Luau)
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"backend": "open-cloud",
|
|
154
|
+
"collectCoverage": true,
|
|
155
|
+
"coverageThreshold": {
|
|
156
|
+
"branches": 70,
|
|
157
|
+
"functions": 80,
|
|
158
|
+
"statements": 80
|
|
159
|
+
},
|
|
160
|
+
"jestPath": "ReplicatedStorage/Packages/Jest",
|
|
161
|
+
"luauRoots": ["./src"],
|
|
162
|
+
"placeFile": "./game.rbxl",
|
|
163
|
+
"projects": ["ReplicatedStorage/client", "ServerScriptService/server"],
|
|
164
|
+
"timeout": 60000
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Backends
|
|
169
|
+
|
|
170
|
+
jest-roblox-cli can run tests two ways:
|
|
171
|
+
|
|
172
|
+
### Open Cloud (remote)
|
|
173
|
+
|
|
174
|
+
Uploads your place file to Roblox, runs the tests there, and polls for results.
|
|
175
|
+
|
|
176
|
+
You need these environment variables:
|
|
177
|
+
|
|
178
|
+
| Variable | What it is |
|
|
179
|
+
|---|---|
|
|
180
|
+
| `ROBLOX_OPEN_CLOUD_API_KEY` | Your Open Cloud API key |
|
|
181
|
+
| `ROBLOX_UNIVERSE_ID` | The universe to run tests in |
|
|
182
|
+
| `ROBLOX_PLACE_ID` | The place to run tests in |
|
|
183
|
+
|
|
184
|
+
### Studio (local)
|
|
185
|
+
|
|
186
|
+
Connects to Roblox Studio on your machine through a WebSocket plugin. This is
|
|
187
|
+
faster because there is no upload step, but requires Roblox Studio to be open
|
|
188
|
+
and running the plugin.
|
|
189
|
+
|
|
190
|
+
> [!TIP]
|
|
191
|
+
> In auto mode, the CLI tries Studio first. If Studio is not running, it falls back to Open Cloud.
|
|
192
|
+
|
|
193
|
+
## CLI flags
|
|
194
|
+
|
|
195
|
+
| Flag | What it does |
|
|
196
|
+
|---|---|
|
|
197
|
+
| `--backend <type>` | Choose `auto`, `open-cloud`, or `studio` |
|
|
198
|
+
| `--port <n>` | WebSocket port for Studio |
|
|
199
|
+
| `--config <path>` | Path to config file |
|
|
200
|
+
| `--testPathPattern <regex>` | Filter test files by path |
|
|
201
|
+
| `-t, --testNamePattern <regex>` | Filter tests by name |
|
|
202
|
+
| `--json` | Output results as JSON |
|
|
203
|
+
| `--compact` | Short output for AI tools |
|
|
204
|
+
| `--outputFile <path>` | Write results to a file |
|
|
205
|
+
| `--coverage` | Collect coverage |
|
|
206
|
+
| `--coverageDirectory <path>` | Where to put coverage reports |
|
|
207
|
+
| `--coverageReporters <r...>` | Which report formats to use |
|
|
208
|
+
| `--luauRoots <path...>` | Where compiled Luau files live |
|
|
209
|
+
| `-u, --updateSnapshot` | Update snapshot files |
|
|
210
|
+
| `--sourceMap` | Map Luau errors to TypeScript (roblox-ts only) |
|
|
211
|
+
| `--rojoProject <path>` | Path to Rojo project file |
|
|
212
|
+
| `--verbose` | Show each test result |
|
|
213
|
+
| `--silent` | Hide all output |
|
|
214
|
+
| `--no-color` | Turn off colors |
|
|
215
|
+
| `--no-cache` | Force a fresh place file upload |
|
|
216
|
+
| `--pollInterval <ms>` | How often to check for results (Open Cloud) |
|
|
217
|
+
| `--projects <path...>` | DataModel paths that hold tests |
|
|
218
|
+
| `--setupFiles <path...>` | Scripts to run before env |
|
|
219
|
+
| `--setupFilesAfterEnv <path...>` | Scripts to run after env |
|
|
220
|
+
| `--typecheck` | Run type tests too |
|
|
221
|
+
| `--typecheckOnly` | Run only type tests |
|
|
222
|
+
| `--typecheckTsconfig <path>` | tsconfig for type tests |
|
|
223
|
+
|
|
224
|
+
## How it works
|
|
225
|
+
|
|
226
|
+
1. Scans your project for files that match `testMatch` patterns
|
|
227
|
+
2. Uses Rojo to build a `.rbxl` file with your code
|
|
228
|
+
3. Sends the place to Roblox via Open Cloud or Studio over WebSocket
|
|
229
|
+
4. Reads Jest JSON output from the Roblox session
|
|
230
|
+
5. For roblox-ts projects, turns Luau line numbers into TypeScript line numbers
|
|
231
|
+
using source maps
|
|
232
|
+
6. Prints pass/fail results in your terminal
|
|
233
|
+
|
|
234
|
+
> [!NOTE]
|
|
235
|
+
> For coverage, there are extra steps. The tool copies your Luau files, adds
|
|
236
|
+
> tracking code to each line, and builds a special place file. After the tests
|
|
237
|
+
> run, it maps the tracking data back to your source. For roblox-ts projects, it
|
|
238
|
+
> maps through source maps to show TypeScript lines.
|
|
239
|
+
|
|
240
|
+
## Test file patterns
|
|
241
|
+
|
|
242
|
+
The tool finds test files by these patterns (you can change them with
|
|
243
|
+
`testMatch`):
|
|
244
|
+
|
|
245
|
+
- TypeScript: `*.spec.ts`, `*.test.ts`, `*.spec.tsx`, `*.test.tsx`
|
|
246
|
+
- Luau: `*.spec.lua`, `*.test.lua`, `*.spec.luau`, `*.test.luau`
|
|
247
|
+
- Type tests: `*.spec-d.ts`, `*.test-d.ts`
|
|
248
|
+
|
|
249
|
+
## Project structure
|
|
250
|
+
|
|
251
|
+
```text
|
|
252
|
+
jest-roblox-cli/
|
|
253
|
+
├── bin/ CLI entry point
|
|
254
|
+
├── src/
|
|
255
|
+
│ ├── backends/ Open Cloud and Studio backends
|
|
256
|
+
│ ├── config/ Config loading and validation
|
|
257
|
+
│ ├── coverage/ Coverage instrumentation pipeline
|
|
258
|
+
│ ├── formatters/ Human, JSON, and compact output
|
|
259
|
+
│ ├── reporter/ Result parsing and validation
|
|
260
|
+
│ ├── source-mapper/ Luau-to-TypeScript error mapping
|
|
261
|
+
│ ├── snapshot/ Snapshot file handling
|
|
262
|
+
│ ├── typecheck/ Type test runner
|
|
263
|
+
│ ├── types/ Shared type definitions
|
|
264
|
+
│ └── utils/ Helpers (glob, hash, cache, paths)
|
|
265
|
+
├── luau/ Luau code that runs inside Roblox
|
|
266
|
+
├── plugin/ Roblox Studio WebSocket plugin
|
|
267
|
+
└── test/ Test fixtures and mocks
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Contributing
|
|
271
|
+
|
|
272
|
+
### Build
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
pnpm build # Full build
|
|
276
|
+
pnpm watch # Watch mode
|
|
277
|
+
pnpm typecheck # Check types
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Test
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
vitest run # All tests
|
|
284
|
+
vitest run src/formatters # One folder
|
|
285
|
+
vitest run src/cli.spec.ts # One file
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### Lint
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
eslint .
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
> [!IMPORTANT]
|
|
295
|
+
> This project keeps 100% test coverage. Write tests before you write code. Every pull request must keep full coverage.
|
|
296
|
+
|
|
297
|
+
## License
|
|
298
|
+
|
|
299
|
+
MIT
|
package/dist/cli.d.mts
CHANGED