Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leaftail1880 committed Aug 27, 2024
1 parent 1105cda commit 357699f
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 26 deletions.
5 changes: 4 additions & 1 deletion src/lib/database/player.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ describe('player database', () => {

it('should skip respawns', () => {
// @ts-expect-error
EventSignal.emit(world.afterEvents.playerSpawn, { initialRespawn: false })
const player = new Player() as Player

// @ts-expect-error
EventSignal.emit(world.afterEvents.playerSpawn, { player, initialRespawn: false })
})
})
9 changes: 4 additions & 5 deletions src/lib/load/watchdog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const reasons: Record<WatchdogTerminateReason, string> = {
StackOverflow: 'Стэк переполнен',
}

if (!__VITEST__)
system.beforeEvents.watchdogTerminate.subscribe(event => {
world.say('§cСобакаСутулая: §f' + reasons[event.terminateReason])
event.cancel = true
})
system.beforeEvents.watchdogTerminate.subscribe(event => {
world.say('§cСобакаСутулая: §f' + reasons[event.terminateReason])
event.cancel = true
})
3 changes: 0 additions & 3 deletions src/lib/location.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { Player } from '@minecraft/server'
import 'lib/extensions/player'

import 'lib/database/player'
import 'lib/database/scoreboard'
import { MockInstance, beforeEach, describe, expect, it, vi } from 'vitest'
import { location, locationWithRadius, locationWithRotation, migrateLocationName } from './location'
Expand Down
5 changes: 1 addition & 4 deletions src/lib/region/kinds/region.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Player } from '@minecraft/server'
import 'lib/load/extensions'

import { Vector } from 'lib'
import 'lib/database/player'
import { Vector } from 'lib/vector'
import { describe, expect, it } from 'vitest'
import { SphereArea } from '../areas/sphere'
import { Region } from './region'
Expand Down
3 changes: 0 additions & 3 deletions src/lib/region/kinds/safe-area.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'lib/database/player'
import 'lib/load/extensions'

import { Vector } from 'lib/vector'
import { describe, expect, it } from 'vitest'
import { SphereArea } from '../areas/sphere'
Expand Down
4 changes: 0 additions & 4 deletions src/lib/roles.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import 'lib/load/enviroment'

import 'lib/database/player'

import { GameMode, Player } from '@minecraft/server'
import { describe, expect, it } from 'vitest'
import { getRole, setRole } from './roles'
Expand Down
3 changes: 0 additions & 3 deletions src/lib/shop/cost.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { ItemStack, Player } from '@minecraft/server'
import { MinecraftItemTypes } from '@minecraft/vanilla-data'
import 'lib/extensions/player'

import 'lib/database/player'
import { describe, expect, expectTypeOf, it } from 'vitest'
import { Cost, ItemCost, MoneyCost, MultiCost } from './cost'

Expand Down
3 changes: 0 additions & 3 deletions src/lib/text.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'lib/database/player'
import 'lib/load/enviroment'

import 'lib/command/index'

import { Player } from '@minecraft/server'
Expand Down
11 changes: 11 additions & 0 deletions src/test/__mocks__/minecraft_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ export class System {
}
return 0
}

beforeEvents = new SystemBeforeEvents()
}

export enum WatchdogTerminateReason {
Hang = 'Hang',
StackOverflow = 'StackOverflow',
}

export class SystemBeforeEvents {
readonly watchdogTerminate = new EventSignal<{ cancel: boolean; terminateReason: WatchdogTerminateReason }>()
}

export const system = new System()
Expand Down
2 changes: 2 additions & 0 deletions src/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import 'lib/load/enviroment'
import 'lib/database/player'
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({
include: ['src/lib', 'src/modules'],
exclude: ['src/lib/assets', 'src/lib/bds', 'src/test', '**/*.test.ts', '**/*.spec.ts'],
},
setupFiles: ['src/test/setup.ts'],
alias: {
'@minecraft/server': 'test/__mocks__/minecraft_server.ts',
'@minecraft/server-net': 'test/__mocks__/minecraft_server-net.ts',
Expand Down

0 comments on commit 357699f

Please sign in to comment.