board-game-engine-react 0.0.15 → 0.0.17
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/.nycrc.json +8 -0
- package/babel.config.js +6 -1
- package/dist/board-game-engine-react.js +17 -16
- package/dist/board-game-engine-react.min.js +1 -1
- package/e2e/coverage.js +28 -0
- package/e2e/harness.spec.js +73 -0
- package/examples/checkers.json +793 -0
- package/examples/connect-four.json +126 -0
- package/examples/eights.json +653 -0
- package/examples/reversi.json +215 -0
- package/examples/tic-tac-toe.json +53 -0
- package/package.json +16 -4
- package/playwright.config.cjs +23 -0
- package/src/components/entity/entity.js +2 -1
- package/test-app/index.html +25 -0
- package/test-app/main.jsx +101 -0
- package/test-app/public/games/checkers.json +793 -0
- package/test-app/public/games/connect-four.json +126 -0
- package/test-app/public/games/eights.json +653 -0
- package/test-app/public/games/reversi.json +215 -0
- package/test-app/public/games/tic-tac-toe.json +53 -0
- package/vite.harness.config.js +16 -0
package/e2e/coverage.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Playwright test with optional coverage collection for Firefox e2e.
|
|
3
|
+
* When COVERAGE=1, after each test we collect window.__coverage__ from the page
|
|
4
|
+
* (from the instrumented bundle) and write it to .nyc_output/run/ for later merge.
|
|
5
|
+
*/
|
|
6
|
+
import { test as base } from '@playwright/test'
|
|
7
|
+
import { mkdirSync, writeFileSync } from 'fs'
|
|
8
|
+
import { join } from 'path'
|
|
9
|
+
|
|
10
|
+
export const test = base.extend({
|
|
11
|
+
page: async ({ page }, use, testInfo) => {
|
|
12
|
+
await use(page)
|
|
13
|
+
if (!process.env.COVERAGE || !page) return
|
|
14
|
+
try {
|
|
15
|
+
const coverage = await page.evaluate(() => window.__coverage__)
|
|
16
|
+
if (coverage && typeof coverage === 'object' && Object.keys(coverage).length > 0) {
|
|
17
|
+
const dir = join(process.cwd(), '.nyc_output', 'run')
|
|
18
|
+
mkdirSync(dir, { recursive: true })
|
|
19
|
+
const file = join(dir, `cov-${testInfo.workerIndex}-${testInfo.testId}.json`)
|
|
20
|
+
writeFileSync(file, JSON.stringify(coverage), 'utf8')
|
|
21
|
+
}
|
|
22
|
+
} catch (_) {
|
|
23
|
+
// page may be closed or __coverage__ not present
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export { expect } from '@playwright/test'
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** E2E tests for test-app harness (Board Game Engine React) – game selector and local mode. */
|
|
2
|
+
import { test, expect } from './coverage.js'
|
|
3
|
+
|
|
4
|
+
const HARNESS_URL = '/'
|
|
5
|
+
|
|
6
|
+
test.describe('Harness', () => {
|
|
7
|
+
test('harness loads with title and game selector', async ({ page }) => {
|
|
8
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
9
|
+
await expect(page.getByTestId('harness-title')).toHaveText(/Board Game Engine React/i)
|
|
10
|
+
await expect(page.getByTestId('game-select')).toHaveValue('tic-tac-toe')
|
|
11
|
+
await expect(page.getByTestId('start-btn')).toHaveText(/Start \/ Reset Game/i)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('can select different games from dropdown', async ({ page }) => {
|
|
15
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
16
|
+
await page.getByTestId('game-select').selectOption('connect-four')
|
|
17
|
+
await expect(page.getByTestId('game-select')).toHaveValue('connect-four')
|
|
18
|
+
await page.getByTestId('game-select').selectOption('reversi')
|
|
19
|
+
await expect(page.getByTestId('game-select')).toHaveValue('reversi')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test('can start tic-tac-toe in local mode', async ({ page }) => {
|
|
23
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
24
|
+
await expect(page.getByTestId('game-select')).toHaveValue('tic-tac-toe')
|
|
25
|
+
await page.getByTestId('start-btn').click()
|
|
26
|
+
await expect(page.getByTestId('start-btn')).not.toHaveText(/Loading/)
|
|
27
|
+
await expect(page.getByTestId('harness-game').locator('.game')).toBeVisible({ timeout: 5000 })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('can start connect-four and see game', async ({ page }) => {
|
|
31
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
32
|
+
await page.getByTestId('game-select').selectOption('connect-four')
|
|
33
|
+
await page.getByTestId('start-btn').click()
|
|
34
|
+
await expect(page.getByTestId('harness-game').locator('.game')).toBeVisible({ timeout: 5000 })
|
|
35
|
+
await expect(page.getByTestId('harness-game').locator('.shared-board')).toBeAttached()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test('tic-tac-toe shows game content after start', async ({ page }) => {
|
|
39
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
40
|
+
await page.getByTestId('start-btn').click()
|
|
41
|
+
const gameArea = page.getByTestId('harness-game').locator('.game')
|
|
42
|
+
await expect(gameArea).toBeVisible({ timeout: 5000 })
|
|
43
|
+
await expect(gameArea.locator('.grid, .shared-board').first()).toBeAttached({ timeout: 3000 })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('tic-tac-toe: click one space and an entity appears in that space', async ({ page }) => {
|
|
47
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
48
|
+
await page.getByTestId('start-btn').click()
|
|
49
|
+
const gameArea = page.getByTestId('harness-game').locator('.game')
|
|
50
|
+
await expect(gameArea).toBeVisible({ timeout: 5000 })
|
|
51
|
+
const cells = gameArea.locator('.grid__cell')
|
|
52
|
+
await expect(cells).toHaveCount(9, { timeout: 3000 })
|
|
53
|
+
const firstCell = cells.nth(0)
|
|
54
|
+
await firstCell.locator('.space').first().click()
|
|
55
|
+
await expect(firstCell.locator('.entity')).toBeVisible({ timeout: 2000 })
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('plays a full game of tic-tac-toe and game ends', async ({ page }) => {
|
|
59
|
+
await page.goto(HARNESS_URL, { waitUntil: 'load' })
|
|
60
|
+
await page.getByTestId('start-btn').click()
|
|
61
|
+
const gameArea = page.getByTestId('harness-game').locator('.game')
|
|
62
|
+
await expect(gameArea).toBeVisible({ timeout: 5000 })
|
|
63
|
+
await expect(gameArea.locator('.grid__cell')).toHaveCount(9, { timeout: 3000 })
|
|
64
|
+
const moveOrder = [0, 3, 1, 4, 2]
|
|
65
|
+
for (const index of moveOrder) {
|
|
66
|
+
const cell = gameArea.locator('.grid__cell').nth(index)
|
|
67
|
+
await cell.locator('.space').first().click()
|
|
68
|
+
await page.waitForTimeout(200)
|
|
69
|
+
}
|
|
70
|
+
await expect(gameArea.locator('.game-status')).toBeVisible({ timeout: 5000 })
|
|
71
|
+
await expect(gameArea.locator('.game-status')).toHaveText(/Wins!|Draw!/)
|
|
72
|
+
})
|
|
73
|
+
})
|