cm-chessboard 8.7.1 → 8.7.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.7.1",
3
+ "version": "8.7.3",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -71,7 +71,7 @@ export class Position {
71
71
  return parts.join("/")
72
72
  }
73
73
 
74
- getPieces(pieceType = undefined, pieceColor = undefined, sortBy = ['k', 'q', 'r', 'b', 'n', 'p']) {
74
+ getPieces(pieceColor = undefined, pieceType = undefined, sortBy = ['k', 'q', 'r', 'b', 'n', 'p']) {
75
75
  const pieces = []
76
76
  const sort = (a, b) => {
77
77
  return sortBy.indexOf(a.name) - sortBy.indexOf(b.name)
@@ -10,12 +10,31 @@ import {FEN} from "../src/model/Position.js"
10
10
 
11
11
  describe("TestChessboard", () => {
12
12
 
13
+ // https://github.com/shaack/cm-chessboard/issues/47
14
+ it("should create and immediately destroy a board without failure", () => {
15
+ const chessboard = new Chessboard(document.getElementById("TestBoard"), {
16
+ assetsUrl: "../assets/",
17
+ position: FEN.start
18
+ })
19
+ chessboard.destroy()
20
+ })
21
+
22
+ it("should create and destroy a board", () => {
23
+ const chessboard = new Chessboard(document.getElementById("TestBoard"), {
24
+ assetsUrl: "../assets/",
25
+ position: FEN.start
26
+ })
27
+ assert.equal(chessboard.view.container.childNodes.length, 1)
28
+ chessboard.destroy()
29
+ assert.equal(chessboard.state, undefined)
30
+ })
31
+
13
32
  it("should create and destroy a chessboard", () => {
14
33
  const chessboard = new Chessboard(document.getElementById("TestPosition"), {
15
34
  assetsUrl: "../assets/",
16
35
  position: FEN.start
17
36
  })
18
- assert.equal(chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
37
+ assert.equal("" + chessboard.getPosition(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
19
38
  chessboard.destroy()
20
39
  })
21
40
 
@@ -23,7 +42,7 @@ describe("TestChessboard", () => {
23
42
  const chessboard = new Chessboard(document.getElementById("TestPosition"),
24
43
  {assetsUrl: "../assets/"})
25
44
  chessboard.setPosition("rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR w Gkq - 4 11", false).then(() => {
26
- assert.equal(chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
45
+ assert.equal("" + chessboard.getPosition(), "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR")
27
46
  chessboard.destroy()
28
47
  })
29
48
  })
@@ -5,7 +5,8 @@
5
5
  */
6
6
 
7
7
  import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
8
- import {Position} from "../src/model/Position.js"
8
+ import {FEN, Position} from "../src/model/Position.js"
9
+ import {COLOR, PIECE_TYPE} from "../src/Chessboard.js"
9
10
 
10
11
  describe("TestPosition", () => {
11
12
  it("should convert square to index", () => {
@@ -22,4 +23,21 @@ describe("TestPosition", () => {
22
23
  assert.equal(Position.indexToSquare(38), "g5")
23
24
  assert.equal(Position.indexToSquare(63), "h8")
24
25
  })
26
+ it("should return the correct FEN string", () => {
27
+ const position = new Position(FEN.start)
28
+ assert.equal(position.getFen(), "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR")
29
+ })
30
+ it("should find the correct pieces", () => {
31
+ const position = new Position("8/5P2/8/1P3r2/8/8/1P3P1P/8")
32
+ const blackPiece = position.getPieces(COLOR.black)
33
+ assert.equal(blackPiece.length, 1)
34
+ assert.equal(blackPiece[0].type, PIECE_TYPE.rook)
35
+ assert.equal(blackPiece[0].square, "f5")
36
+ const whitePieces = position.getPieces(COLOR.white)
37
+ assert.equal(whitePieces.length, 5)
38
+ const rooks = position.getPieces(undefined, PIECE_TYPE.rook)
39
+ assert.equal(rooks.length, 1)
40
+ assert.equal(rooks[0].square, "f5")
41
+ })
25
42
  })
43
+
package/test/index.html CHANGED
@@ -23,7 +23,6 @@
23
23
  <script type="module">
24
24
  import {teevi} from "../node_modules/teevi/src/teevi.js"
25
25
  import "./TestChessboard.js"
26
- import "./TestBoard.js"
27
26
  import "./TestPiecesAnimation.js"
28
27
  import "./TestMarkers.js"
29
28
  import "./TestPosition.js"
package/test/TestBoard.js DELETED
@@ -1,32 +0,0 @@
1
- /**
2
- * Author and copyright: Stefan Haack (https://shaack.com)
3
- * Repository: https://github.com/shaack/cm-chessboard
4
- * License: MIT, see file 'LICENSE'
5
- */
6
-
7
- import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
8
- import {Chessboard} from "../src/Chessboard.js"
9
- import {FEN} from "../src/model/Position.js"
10
-
11
- describe("TestBoard", () => {
12
-
13
- // https://github.com/shaack/cm-chessboard/issues/47
14
- it("should create and immediately destroy a board without failure", () => {
15
- const chessboard = new Chessboard(document.getElementById("TestBoard"), {
16
- assetsUrl: "../assets/",
17
- position: FEN.start
18
- })
19
- chessboard.destroy()
20
- })
21
-
22
- it("should create and destroy a board", () => {
23
- const chessboard = new Chessboard(document.getElementById("TestBoard"), {
24
- assetsUrl: "../assets/",
25
- position: FEN.start
26
- })
27
- assert.equal(chessboard.view.container.childNodes.length, 1)
28
- chessboard.destroy()
29
- assert.equal(chessboard.state, undefined)
30
- })
31
-
32
- })