diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/test/unit/core/toLocal.test.js b/test/unit/core/toLocal.test.js deleted file mode 100644 index 93d6046..0000000 --- a/test/unit/core/toLocal.test.js +++ /dev/null @@ -1,59 +0,0 @@ -describe('toLocal', function () { - - - it('should return correct local cordinates of a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(40); - expect(localPoint.y).to.equal(40); - - }); - - it('should map the correct local cordinates of a displayObject to another', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - var container2 = new PIXI.Container(); - - parent.addChild(container); - parent.addChild(container2); - - container2.position.x = 100; - container2.position.y = 100; - - var point = new PIXI.Point(100, 100); - - // container.position.x = 20; - // container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point, container2); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/test/unit/core/toLocal.test.js b/test/unit/core/toLocal.test.js deleted file mode 100644 index 93d6046..0000000 --- a/test/unit/core/toLocal.test.js +++ /dev/null @@ -1,59 +0,0 @@ -describe('toLocal', function () { - - - it('should return correct local cordinates of a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(40); - expect(localPoint.y).to.equal(40); - - }); - - it('should map the correct local cordinates of a displayObject to another', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - var container2 = new PIXI.Container(); - - parent.addChild(container); - parent.addChild(container2); - - container2.position.x = 100; - container2.position.y = 100; - - var point = new PIXI.Point(100, 100); - - // container.position.x = 20; - // container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point, container2); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - }); -}); diff --git a/test/unit/core/utils/util.test.js b/test/unit/core/utils/util.test.js deleted file mode 100644 index 145111b..0000000 --- a/test/unit/core/utils/util.test.js +++ /dev/null @@ -1,114 +0,0 @@ -describe('PIXI.utils', function () { - describe('.uid', function () { - it('should exist', function () { - expect(PIXI.utils.uid) - .to.be.a('function'); - }); - - it('should return a number', function () { - expect(PIXI.utils.uid()) - .to.be.a('number'); - }); - }); - - describe('.hex2rgb', function () { - it('should exist', function () { - expect(PIXI.utils.hex2rgb) - .to.be.a('function'); - }); - - it('should properly convert number to rgb array'); - }); - - describe('.hex2string', function () { - it('should exist', function () { - expect(PIXI.utils.hex2string) - .to.be.a('function'); - }); - - it('should properly convert number to hex color string'); - }); - - describe('.rgb2hex', function () { - it('should exist', function () { - expect(PIXI.utils.rgb2hex) - .to.be.a('function'); - }); - - it('should properly convert rgb array to hex color string'); - }); - - describe('.getResolutionOfUrl', function () { - it('should exist', function () { - expect(PIXI.utils.getResolutionOfUrl) - .to.be.a('function'); - }); - - it('should return the correct resolution based on a URL'); - }); - - describe('.sayHello', function () { - it('should exist', function () { - expect(PIXI.utils.sayHello) - .to.be.a('function'); - }); - }); - - describe('.isWebGLSupported', function () { - it('should exist', function () { - expect(PIXI.utils.isWebGLSupported) - .to.be.a('function'); - }); - }); - - describe('.sign', function () { - it('should return 0 for 0', function () { - expect(PIXI.utils.sign(0)) - .to.be.equal(0); - }); - - it('should return -1 for negative numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(-Math.random())) - .to.be.equal(-1); - } - }); - - it('should return 1 for positive numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(Math.random() + 0.000001)) - .to.be.equal(1); - } - }); - }); - - describe('.removeItems', function () { - var arr; - - beforeEach(function () { - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - }); - - it('should return if the start index is greater than or equal to the length of the array', function () { - PIXI.utils.removeItems(arr, arr.length+1, 5); - expect(arr.length).to.be.equal(10); - }); - - it('should return if the remove count is 0', function () { - PIXI.utils.removeItems(arr, 2, 0); - expect(arr.length).to.be.equal(10); - }); - - it('should remove the number of elements specified from the array, starting from the start index', function () { - var res = [ 1, 2, 3, 8, 9, 10 ]; - PIXI.utils.removeItems(arr, 3, 4); - expect(arr).to.be.deep.equal(res); - }); - - it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { - var res = [ 1, 2, 3, 4, 5, 6, 7 ]; - PIXI.utils.removeItems(arr, 7, 10); - expect(arr).to.be.deep.equal(res); - }); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/test/unit/core/toLocal.test.js b/test/unit/core/toLocal.test.js deleted file mode 100644 index 93d6046..0000000 --- a/test/unit/core/toLocal.test.js +++ /dev/null @@ -1,59 +0,0 @@ -describe('toLocal', function () { - - - it('should return correct local cordinates of a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(40); - expect(localPoint.y).to.equal(40); - - }); - - it('should map the correct local cordinates of a displayObject to another', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - var container2 = new PIXI.Container(); - - parent.addChild(container); - parent.addChild(container2); - - container2.position.x = 100; - container2.position.y = 100; - - var point = new PIXI.Point(100, 100); - - // container.position.x = 20; - // container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point, container2); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - }); -}); diff --git a/test/unit/core/utils/util.test.js b/test/unit/core/utils/util.test.js deleted file mode 100644 index 145111b..0000000 --- a/test/unit/core/utils/util.test.js +++ /dev/null @@ -1,114 +0,0 @@ -describe('PIXI.utils', function () { - describe('.uid', function () { - it('should exist', function () { - expect(PIXI.utils.uid) - .to.be.a('function'); - }); - - it('should return a number', function () { - expect(PIXI.utils.uid()) - .to.be.a('number'); - }); - }); - - describe('.hex2rgb', function () { - it('should exist', function () { - expect(PIXI.utils.hex2rgb) - .to.be.a('function'); - }); - - it('should properly convert number to rgb array'); - }); - - describe('.hex2string', function () { - it('should exist', function () { - expect(PIXI.utils.hex2string) - .to.be.a('function'); - }); - - it('should properly convert number to hex color string'); - }); - - describe('.rgb2hex', function () { - it('should exist', function () { - expect(PIXI.utils.rgb2hex) - .to.be.a('function'); - }); - - it('should properly convert rgb array to hex color string'); - }); - - describe('.getResolutionOfUrl', function () { - it('should exist', function () { - expect(PIXI.utils.getResolutionOfUrl) - .to.be.a('function'); - }); - - it('should return the correct resolution based on a URL'); - }); - - describe('.sayHello', function () { - it('should exist', function () { - expect(PIXI.utils.sayHello) - .to.be.a('function'); - }); - }); - - describe('.isWebGLSupported', function () { - it('should exist', function () { - expect(PIXI.utils.isWebGLSupported) - .to.be.a('function'); - }); - }); - - describe('.sign', function () { - it('should return 0 for 0', function () { - expect(PIXI.utils.sign(0)) - .to.be.equal(0); - }); - - it('should return -1 for negative numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(-Math.random())) - .to.be.equal(-1); - } - }); - - it('should return 1 for positive numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(Math.random() + 0.000001)) - .to.be.equal(1); - } - }); - }); - - describe('.removeItems', function () { - var arr; - - beforeEach(function () { - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - }); - - it('should return if the start index is greater than or equal to the length of the array', function () { - PIXI.utils.removeItems(arr, arr.length+1, 5); - expect(arr.length).to.be.equal(10); - }); - - it('should return if the remove count is 0', function () { - PIXI.utils.removeItems(arr, 2, 0); - expect(arr.length).to.be.equal(10); - }); - - it('should remove the number of elements specified from the array, starting from the start index', function () { - var res = [ 1, 2, 3, 8, 9, 10 ]; - PIXI.utils.removeItems(arr, 3, 4); - expect(arr).to.be.deep.equal(res); - }); - - it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { - var res = [ 1, 2, 3, 4, 5, 6, 7 ]; - PIXI.utils.removeItems(arr, 7, 10); - expect(arr).to.be.deep.equal(res); - }); - }); -}); diff --git a/test/unit/index.test.js b/test/unit/index.test.js deleted file mode 100644 index 37e1d2a..0000000 --- a/test/unit/index.test.js +++ /dev/null @@ -1,6 +0,0 @@ -describe('PIXI', function () { - it('exists', function () { - expect(PIXI) - .to.be.an('object'); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/test/unit/core/toLocal.test.js b/test/unit/core/toLocal.test.js deleted file mode 100644 index 93d6046..0000000 --- a/test/unit/core/toLocal.test.js +++ /dev/null @@ -1,59 +0,0 @@ -describe('toLocal', function () { - - - it('should return correct local cordinates of a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(40); - expect(localPoint.y).to.equal(40); - - }); - - it('should map the correct local cordinates of a displayObject to another', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - var container2 = new PIXI.Container(); - - parent.addChild(container); - parent.addChild(container2); - - container2.position.x = 100; - container2.position.y = 100; - - var point = new PIXI.Point(100, 100); - - // container.position.x = 20; - // container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point, container2); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - }); -}); diff --git a/test/unit/core/utils/util.test.js b/test/unit/core/utils/util.test.js deleted file mode 100644 index 145111b..0000000 --- a/test/unit/core/utils/util.test.js +++ /dev/null @@ -1,114 +0,0 @@ -describe('PIXI.utils', function () { - describe('.uid', function () { - it('should exist', function () { - expect(PIXI.utils.uid) - .to.be.a('function'); - }); - - it('should return a number', function () { - expect(PIXI.utils.uid()) - .to.be.a('number'); - }); - }); - - describe('.hex2rgb', function () { - it('should exist', function () { - expect(PIXI.utils.hex2rgb) - .to.be.a('function'); - }); - - it('should properly convert number to rgb array'); - }); - - describe('.hex2string', function () { - it('should exist', function () { - expect(PIXI.utils.hex2string) - .to.be.a('function'); - }); - - it('should properly convert number to hex color string'); - }); - - describe('.rgb2hex', function () { - it('should exist', function () { - expect(PIXI.utils.rgb2hex) - .to.be.a('function'); - }); - - it('should properly convert rgb array to hex color string'); - }); - - describe('.getResolutionOfUrl', function () { - it('should exist', function () { - expect(PIXI.utils.getResolutionOfUrl) - .to.be.a('function'); - }); - - it('should return the correct resolution based on a URL'); - }); - - describe('.sayHello', function () { - it('should exist', function () { - expect(PIXI.utils.sayHello) - .to.be.a('function'); - }); - }); - - describe('.isWebGLSupported', function () { - it('should exist', function () { - expect(PIXI.utils.isWebGLSupported) - .to.be.a('function'); - }); - }); - - describe('.sign', function () { - it('should return 0 for 0', function () { - expect(PIXI.utils.sign(0)) - .to.be.equal(0); - }); - - it('should return -1 for negative numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(-Math.random())) - .to.be.equal(-1); - } - }); - - it('should return 1 for positive numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(Math.random() + 0.000001)) - .to.be.equal(1); - } - }); - }); - - describe('.removeItems', function () { - var arr; - - beforeEach(function () { - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - }); - - it('should return if the start index is greater than or equal to the length of the array', function () { - PIXI.utils.removeItems(arr, arr.length+1, 5); - expect(arr.length).to.be.equal(10); - }); - - it('should return if the remove count is 0', function () { - PIXI.utils.removeItems(arr, 2, 0); - expect(arr.length).to.be.equal(10); - }); - - it('should remove the number of elements specified from the array, starting from the start index', function () { - var res = [ 1, 2, 3, 8, 9, 10 ]; - PIXI.utils.removeItems(arr, 3, 4); - expect(arr).to.be.deep.equal(res); - }); - - it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { - var res = [ 1, 2, 3, 4, 5, 6, 7 ]; - PIXI.utils.removeItems(arr, 7, 10); - expect(arr).to.be.deep.equal(res); - }); - }); -}); diff --git a/test/unit/index.test.js b/test/unit/index.test.js deleted file mode 100644 index 37e1d2a..0000000 --- a/test/unit/index.test.js +++ /dev/null @@ -1,6 +0,0 @@ -describe('PIXI', function () { - it('exists', function () { - expect(PIXI) - .to.be.an('object'); - }); -}); diff --git a/test/unit/interaction/InteractionData.test.js b/test/unit/interaction/InteractionData.test.js deleted file mode 100644 index 690ca16..0000000 --- a/test/unit/interaction/InteractionData.test.js +++ /dev/null @@ -1,22 +0,0 @@ -describe('PIXI.interaction.InteractionData', function() { - describe('getLocalPosition', function() { - it('should populate second parameter with result', function() { - var data = new PIXI.interaction.InteractionData(), - stage = new PIXI.DisplayObject(), - displayObject = new PIXI.DisplayObject(), - point = new PIXI.Point(); - - data.global.set(10, 10); - - displayObject.position.set(5, 3); - - displayObject.parent = stage - displayObject.displayObjectUpdateTransform(); - - data.getLocalPosition(displayObject, point); - - expect(point.x).to.equal(5); - expect(point.y).to.equal(7); - }); - }); -}); diff --git a/.travis.yml b/.travis.yml index 1ba377e..385e8b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ -sudo: false language: node_js node_js: - "4" -branches: - only: - - master - - dev +env: + - CXX=g++-4.8 + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-4.8 install: + - npm install xvfb-maybe - npm install cache: - directories: - - node_modules + directories: + - node_modules before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start + - export DISPLAY=':99.0' + - Xvfb :99 -screen 0 1024x768x24 -extension RANDR & script: - - npm test + - xvfb-maybe npm run build \ No newline at end of file diff --git a/package.json b/package.json index 74f545e..5dc29c8 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "start": "parallelshell \"npm run watch:debug\" \"npm run watch:release\"", "watch:debug": "watchify src/index.js -s PIXI -o bin/pixi.js -dv", "watch:release": "watchify src/index.js -s PIXI -o bin/pixi.min.js -dv", - "test": "npm run build && testem ci", - "lint": "jshint --reporter=scripts/reporter.js scripts src", + "test": "floss --path test/index.js", + "test:debug": "npm test -- --debug", + "lint": "jshint --reporter=scripts/reporter.js scripts src test", "prebuild": "npm run lint && npm run clean", "build": "pixify --name pixi", + "postbuild": "npm test", "docs": "jsdoc -c scripts/jsdoc.conf.json -R README.md" }, "files": [ @@ -50,8 +52,9 @@ }, "devDependencies": { "browserify-versionify": "^1.0.6", - "chai": "^3.5.0", "del": "^2.2.0", + "electron-prebuilt": "^1.3.2", + "floss": "^0.7.1", "jaguarjs-jsdoc": "^1.0.0", "jsdoc": "^3.4.0", "jshint": "^2.9.2", @@ -59,11 +62,9 @@ "jshint-stylish-summary": "^0.1.2", "minimist": "^1.2.0", "mkdirp": "^0.5.1", - "mocha": "^2.5.3", "parallelshell": "^2.0.0", "pixify": "^1.2.0", "rimraf": "^2.5.3", - "testem": "^1.8.1", "watchify": "^3.7.0" }, "browserify": { diff --git a/test/.jshintrc b/test/.jshintrc old mode 100644 new mode 100755 index e026e83..507b55a --- a/test/.jshintrc +++ b/test/.jshintrc @@ -1,4 +1,13 @@ { - "mocha": true, - "chai": true -} + "node": true, + "mocha": true, + "browser": true, + "esversion": 6, + "expr": true, + "predef": [ + "PIXI", + "chai", + "expect", + "assert" + ] +} \ No newline at end of file diff --git a/test/core/Bounds.js b/test/core/Bounds.js new file mode 100644 index 0000000..328bca9 --- /dev/null +++ b/test/core/Bounds.js @@ -0,0 +1,363 @@ +describe('getBounds', function () { + + it('should register correct width and height with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + bounds = sprite.getBounds(true); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + var bounds; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(graphics); + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + graphics.position.x = 20; + graphics.position.y = 20; + + graphics.scale.x = 2; + graphics.scale.y = 2; + + bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(40); + expect(bounds.height).to.equal(40); + + }); + + it('should register correct width and height with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + }); + + it('should register correct width and height with a Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(80); + expect(bounds.height).to.equal(90); + + container.rotation = 0.1; + + bounds = container.getBounds(); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + bounds = container.getBounds(true); + + expect(bounds.x | 0).to.equal(26); + expect(bounds.y | 0).to.equal(22); + expect(bounds.width | 0).to.equal(73); + expect(bounds.height | 0).to.equal(97); + + + }); + + it('should register correct width and height with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + bounds = graphics.getBounds(true); + + expect(bounds.x).to.equal(100); + expect(bounds.y).to.equal(100); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); + + it('should register correct width and height with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + plane.scale.x = 2; + plane.scale.y = 2; + + bounds = plane.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct width and height with an a DisplayObject is visible false', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + container.addChild(sprite); + container.addChild(graphics); + + parent.addChild(container); + + sprite.position.x = 30; + sprite.position.y = 20; + graphics.position.x = 100; + graphics.position.y = 100; + + graphics.visible = false; + + var bounds; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(30); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + container.visible = false; + + bounds = container.getBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct width and height with an a DisplayObject parent has moved', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + container.addChild(graphics); + + parent.addChild(container); + + // graphics.position.x = 100; + // graphics.position.y = 100; + container.position.x -= 100; + container.position.y -= 100; + + var bounds = graphics.getBounds(); + + expect(bounds.x).to.equal(-110); + expect(bounds.y).to.equal(-110); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + + }); + + it('should register correct width and height with an a Text Object', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var text = new PIXI.Text('i am some text'); + + container.addChild(text); + + parent.addChild(container); + + var bounds; + + bounds = text.getBounds(); + var bx = bounds.width; + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.be.greaterThan(0); + expect(bounds.height).to.greaterThan(0); + + text.text = 'hello!'; + + bounds = text.getBounds(); + + // this variable seems to be different on different devices. a font thing? + expect(bounds.width).to.not.equal(bx); + + }); + + it('should return a different rectangle if getting local bounds after global bounds ', function() { + + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + var sprite = new PIXI.Sprite(texture); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + parent.addChild(sprite); + + var bounds = sprite.getBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + var localBounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(20); + expect(bounds.y).to.equal(20); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + }); +}); \ No newline at end of file diff --git a/test/core/Container.js b/test/core/Container.js new file mode 100755 index 0000000..34b5947 --- /dev/null +++ b/test/core/Container.js @@ -0,0 +1,42 @@ +describe('PIXI.Container', function () { + describe('parent', function () { + it('should be present when adding children to Container', function() { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(); + + expect(container.children.length).to.be.equals(0); + container.addChild(child); + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(container); + }); + }); + + describe('events', function () { + it('should trigger "added" and "removed" events on it\'s children', function () { + var container = new PIXI.Container(), + child = new PIXI.DisplayObject(), + triggeredAdded = false, + triggeredRemoved = false; + + child.on('added', function(to) { + triggeredAdded = true; + expect(container.children.length).to.be.equals(1); + expect(child.parent).to.be.equals(to); + }); + child.on('removed', function(from) { + triggeredRemoved = true; + expect(container.children.length).to.be.equals(0); + expect(child.parent).to.be.null; + expect(container).to.be.equals(from); + }); + + container.addChild(child); + expect(triggeredAdded).to.be.true; + expect(triggeredRemoved).to.be.false; + + container.removeChild(child); + expect(triggeredRemoved).to.be.true; + }); + + }); +}); diff --git a/test/core/DisplayObject.js b/test/core/DisplayObject.js new file mode 100755 index 0000000..e2ee32d --- /dev/null +++ b/test/core/DisplayObject.js @@ -0,0 +1,11 @@ +describe('PIXI.DisplayObject', function () { + it('should be able to add itself to a Container', function() { + var child = new PIXI.DisplayObject(), + container = new PIXI.Container(); + + expect(container.children.length).to.equal(0); + child.setParent(container); + expect(container.children.length).to.equal(1); + expect(child.parent).to.equal(container); + }); +}); diff --git a/test/core/Sprite.js b/test/core/Sprite.js new file mode 100755 index 0000000..f94952a --- /dev/null +++ b/test/core/Sprite.js @@ -0,0 +1,55 @@ +describe('PIXI.Sprite', function () { + describe('width', function () { + it('should not be negative for nagative scale.x', function () { + var sprite = new PIXI.Sprite(); + + sprite.width = 100; + expect(sprite.width).to.be.at.least(0); + sprite.scale.x = -1; + expect(sprite.width).to.be.at.least(0); + }); + + it('should not change sign of scale.x', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.width = 100; + sprite.scale.x = 1; + sprite.width = 50; + + expect(sprite.scale.x).to.be.above(0); + + sprite.scale.x = -1; + sprite.width = 75; + + expect(sprite.scale.x).to.be.below(0); + }); + }); + + describe('height', function () { + it('should not be negative for nagative scale.y', function () { + var sprite = new PIXI.Sprite(); + + sprite.height = 100; + expect(sprite.height).to.be.at.least(0); + sprite.scale.y = -1; + expect(sprite.height).to.be.at.least(0); + }); + + it('should not change sign of scale.y', function () { + var texture = new PIXI.Texture(new PIXI.BaseTexture()); + var sprite = new PIXI.Sprite(); + + texture.height = 100; + sprite.scale.y = 1; + sprite.height = 50; + + expect(sprite.scale.y).to.be.above(0); + + sprite.scale.y = -1; + sprite.height = 75; + + expect(sprite.scale.y).to.be.below(0); + }); + }); +}); diff --git a/test/core/Text.js b/test/core/Text.js new file mode 100644 index 0000000..4564c06 --- /dev/null +++ b/test/core/Text.js @@ -0,0 +1,53 @@ +describe('PIXI.Text', function () { + describe('destroy', function () { + it('should call through to Sprite.destroy', function () { + var text = new PIXI.Text("foo"); + + expect(text.anchor).to.not.equal(null); + text.destroy(); + expect(text.anchor).to.equal(null); + }); + + it('should set context to null', function () { + var text = new PIXI.Text("foo"); + + expect(text.style).to.not.equal(null); + text.destroy(); + expect(text.style).to.equal(null); + }); + + it('should destroy children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy({children: true}); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should accept boolean correctly', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(); + + text.addChild(child); + text.destroy(true); + expect(text.transform).to.equal(null); + expect(child.transform).to.equal(null); + }); + + it('should pass opts on to children if children flag is set', function () { + var text = new PIXI.Text("foo"), + child = new PIXI.DisplayObject(), + childDestroyOpts; + + child.destroy = function(opts) { + childDestroyOpts = opts; + }; + + text.addChild(child); + text.destroy({children: true, texture: true}); + expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); + }); + }); +}); diff --git a/test/core/getLocalBounds.js b/test/core/getLocalBounds.js new file mode 100644 index 0000000..2284349 --- /dev/null +++ b/test/core/getLocalBounds.js @@ -0,0 +1,117 @@ +describe('getLocalBounds', function () { + + + it('should register correct local-bounds with a LOADED Sprite', function() { + var parent = new PIXI.Container(); + var texture = PIXI.RenderTexture.create(10, 10); + + var sprite = new PIXI.Sprite(texture); + + parent.addChild(sprite); + + var bounds; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + sprite.position.x = 20; + sprite.position.y = 20; + + sprite.scale.x = 2; + sprite.scale.y = 2; + + bounds = sprite.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + }); + + it('should register correct local-bounds with Graphics', function() { + var parent = new PIXI.Container(); + + var graphics = new PIXI.Graphics(); + + graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); + + graphics.scale.set(2); + + parent.addChild(graphics); + + var bounds = graphics.getLocalBounds(); + + expect(bounds.x).to.equal(-10); + expect(bounds.y).to.equal(-10); + expect(bounds.width).to.equal(20); + expect(bounds.height).to.equal(20); + + }); + + it('should register correct local-bounds with an empty Container', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + parent.addChild(container); + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(0); + expect(bounds.height).to.equal(0); + + + }); + + it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { + var parent = new PIXI.Container(); + + var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); + + var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); + + + parent.addChild(container); + container.addChild(graphics); + + container.position.x = 100; + container.position.y = 100; + + var bounds = container.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + + + + }); + + it('should register correct local-bounds with a Mesh', function() { + var parent = new PIXI.Container(); + + var texture = PIXI.RenderTexture.create(10, 10); + + var plane = new PIXI.mesh.Plane(texture); + + parent.addChild(plane); + + plane.position.x = 20; + plane.position.y = 20; + + var bounds = plane.getLocalBounds(); + + expect(bounds.x).to.equal(0); + expect(bounds.y).to.equal(0); + expect(bounds.width).to.equal(10); + expect(bounds.height).to.equal(10); + }); +}); \ No newline at end of file diff --git a/test/core/index.js b/test/core/index.js new file mode 100755 index 0000000..791fa7f --- /dev/null +++ b/test/core/index.js @@ -0,0 +1,9 @@ +require('./Bounds'); +require('./Container'); +require('./DisplayObject'); +require('./getLocalBounds'); +require('./Sprite'); +require('./Text'); +require('./toGlobal'); +require('./toLocal'); +require('./util'); \ No newline at end of file diff --git a/test/core/toGlobal.js b/test/core/toGlobal.js new file mode 100644 index 0000000..7fd34c1 --- /dev/null +++ b/test/core/toGlobal.js @@ -0,0 +1,34 @@ +describe('toGlobal', function () { + + + it('should return correct global cordinates of a point from within a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var globalPoint; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(100); + expect(globalPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + globalPoint = container.toGlobal(point); + + expect(globalPoint.x).to.equal(220); + expect(globalPoint.y).to.equal(220); + + }); + +}); diff --git a/test/core/toLocal.js b/test/core/toLocal.js new file mode 100644 index 0000000..33447d0 --- /dev/null +++ b/test/core/toLocal.js @@ -0,0 +1,57 @@ +describe('toLocal', function () { + + it('should return correct local cordinates of a displayObject', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + + parent.addChild(container); + + var point = new PIXI.Point(100, 100); + + var localPoint; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + container.position.x = 20; + container.position.y = 20; + + container.scale.x = 2; + container.scale.y = 2; + + localPoint = container.toLocal(point); + + expect(localPoint.x).to.equal(40); + expect(localPoint.y).to.equal(40); + + }); + + it('should map the correct local cordinates of a displayObject to another', function() { + + var parent = new PIXI.Container(); + + var container = new PIXI.Container(); + var container2 = new PIXI.Container(); + + parent.addChild(container); + parent.addChild(container2); + + container2.position.x = 100; + container2.position.y = 100; + + var point = new PIXI.Point(100, 100); + + container.scale.x = 2; + container.scale.y = 2; + + var localPoint = container.toLocal(point, container2); + + expect(localPoint.x).to.equal(100); + expect(localPoint.y).to.equal(100); + + }); +}); \ No newline at end of file diff --git a/test/core/util.js b/test/core/util.js new file mode 100755 index 0000000..ab695ae --- /dev/null +++ b/test/core/util.js @@ -0,0 +1,114 @@ +describe('PIXI.utils', function () { + describe('uid', function () { + it('should exist', function () { + expect(PIXI.utils.uid) + .to.be.a('function'); + }); + + it('should return a number', function () { + expect(PIXI.utils.uid()) + .to.be.a('number'); + }); + }); + + describe('hex2rgb', function () { + it('should exist', function () { + expect(PIXI.utils.hex2rgb) + .to.be.a('function'); + }); + + // it('should properly convert number to rgb array'); + }); + + describe('hex2string', function () { + it('should exist', function () { + expect(PIXI.utils.hex2string) + .to.be.a('function'); + }); + + // it('should properly convert number to hex color string'); + }); + + describe('rgb2hex', function () { + it('should exist', function () { + expect(PIXI.utils.rgb2hex) + .to.be.a('function'); + }); + + // it('should properly convert rgb array to hex color string'); + }); + + describe('getResolutionOfUrl', function () { + it('should exist', function () { + expect(PIXI.utils.getResolutionOfUrl) + .to.be.a('function'); + }); + + // it('should return the correct resolution based on a URL'); + }); + + describe('sayHello', function () { + it('should exist', function () { + expect(PIXI.utils.sayHello) + .to.be.a('function'); + }); + }); + + describe('isWebGLSupported', function () { + it('should exist', function () { + expect(PIXI.utils.isWebGLSupported) + .to.be.a('function'); + }); + }); + + describe('sign', function () { + it('should return 0 for 0', function () { + expect(PIXI.utils.sign(0)) + .to.be.equal(0); + }); + + it('should return -1 for negative numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(-Math.random())) + .to.be.equal(-1); + } + }); + + it('should return 1 for positive numbers', function () { + for (var i = 0;i<10;i+=1){ + expect(PIXI.utils.sign(Math.random() + 0.000001)) + .to.be.equal(1); + } + }); + }); + + describe('.removeItems', function () { + var arr; + + beforeEach(function () { + arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + }); + + it('should return if the start index is greater than or equal to the length of the array', function () { + PIXI.utils.removeItems(arr, arr.length+1, 5); + expect(arr.length).to.be.equal(10); + }); + + it('should return if the remove count is 0', function () { + PIXI.utils.removeItems(arr, 2, 0); + expect(arr.length).to.be.equal(10); + }); + + it('should remove the number of elements specified from the array, starting from the start index', function () { + var res = [ 1, 2, 3, 8, 9, 10 ]; + PIXI.utils.removeItems(arr, 3, 4); + expect(arr).to.be.deep.equal(res); + }); + + it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { + var res = [ 1, 2, 3, 4, 5, 6, 7 ]; + PIXI.utils.removeItems(arr, 7, 10); + expect(arr).to.be.deep.equal(res); + }); + }); +}); diff --git a/test/index.js b/test/index.js new file mode 100755 index 0000000..fb7dd8a --- /dev/null +++ b/test/index.js @@ -0,0 +1,9 @@ +require('../bin/pixi'); + +describe('PIXI', function () { + it('should exist as a global object', function () { + expect(PIXI).to.be.an('object'); + }); + require('./core'); + require('./interaction'); +}); \ No newline at end of file diff --git a/test/interaction/InteractionData.js b/test/interaction/InteractionData.js new file mode 100755 index 0000000..bd57181 --- /dev/null +++ b/test/interaction/InteractionData.js @@ -0,0 +1,18 @@ +describe('PIXI.interaction.InteractionData', function() { + describe('getLocalPosition', function() { + it('should populate second parameter with result', function() { + var data = new PIXI.interaction.InteractionData(), + stage = new PIXI.DisplayObject(), + displayObject = new PIXI.DisplayObject(), + point = new PIXI.Point(); + + data.global.set(10, 10); + displayObject.position.set(5, 3); + displayObject.parent = stage; + displayObject.displayObjectUpdateTransform(); + data.getLocalPosition(displayObject, point); + expect(point.x).to.equal(5); + expect(point.y).to.equal(7); + }); + }); +}); diff --git a/test/interaction/index.js b/test/interaction/index.js new file mode 100644 index 0000000..08965a5 --- /dev/null +++ b/test/interaction/index.js @@ -0,0 +1 @@ +require('./InteractionData'); \ No newline at end of file diff --git a/test/lib/pixi/core/Circle.js b/test/lib/pixi/core/Circle.js deleted file mode 100644 index e7cbd4d..0000000 --- a/test/lib/pixi/core/Circle.js +++ /dev/null @@ -1,22 +0,0 @@ -function pixi_core_Circle_confirmNewCircle(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Circle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - expect(obj).to.respondTo('getBounds'); - - expect(obj).to.have.property('x', 0); - expect(obj).to.have.property('y', 0); - expect(obj).to.have.property('radius', 0); -} - -function pixi_core_Circle_isBoundedByRectangle(obj, rect) { - var expect = chai.expect; - - expect(rect).to.have.property('x', obj.x - obj.radius); - expect(rect).to.have.property('y', obj.y - obj.radius); - - expect(rect).to.have.property('width', obj.radius * 2); - expect(rect).to.have.property('height', obj.radius * 2); -} diff --git a/test/lib/pixi/core/Matrix.js b/test/lib/pixi/core/Matrix.js deleted file mode 100644 index 77492c2..0000000 --- a/test/lib/pixi/core/Matrix.js +++ /dev/null @@ -1,13 +0,0 @@ -function pixi_core_Matrix_confirmNewMatrix(matrix) { - var expect = chai.expect; - - expect(matrix).to.be.an.instanceof(PIXI.Matrix); - expect(matrix).to.not.be.empty; - - expect(matrix.a).to.equal(1); - expect(matrix.b).to.equal(0); - expect(matrix.c).to.equal(0); - expect(matrix.d).to.equal(1); - expect(matrix.tx).to.equal(0); - expect(matrix.ty).to.equal(0); -} \ No newline at end of file diff --git a/test/lib/pixi/core/Point.js b/test/lib/pixi/core/Point.js deleted file mode 100644 index e5df07b..0000000 --- a/test/lib/pixi/core/Point.js +++ /dev/null @@ -1,10 +0,0 @@ - -function pixi_core_Point_confirm(obj, x, y) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Point); - expect(obj).to.respondTo('clone'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); -} diff --git a/test/lib/pixi/core/Rectangle.js b/test/lib/pixi/core/Rectangle.js deleted file mode 100644 index 23f0d12..0000000 --- a/test/lib/pixi/core/Rectangle.js +++ /dev/null @@ -1,13 +0,0 @@ - -function pixi_core_Rectangle_confirm(obj, x, y, width, height) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.Rectangle); - expect(obj).to.respondTo('clone'); - expect(obj).to.respondTo('contains'); - - expect(obj).to.have.property('x', x); - expect(obj).to.have.property('y', y); - expect(obj).to.have.property('width', width); - expect(obj).to.have.property('height', height); -} diff --git a/test/lib/pixi/display/DisplayObject.js b/test/lib/pixi/display/DisplayObject.js deleted file mode 100644 index c1b8883..0000000 --- a/test/lib/pixi/display/DisplayObject.js +++ /dev/null @@ -1,39 +0,0 @@ - -function pixi_display_DisplayObject_confirmNew(obj) { - var expect = chai.expect; - - expect(obj).to.be.an.instanceof(PIXI.DisplayObject); - //expect(obj).to.respondTo('setInteractive'); - //expect(obj).to.respondTo('addFilter'); - //expect(obj).to.respondTo('removeFilter'); - expect(obj).to.respondTo('updateTransform'); - expect(obj).to.respondTo('setParent'); - - expect(obj).to.contain.property('position'); - pixi_core_Point_confirm(obj.position, 0, 0); - expect(obj).to.contain.property('scale'); - pixi_core_Point_confirm(obj.scale, 1, 1); - expect(obj).to.contain.property('pivot'); - pixi_core_Point_confirm(obj.pivot, 0, 0); - - expect(obj).to.have.property('rotation', 0); - expect(obj).to.have.property('alpha', 1); - expect(obj).to.have.property('visible', true); - expect(obj).to.have.property('buttonMode', false); - expect(obj).to.have.property('parent', null); - expect(obj).to.have.property('worldAlpha', 1); - - expect(obj).to.have.property('hitArea'); - expect(obj).to.have.property('interactive'); // TODO: Have a better default value - expect('mask' in obj).to.be.true; // TODO: Have a better default value - expect(obj.mask).to.be.null; - - expect(obj).to.have.property('renderable'); - expect(obj).to.have.property('stage'); - - expect(obj).to.have.deep.property('worldTransform'); - pixi_core_Matrix_confirmNewMatrix(obj.worldTransform); - - //expect(obj).to.have.deep.property('color.length', 0); - //expect(obj).to.have.property('dynamic', true); -} diff --git a/test/lib/pixi/display/DisplayObjectContainer.js b/test/lib/pixi/display/DisplayObjectContainer.js deleted file mode 100644 index 58160a9..0000000 --- a/test/lib/pixi/display/DisplayObjectContainer.js +++ /dev/null @@ -1,18 +0,0 @@ - -function pixi_display_DisplayObjectContainer_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObject_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.DisplayObjectContainer); - expect(obj).to.respondTo('addChild'); - expect(obj).to.respondTo('addChildAt'); - expect(obj).to.respondTo('swapChildren'); - expect(obj).to.respondTo('getChildAt'); - expect(obj).to.respondTo('getChildIndex'); - expect(obj).to.respondTo('setChildIndex'); - expect(obj).to.respondTo('removeChild'); - expect(obj).to.respondTo('updateTransform'); - - expect(obj).to.have.deep.property('children.length', 0); -} diff --git a/test/lib/pixi/display/Sprite.js b/test/lib/pixi/display/Sprite.js deleted file mode 100644 index 2288c16..0000000 --- a/test/lib/pixi/display/Sprite.js +++ /dev/null @@ -1,30 +0,0 @@ - -function pixi_display_Sprite_confirmNew(obj, done) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Sprite); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - expect(obj).to.have.property('hitArea', null); - expect(obj).to.have.property('interactive', false); - expect(obj).to.have.property('renderable', true); - expect(obj).to.have.property('stage', null); - - expect(obj).to.have.property('anchor'); - pixi_core_Point_confirm(obj.anchor, 0, 0); - - expect(obj).to.have.property('blendMode', PIXI.blendModes.NORMAL); - expect(obj).to.have.property('width', 1); // TODO: is 1 expected - expect(obj).to.have.property('height', 1); // TODO: is 1 expected - - expect(obj).to.have.property('tint', 0xFFFFFF); - - // FIXME: Just make this a boolean that is always there - expect(!!obj.updateFrame).to.equal(obj.texture.baseTexture.hasLoaded); - - expect(obj).to.have.property('texture'); - pixi_textures_Texture_confirmNew(obj.texture, done); -} diff --git a/test/lib/pixi/extras/Strip.js b/test/lib/pixi/extras/Strip.js deleted file mode 100644 index 8927a8a..0000000 --- a/test/lib/pixi/extras/Strip.js +++ /dev/null @@ -1,12 +0,0 @@ - -function pixi_extras_Strip_confirmNew(obj) { - var expect = chai.expect; - - pixi_display_DisplayObjectContainer_confirmNew(obj); - - expect(obj).to.be.an.instanceof(PIXI.Strip); - expect(obj).to.respondTo('setTexture'); - expect(obj).to.respondTo('onTextureUpdate'); - - // TODO: Test properties -} diff --git a/test/lib/pixi/textures/RenderTexture.js b/test/lib/pixi/textures/RenderTexture.js deleted file mode 100644 index 8556501..0000000 --- a/test/lib/pixi/textures/RenderTexture.js +++ /dev/null @@ -1,14 +0,0 @@ - -function pixi_textures_RenderTexture_confirmNew(obj, done) { - var expect = chai.expect; - - expect(obj).to.have.property('width'); - expect(obj).to.have.property('height'); - - expect(obj).to.have.property('render'); - expect(obj).to.have.property('renderer'); - // expect(obj).to.have.property('projection'); - expect(obj).to.have.property('textureBuffer'); - - pixi_textures_Texture_confirmNew(obj, done); -} diff --git a/test/lib/pixi/textures/Texture.js b/test/lib/pixi/textures/Texture.js deleted file mode 100644 index 2493385..0000000 --- a/test/lib/pixi/textures/Texture.js +++ /dev/null @@ -1,26 +0,0 @@ - -function pixi_textures_Texture_confirmNew(obj, done) { - var expect = chai.expect; - - function confirmFrameDone() { - pixi_core_Rectangle_confirm(obj.frame, 0, 0, obj.baseTexture.width, obj.baseTexture.height); - - expect(obj).to.have.property('width', obj.baseTexture.width); - expect(obj).to.have.property('height', obj.baseTexture.height); - done(); - } - - expect(obj).to.be.an.instanceof(PIXI.Texture); - pixi_utils_EventTarget_confirm(obj); - - expect(obj).to.have.property('baseTexture') - .and.to.be.an.instanceof(PIXI.BaseTexture); - - expect(obj).to.have.property('frame'); - if (obj.baseTexture.hasLoaded) { - confirmFrameDone(); - } else { - obj.on('update', confirmFrameDone); - pixi_core_Rectangle_confirm(obj.frame, 0, 0, 1, 1); - } -} diff --git a/test/lib/pixi/utils/EventTarget.js b/test/lib/pixi/utils/EventTarget.js deleted file mode 100644 index a0c3924..0000000 --- a/test/lib/pixi/utils/EventTarget.js +++ /dev/null @@ -1,34 +0,0 @@ - -function pixi_utils_EventTarget_confirm(obj) { - var expect = chai.expect; - - //public API - expect(obj).to.respondTo('listeners'); - expect(obj).to.respondTo('emit'); - expect(obj).to.respondTo('on'); - expect(obj).to.respondTo('once'); - expect(obj).to.respondTo('off'); - expect(obj).to.respondTo('removeAllListeners'); - - //Aliased names - expect(obj).to.respondTo('removeEventListener'); - expect(obj).to.respondTo('addEventListener'); - expect(obj).to.respondTo('dispatchEvent'); -} - -function pixi_utils_EventTarget_Event_confirm(event, obj, data) { - var expect = chai.expect; - - expect(event).to.be.an.instanceOf(PIXI.Event); - - expect(event).to.have.property('stopped', false); - expect(event).to.have.property('stoppedImmediate', false); - - expect(event).to.have.property('target', obj); - expect(event).to.have.property('type', data.type || 'myevent'); - expect(event).to.have.property('data', data); - expect(event).to.have.property('content', data); - - expect(event).to.respondTo('stopPropagation'); - expect(event).to.respondTo('stopImmediatePropagation'); -} \ No newline at end of file diff --git a/test/lib/resemble.js b/test/lib/resemble.js deleted file mode 100644 index 1cb8c29..0000000 --- a/test/lib/resemble.js +++ /dev/null @@ -1,535 +0,0 @@ -/* -Author: James Cryer -Company: Huddle -Last updated date: 21 Feb 2013 -URL: https://github.com/Huddle/Resemble.js -*/ - -(function(_this){ - 'use strict'; - - _this['resemble'] = function( fileData ){ - - var data = {}; - var images = []; - var updateCallbackArray = []; - - var tolerance = { // between 0 and 255 - red: 16, - green: 16, - blue: 16, - minBrightness: 16, - maxBrightness: 240 - }; - - var ignoreAntialiasing = false; - var ignoreColors = false; - - function triggerDataUpdate(){ - var len = updateCallbackArray.length; - var i; - for(i=0;i tolerance.maxBrightness; - } - - function getHue(r,g,b){ - - r = r / 255; - g = g / 255; - b = b / 255; - var max = Math.max(r, g, b), min = Math.min(r, g, b); - var h; - var d; - - if (max == min){ - h = 0; // achromatic - } else{ - d = max - min; - switch(max){ - case r: h = (g - b) / d + (g < b ? 6 : 0); break; - case g: h = (b - r) / d + 2; break; - case b: h = (r - g) / d + 4; break; - } - h /= 6; - } - - return h; - } - - function isAntialiased(sourcePix, data, cacheSet, verticalPos, horizontalPos, width){ - var offset; - var targetPix; - var distance = 1; - var i; - var j; - var hasHighContrastSibling = 0; - var hasSiblingWithDifferentHue = 0; - var hasEquivilantSibling = 0; - - addHueInfo(sourcePix); - - for (i = distance*-1; i <= distance; i++){ - for (j = distance*-1; j <= distance; j++){ - - if(i===0 && j===0){ - // ignore source pixel - } else { - - offset = ((verticalPos+j)*width + (horizontalPos+i)) * 4; - targetPix = getPixelInfo(data, offset, cacheSet); - - if(targetPix === null){ - continue; - } - - addBrightnessInfo(targetPix); - addHueInfo(targetPix); - - if( isContrasting(sourcePix, targetPix) ){ - hasHighContrastSibling++; - } - - if( isRGBSame(sourcePix,targetPix) ){ - hasEquivilantSibling++; - } - - if( Math.abs(targetPix.h - sourcePix.h) > 0.3 ){ - hasSiblingWithDifferentHue++; - } - - if( hasSiblingWithDifferentHue > 1 || hasHighContrastSibling > 1){ - return true; - } - } - } - } - - if(hasEquivilantSibling < 2){ - return true; - } - - return false; - } - - function errorPixel(px, offset){ - px[offset] = 255; //r - px[offset + 1] = 0; //g - px[offset + 2] = 255; //b - px[offset + 3] = 255; //a - } - - function copyPixel(px, offset, data){ - px[offset] = data.r; //r - px[offset + 1] = data.g; //g - px[offset + 2] = data.b; //b - px[offset + 3] = 255; //a - } - - function copyGrayScalePixel(px, offset, data){ - px[offset] = data.brightness; //r - px[offset + 1] = data.brightness; //g - px[offset + 2] = data.brightness; //b - px[offset + 3] = 255; //a - } - - - function getPixelInfo(data, offset, cacheSet){ - var r; - var g; - var b; - var d; - - if(typeof data[offset] !== 'undefined'){ - r = data[offset]; - g = data[offset+1]; - b = data[offset+2]; - d = { - r: r, - g: g, - b: b - }; - - return d; - } else { - return null; - } - } - - function addBrightnessInfo(data){ - data.brightness = getBrightness(data.r,data.g,data.b); // 'corrected' lightness - } - - function addHueInfo(data){ - data.h = getHue(data.r,data.g,data.b); - } - - function analyseImages(img1, img2, width, height){ - - var hiddenCanvas = document.createElement('canvas'); - - var data1 = img1.data; - var data2 = img2.data; - - hiddenCanvas.width = width; - hiddenCanvas.height = height; - - var context = hiddenCanvas.getContext('2d'); - var imgd = context.createImageData(width,height); - var targetPix = imgd.data; - - var mismatchCount = 0; - - var time = Date.now(); - - var skip; - - if( (width > 1200 || height > 1200) && ignoreAntialiasing){ - skip = 6; - } - - loop(height, width, function(verticalPos, horizontalPos){ - - if(skip){ // only skip if the image isn't small - if(verticalPos % skip === 0 || horizontalPos % skip === 0){ - return; - } - } - - var offset = (verticalPos*width + horizontalPos) * 4; - var pixel1 = getPixelInfo(data1, offset, 1); - var pixel2 = getPixelInfo(data2, offset, 2); - - if(pixel1 === null || pixel2 === null){ - return; - } - - if (ignoreColors){ - - addBrightnessInfo(pixel1); - addBrightnessInfo(pixel2); - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - return; - } - - if( isRGBSimilar(pixel1, pixel2) ){ - copyPixel(targetPix, offset, pixel2); - - } else if( ignoreAntialiasing && ( - addBrightnessInfo(pixel1), // jit pixel info augmentation looks a little weird, sorry. - addBrightnessInfo(pixel2), - isAntialiased(pixel1, data1, 1, verticalPos, horizontalPos, width) || - isAntialiased(pixel2, data2, 2, verticalPos, horizontalPos, width) - )){ - - if( isPixelBrightnessSimilar(pixel1, pixel2) ){ - copyGrayScalePixel(targetPix, offset, pixel2); - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - } else { - errorPixel(targetPix, offset); - mismatchCount++; - } - - }); - - data.misMatchPercentage = (mismatchCount / (height*width) * 100).toFixed(2); - data.analysisTime = Date.now() - time; - - data.getImageDataUrl = function(text){ - var barHeight = 0; - - if(text){ - barHeight = addLabel(text,context,hiddenCanvas); - } - - context.putImageData(imgd, 0, barHeight); - - return hiddenCanvas.toDataURL("image/png"); - }; - } - - function addLabel(text, context, hiddenCanvas){ - var textPadding = 2; - - context.font = '12px sans-serif'; - - var textWidth = context.measureText(text).width + textPadding*2; - var barHeight = 22; - - if(textWidth > hiddenCanvas.width){ - hiddenCanvas.width = textWidth; - } - - hiddenCanvas.height += barHeight; - - context.fillStyle = "#666"; - context.fillRect(0,0,hiddenCanvas.width,barHeight -4); - context.fillStyle = "#fff"; - context.fillRect(0,barHeight -4,hiddenCanvas.width, 4); - - context.fillStyle = "#fff"; - context.textBaseline = "top"; - context.font = '12px sans-serif'; - context.fillText(text, textPadding, 1); - - return barHeight; - } - - function normalise(img, w, h){ - var c; - var context; - - if(img.height < h || img.width < w){ - c = document.createElement('canvas'); - c.width = w; - c.height = h; - context = c.getContext('2d'); - context.putImageData(img, 0, 0); - return context.getImageData(0, 0, w, h); - } - - return img; - } - - function compare(one, two){ - - function onceWeHaveBoth(){ - var width; - var height; - if(images.length === 2){ - width = images[0].width > images[1].width ? images[0].width : images[1].width; - height = images[0].height > images[1].height ? images[0].height : images[1].height; - - if( (images[0].width === images[1].width) && (images[0].height === images[1].height) ){ - data.isSameDimensions = true; - } else { - data.isSameDimensions = false; - } - - analyseImages( normalise(images[0],width, height), normalise(images[1],width, height), width, height); - - triggerDataUpdate(); - } - } - - images = []; - loadImageData(one, onceWeHaveBoth); - loadImageData(two, onceWeHaveBoth); - } - - function getCompareApi(param){ - - var secondFileData, - hasMethod = typeof param === 'function'; - - if( !hasMethod ){ - // assume it's file data - secondFileData = param; - } - - var self = { - ignoreNothing: function(){ - - tolerance.red = 16; - tolerance.green = 16; - tolerance.blue = 16; - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreAntialiasing: function(){ - - tolerance.red = 32; - tolerance.green = 32; - tolerance.blue = 32; - tolerance.minBrightness = 64; - tolerance.maxBrightness = 96; - - ignoreAntialiasing = true; - ignoreColors = false; - - if(hasMethod) { param(); } - return self; - }, - ignoreColors: function(){ - - tolerance.minBrightness = 16; - tolerance.maxBrightness = 240; - - ignoreAntialiasing = false; - ignoreColors = true; - - if(hasMethod) { param(); } - return self; - }, - onComplete: function( callback ){ - - updateCallbackArray.push(callback); - - var wrapper = function(){ - compare(fileData, secondFileData); - }; - - wrapper(); - - return getCompareApi(wrapper); - } - }; - - return self; - } - - return { - onComplete: function( callback ){ - updateCallbackArray.push(callback); - loadImageData(fileData, function(imageData, width, height){ - parseImage(imageData.data, width, height); - }); - }, - compareTo: function(secondFileData){ - return getCompareApi(secondFileData); - } - }; - - }; -}(this)); \ No newline at end of file diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 69e1b7a..0000000 --- a/test/setup.js +++ /dev/null @@ -1 +0,0 @@ -expect = chai.expect; diff --git a/test/textures/SpriteSheet-Aliens.png b/test/textures/SpriteSheet-Aliens.png deleted file mode 100644 index 210acb1..0000000 --- a/test/textures/SpriteSheet-Aliens.png +++ /dev/null Binary files differ diff --git a/test/textures/SpriteSheet-Explosion.png b/test/textures/SpriteSheet-Explosion.png deleted file mode 100755 index 79e1a69..0000000 --- a/test/textures/SpriteSheet-Explosion.png +++ /dev/null Binary files differ diff --git a/test/textures/bunny.png b/test/textures/bunny.png deleted file mode 100644 index 79c3167..0000000 --- a/test/textures/bunny.png +++ /dev/null Binary files differ diff --git a/test/unit/core/Bounds.test.js b/test/unit/core/Bounds.test.js deleted file mode 100644 index d3aa989..0000000 --- a/test/unit/core/Bounds.test.js +++ /dev/null @@ -1,362 +0,0 @@ -describe('getBounds', function () { - - - it('should register correct width and height with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var bounds = sprite.getBounds(true); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(graphics); - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - graphics.position.x = 20; - graphics.position.y = 20; - - graphics.scale.x = 2; - graphics.scale.y = 2; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(40); - expect(bounds.height).to.equal(40); - - }); - - it('should register correct width and height with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - }); - - it('should register correct width and height with a Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(80); - expect(bounds.height).to.equal(90); - - container.rotation = 0.1; - - var bounds = container.getBounds(); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - var bounds = container.getBounds(true); - - expect(bounds.x | 0).to.equal(26); - expect(bounds.y | 0).to.equal(22); - expect(bounds.width | 0).to.equal(73); - expect(bounds.height | 0).to.equal(97); - - - }); - - it('should register correct width and height with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - var bounds = graphics.getBounds(true); - - expect(bounds.x).to.equal(100); - expect(bounds.y).to.equal(100); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - - }); - - it('should register correct width and height with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - plane.scale.x = 2; - plane.scale.y = 2; - - var bounds = plane.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct width and height with an a DisplayObject is visible false', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var texture = PIXI.RenderTexture.create(10, 10); - var sprite = new PIXI.Sprite(texture); - - container.addChild(sprite); - container.addChild(graphics); - - parent.addChild(container); - - sprite.position.x = 30; - sprite.position.y = 20; - graphics.position.x = 100; - graphics.position.y = 100; - - graphics.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(30); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - container.visible = false; - - var bounds = container.getBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct width and height with an a DisplayObject parent has moved', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - container.addChild(graphics); - - parent.addChild(container); - - // graphics.position.x = 100; - // graphics.position.y = 100; - container.position.x -= 100; - container.position.y -= 100; - - var bounds = graphics.getBounds(); - - expect(bounds.x).to.equal(-110); - expect(bounds.y).to.equal(-110); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - }); - - it('should register correct width and height with an a Text Object', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var text = new PIXI.Text('i am some text'); - - container.addChild(text); - - parent.addChild(container); - - var bounds = text.getBounds(); - var bx = bounds.width; - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.be.greaterThan(0); - expect(bounds.height).to.greaterThan(0); - - text.text = 'hello!'; - - var bounds = text.getBounds(); - - // this variable seems to be different on different devices. a font thing? - expect(bounds.width).to.not.equal(bx); - - }); - - it('should return a different rectangle if getting local bounds after global bounds ', function() { - - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - parent.addChild(sprite); - - - var bounds = sprite.getBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - var localBounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(20); - expect(bounds.y).to.equal(20); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - - - }); - - - }); diff --git a/test/unit/core/LocalBounds.test.js b/test/unit/core/LocalBounds.test.js deleted file mode 100644 index 7130af6..0000000 --- a/test/unit/core/LocalBounds.test.js +++ /dev/null @@ -1,119 +0,0 @@ -describe('getLocalBounds', function () { - - - it('should register correct local-bounds with a LOADED Sprite', function() { - var parent = new PIXI.Container(); - var texture = PIXI.RenderTexture.create(10, 10); - - var sprite = new PIXI.Sprite(texture); - - parent.addChild(sprite); - - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - sprite.position.x = 20; - sprite.position.y = 20; - - sprite.scale.x = 2; - sprite.scale.y = 2; - - var bounds = sprite.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - - it('should register correct local-bounds with Graphics', function() { - var parent = new PIXI.Container(); - - var graphics = new PIXI.Graphics(); - - graphics.beginFill(0xFF0000).drawCircle(0, 0, 10);//texture); - - graphics.scale.set(2); - - parent.addChild(graphics); - - var bounds = graphics.getLocalBounds(); - - expect(bounds.x).to.equal(-10); - expect(bounds.y).to.equal(-10); - expect(bounds.width).to.equal(20); - expect(bounds.height).to.equal(20); - - }); - - it('should register correct local-bounds with an empty Container', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - parent.addChild(container); - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(0); - expect(bounds.height).to.equal(0); - - - }); - - it('should register correct local-bounds with an item that has already had its parent Container transformed', function() { - var parent = new PIXI.Container(); - - var container = new PIXI.Container();//Graphics().beginFill(0xFF0000).drawCircle(0, 0, 10, 10);//texture); - - var graphics = new PIXI.Graphics().beginFill(0xFF0000).drawRect(0, 0, 10, 10);//texture); - - - parent.addChild(container); - container.addChild(graphics); - - container.position.x = 100; - container.position.y = 100; - - var bounds = container.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - - }); - - it('should register correct local-bounds with a Mesh', function() { - var parent = new PIXI.Container(); - - var texture = PIXI.RenderTexture.create(10, 10); - - var plane = new PIXI.mesh.Plane(texture); - - parent.addChild(plane); - - plane.position.x = 20; - plane.position.y = 20; - - var bounds = plane.getLocalBounds(); - - expect(bounds.x).to.equal(0); - expect(bounds.y).to.equal(0); - expect(bounds.width).to.equal(10); - expect(bounds.height).to.equal(10); - - - }); - }); diff --git a/test/unit/core/display/Container.test.js b/test/unit/core/display/Container.test.js deleted file mode 100644 index 668cbed..0000000 --- a/test/unit/core/display/Container.test.js +++ /dev/null @@ -1,108 +0,0 @@ -describe('PIXI.Container', function () { - describe('parent', function () { - it('should be present when adding children to Container', function() { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - expect(container.children.length).to.be.equals(0); - container.addChild(child); - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(container); - }); - }); - - describe('events', function () { - it('should trigger "added" and "removed" events on it\'s children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - triggeredAdded = false, - triggeredRemoved = false; - - child.on('added', function(to) { - triggeredAdded = true; - expect(container.children.length).to.be.equals(1); - expect(child.parent).to.be.equals(to); - }); - child.on('removed', function(from) { - triggeredRemoved = true; - expect(container.children.length).to.be.equals(0); - expect(child.parent).to.be.null; - expect(container).to.be.equals(from); - }); - - container.addChild(child); - expect(triggeredAdded).to.be.true; - expect(triggeredRemoved).to.be.false; - - container.removeChild(child); - expect(triggeredRemoved).to.be.true; - }); - - }); - - describe('destroy', function () { - it('should call through to DisplayContainer.destroy', function () { - var container = new PIXI.Container(); - - expect(container.transform).to.not.equal(null); - container.destroy(); - expect(container.transform).to.equal(null); - }); - - it('should set children to null', function () { - var container = new PIXI.Container(); - - expect(container.children).to.deep.equal([]); - container.destroy(); - expect(container.children).to.equal(null); - }); - - it('should by default not destroy children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy(); - expect(container.transform).to.equal(null); - expect(child.transform).to.not.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(); - - container.addChild(child); - container.destroy({children: true}); - expect(container.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should accept boolean and pass it on to children', function () { - var container = new PIXI.Container(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - container.addChild(child); - container.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/display/DisplayObject.test.js b/test/unit/core/display/DisplayObject.test.js deleted file mode 100644 index 5d8ccd8..0000000 --- a/test/unit/core/display/DisplayObject.test.js +++ /dev/null @@ -1,19 +0,0 @@ -describe('PIXI.DisplayObject', function () { - it('should be able to add itself to a Container', function() { - var child = new PIXI.DisplayObject(), - container = new PIXI.Container(); - - expect(container.children.length).to.equal(0); - child.setParent(container); - expect(container.children.length).to.equal(1); - expect(child.parent).to.equal(container); - }); - - it('should be be able to destroy itself', function() { - - var child = new PIXI.DisplayObject(); - - child.destroy(); - - }); -}); diff --git a/test/unit/core/sprites/Sprite.test.js b/test/unit/core/sprites/Sprite.test.js deleted file mode 100644 index fda975a..0000000 --- a/test/unit/core/sprites/Sprite.test.js +++ /dev/null @@ -1,153 +0,0 @@ -describe('PIXI.Sprite', function () { - describe('width', function () { - it('should not be negative for nagative scale.x', function () { - var sprite = new PIXI.Sprite(); - - sprite.width = 100; - expect(sprite.width).to.be.at.least(0); - sprite.scale.x = -1; - expect(sprite.width).to.be.at.least(0); - }); - - it('should not change sign of scale.x', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.width = 100; - sprite.scale.x = 1; - sprite.width = 50; - - expect(sprite.scale.x).to.be.above(0); - - sprite.scale.x = -1; - sprite.width = 75; - - expect(sprite.scale.x).to.be.below(0); - }); - }); - - describe('height', function () { - it('should not be negative for nagative scale.y', function () { - var sprite = new PIXI.Sprite(); - - sprite.height = 100; - expect(sprite.height).to.be.at.least(0); - sprite.scale.y = -1; - expect(sprite.height).to.be.at.least(0); - }); - - it('should not change sign of scale.y', function () { - var texture = new PIXI.Texture(new PIXI.BaseTexture()); - var sprite = new PIXI.Sprite(); - - texture.height = 100; - sprite.scale.y = 1; - sprite.height = 50; - - expect(sprite.scale.y).to.be.above(0); - - sprite.scale.y = -1; - sprite.height = 75; - - expect(sprite.scale.y).to.be.below(0); - }); - }); - - describe('destroy', function () { - it('should call through to Container.destroy', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.children).to.not.equal(null); - sprite.destroy(); - expect(sprite.children).to.equal(null); - }); - - it('should set anchor and texture to null', function () { - var sprite = new PIXI.Sprite(); - - expect(sprite.anchor).to.not.equal(null); - expect(sprite.texture).to.not.equal(null); - sprite.destroy(); - expect(sprite.anchor).to.equal(null); - expect(sprite.texture).to.equal(null); - }); - - it('by default should not destroy texture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy(); - expect(textureDestroyed).to.equal(false); - }); - - it('should destroy texture when texture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyed = false; - - sprite.texture.destroy = function() { textureDestroyed = true; }; - - sprite.destroy({texture: true}); - expect(textureDestroyed).to.equal(true); - }); - - it('by default should not destroy baseTexture', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true}); - expect(textureDestroyArg).to.equal(false); - }); - - it('should destroy baseTexture if baseTexture flag is set', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy({texture: true, baseTexture: true}); - expect(textureDestroyArg).to.equal(true); - }); - - it('should correctly handle boolean', function () { - var sprite = new PIXI.Sprite(); - var textureDestroyArg; - - sprite.texture.destroy = function(arg) { textureDestroyArg = arg; }; - - sprite.destroy(true); - expect(textureDestroyArg).to.equal(true); - }); - - it('should pass opts on to children if children flag is set', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - - it('should pass bool on to children', function () { - var sprite = new PIXI.Sprite(), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - sprite.addChild(child); - sprite.destroy(true); - expect(childDestroyOpts).to.deep.equal(true); - }); - }); -}); diff --git a/test/unit/core/text/Text.test.js b/test/unit/core/text/Text.test.js deleted file mode 100644 index 4564c06..0000000 --- a/test/unit/core/text/Text.test.js +++ /dev/null @@ -1,53 +0,0 @@ -describe('PIXI.Text', function () { - describe('destroy', function () { - it('should call through to Sprite.destroy', function () { - var text = new PIXI.Text("foo"); - - expect(text.anchor).to.not.equal(null); - text.destroy(); - expect(text.anchor).to.equal(null); - }); - - it('should set context to null', function () { - var text = new PIXI.Text("foo"); - - expect(text.style).to.not.equal(null); - text.destroy(); - expect(text.style).to.equal(null); - }); - - it('should destroy children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy({children: true}); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should accept boolean correctly', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(); - - text.addChild(child); - text.destroy(true); - expect(text.transform).to.equal(null); - expect(child.transform).to.equal(null); - }); - - it('should pass opts on to children if children flag is set', function () { - var text = new PIXI.Text("foo"), - child = new PIXI.DisplayObject(), - childDestroyOpts; - - child.destroy = function(opts) { - childDestroyOpts = opts; - }; - - text.addChild(child); - text.destroy({children: true, texture: true}); - expect(childDestroyOpts).to.deep.equal({children: true, texture: true}); - }); - }); -}); diff --git a/test/unit/core/toGlobal.test.js b/test/unit/core/toGlobal.test.js deleted file mode 100644 index 7e28e00..0000000 --- a/test/unit/core/toGlobal.test.js +++ /dev/null @@ -1,32 +0,0 @@ -describe('toGlobal', function () { - - - it('should return correct global cordinates of a point from within a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(100); - expect(globalPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var globalPoint = container.toGlobal(point); - - expect(globalPoint.x).to.equal(220); - expect(globalPoint.y).to.equal(220); - - }); - -}); diff --git a/test/unit/core/toLocal.test.js b/test/unit/core/toLocal.test.js deleted file mode 100644 index 93d6046..0000000 --- a/test/unit/core/toLocal.test.js +++ /dev/null @@ -1,59 +0,0 @@ -describe('toLocal', function () { - - - it('should return correct local cordinates of a displayObject', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - - parent.addChild(container); - - var point = new PIXI.Point(100, 100); - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - container.position.x = 20; - container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point); - - expect(localPoint.x).to.equal(40); - expect(localPoint.y).to.equal(40); - - }); - - it('should map the correct local cordinates of a displayObject to another', function() { - - var parent = new PIXI.Container(); - - var container = new PIXI.Container(); - var container2 = new PIXI.Container(); - - parent.addChild(container); - parent.addChild(container2); - - container2.position.x = 100; - container2.position.y = 100; - - var point = new PIXI.Point(100, 100); - - // container.position.x = 20; - // container.position.y = 20; - - container.scale.x = 2; - container.scale.y = 2; - - var localPoint = container.toLocal(point, container2); - - expect(localPoint.x).to.equal(100); - expect(localPoint.y).to.equal(100); - - }); -}); diff --git a/test/unit/core/utils/util.test.js b/test/unit/core/utils/util.test.js deleted file mode 100644 index 145111b..0000000 --- a/test/unit/core/utils/util.test.js +++ /dev/null @@ -1,114 +0,0 @@ -describe('PIXI.utils', function () { - describe('.uid', function () { - it('should exist', function () { - expect(PIXI.utils.uid) - .to.be.a('function'); - }); - - it('should return a number', function () { - expect(PIXI.utils.uid()) - .to.be.a('number'); - }); - }); - - describe('.hex2rgb', function () { - it('should exist', function () { - expect(PIXI.utils.hex2rgb) - .to.be.a('function'); - }); - - it('should properly convert number to rgb array'); - }); - - describe('.hex2string', function () { - it('should exist', function () { - expect(PIXI.utils.hex2string) - .to.be.a('function'); - }); - - it('should properly convert number to hex color string'); - }); - - describe('.rgb2hex', function () { - it('should exist', function () { - expect(PIXI.utils.rgb2hex) - .to.be.a('function'); - }); - - it('should properly convert rgb array to hex color string'); - }); - - describe('.getResolutionOfUrl', function () { - it('should exist', function () { - expect(PIXI.utils.getResolutionOfUrl) - .to.be.a('function'); - }); - - it('should return the correct resolution based on a URL'); - }); - - describe('.sayHello', function () { - it('should exist', function () { - expect(PIXI.utils.sayHello) - .to.be.a('function'); - }); - }); - - describe('.isWebGLSupported', function () { - it('should exist', function () { - expect(PIXI.utils.isWebGLSupported) - .to.be.a('function'); - }); - }); - - describe('.sign', function () { - it('should return 0 for 0', function () { - expect(PIXI.utils.sign(0)) - .to.be.equal(0); - }); - - it('should return -1 for negative numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(-Math.random())) - .to.be.equal(-1); - } - }); - - it('should return 1 for positive numbers', function () { - for (var i = 0;i<10;i+=1){ - expect(PIXI.utils.sign(Math.random() + 0.000001)) - .to.be.equal(1); - } - }); - }); - - describe('.removeItems', function () { - var arr; - - beforeEach(function () { - arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - }); - - it('should return if the start index is greater than or equal to the length of the array', function () { - PIXI.utils.removeItems(arr, arr.length+1, 5); - expect(arr.length).to.be.equal(10); - }); - - it('should return if the remove count is 0', function () { - PIXI.utils.removeItems(arr, 2, 0); - expect(arr.length).to.be.equal(10); - }); - - it('should remove the number of elements specified from the array, starting from the start index', function () { - var res = [ 1, 2, 3, 8, 9, 10 ]; - PIXI.utils.removeItems(arr, 3, 4); - expect(arr).to.be.deep.equal(res); - }); - - it('should remove rest of elements if the delete count is > than the number of elements after start index', function () { - var res = [ 1, 2, 3, 4, 5, 6, 7 ]; - PIXI.utils.removeItems(arr, 7, 10); - expect(arr).to.be.deep.equal(res); - }); - }); -}); diff --git a/test/unit/index.test.js b/test/unit/index.test.js deleted file mode 100644 index 37e1d2a..0000000 --- a/test/unit/index.test.js +++ /dev/null @@ -1,6 +0,0 @@ -describe('PIXI', function () { - it('exists', function () { - expect(PIXI) - .to.be.an('object'); - }); -}); diff --git a/test/unit/interaction/InteractionData.test.js b/test/unit/interaction/InteractionData.test.js deleted file mode 100644 index 690ca16..0000000 --- a/test/unit/interaction/InteractionData.test.js +++ /dev/null @@ -1,22 +0,0 @@ -describe('PIXI.interaction.InteractionData', function() { - describe('getLocalPosition', function() { - it('should populate second parameter with result', function() { - var data = new PIXI.interaction.InteractionData(), - stage = new PIXI.DisplayObject(), - displayObject = new PIXI.DisplayObject(), - point = new PIXI.Point(); - - data.global.set(10, 10); - - displayObject.position.set(5, 3); - - displayObject.parent = stage - displayObject.displayObjectUpdateTransform(); - - data.getLocalPosition(displayObject, point); - - expect(point.x).to.equal(5); - expect(point.y).to.equal(7); - }); - }); -}); diff --git a/testem.json b/testem.json deleted file mode 100644 index 84c76ef..0000000 --- a/testem.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "framework" : "mocha+chai", - "launch_in_dev" : ["Chrome", "Firefox"], - "launch_in_ci" : ["Firefox"], - "src_files" : [ - "bin/pixi.js", - - "test/setup.js", - "test/unit/**/*.test.js" - ], - "launchers": { - "node": { - "command": "./node_modules/.bin/mocha -r ./test/setup.js -R tap --recursive ./test/unit/", - "protocol": "tap" - } - } -}