Skip to content

Commit 54c5819

Browse files
Merge pull request #19 from ForestOfLight/dev
Add Tests, Linting & CI
2 parents 6f8cc11 + b7e33d9 commit 54c5819

63 files changed

Lines changed: 7486 additions & 344 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [20.14.0]
18+
fail-fast: true
19+
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
cache: 'npm'
29+
30+
- name: Install dependencies
31+
run: npm install
32+
33+
- name: Run ESLint
34+
run: npm run lint
35+
36+
- name: Run tests with coverage
37+
run: npm test
38+
39+
- name: Upload coverage report
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: coverage-report
43+
path: coverage

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/build
22
/.regolith
33
.DS_Store
4-
.vscode/
4+
.vscode/
5+
node_modules/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { vi } from 'vitest'
2+
import { EntityComponentTypes } from '@minecraft/server'
3+
import { Container, Player } from './server'
4+
5+
export function makeEquippable(items = {}) {
6+
return {
7+
getEquipment: vi.fn(slot => items[slot]),
8+
setEquipment: vi.fn(),
9+
}
10+
}
11+
12+
export class SimulatedPlayer extends Player {
13+
#container = new Container()
14+
#equippable = makeEquippable()
15+
16+
headRotation = { x: 0, y: 0 }
17+
18+
navigateToLocation = vi.fn()
19+
navigateToEntity = vi.fn()
20+
navigateToBlock = vi.fn()
21+
moveRelative = vi.fn()
22+
stopMoving = vi.fn()
23+
lookAtBlock = vi.fn()
24+
lookAtEntity = vi.fn()
25+
lookAtLocation = vi.fn()
26+
stopBuild = vi.fn()
27+
stopInteracting = vi.fn()
28+
stopBreakingBlock = vi.fn()
29+
stopUsingItem = vi.fn()
30+
stopSwimming = vi.fn()
31+
stopGliding = vi.fn()
32+
attack = vi.fn()
33+
interact = vi.fn()
34+
useItemInSlot = vi.fn()
35+
dropSelectedItem = vi.fn()
36+
jump = vi.fn()
37+
startBuild = vi.fn()
38+
breakBlock = vi.fn()
39+
getComponent = vi.fn((type) => {
40+
if (type === EntityComponentTypes.Inventory) return { container: this.#container }
41+
if (type === EntityComponentTypes.Equippable) return this.#equippable
42+
return void 0
43+
})
44+
}
45+
46+
export const spawnSimulatedPlayer = vi.fn(() => new SimulatedPlayer())

0 commit comments

Comments
 (0)