Skip to content

Commit

Permalink
Fix unit test and circle ci (cocos#2858)
Browse files Browse the repository at this point in the history
* fix test-animation bug (cocos#2787)

* fix unit test (cocos#2840)

* Improve Sprite & SpriteFrame impl

* Add Sprite inset function deprecation

* Fix unit tests

* fixed the circleci failed test but still pass the commit problem (cocos#2814)

* CircleCI test failed but build successfully problem fixed (cocos#2816)

* Fix Skeleton require

* Another Skeleton mistyping

* Fix phantom environment issues
  • Loading branch information
pandamicro authored Jun 14, 2018
1 parent fd37907 commit 2a3a75e
Show file tree
Hide file tree
Showing 21 changed files with 361 additions and 230 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version: 2
jobs:
test:
docker:
- image: circleci/node:latest
- image: circleci/node:8.9.4
steps:
- checkout
- run: sudo npm install -g gulp
- run: npm install gulp-qunit
- run: npm install
- run: npm test
- run: npm test

workflows:
version: 2
Expand Down
2 changes: 1 addition & 1 deletion cocos2d/core/assets/CCSpriteFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
}

if (filename !== undefined) {
this.initWithTexture(filename, rect, rotated, offset, originalSize);
this.setTexture(filename, rect, rotated, offset, originalSize);
} else {
//todo log Error
}
Expand Down
3 changes: 2 additions & 1 deletion cocos2d/core/components/CCSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ var Sprite = cc.Class({
return this._fillCenter;
},
set: function(value) {
this._fillCenter = cc.v2(value);
this._fillCenter.x = value.x;
this._fillCenter.y = value.y;
if (this._type === SpriteType.FILLED && this._renderData) {
this.markForUpdateRenderData(true);
}
Expand Down
7 changes: 7 additions & 0 deletions cocos2d/deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ if (CC_DEV) {
'isRunning',
]);

provideClearError(cc.Sprite.prototype, {
setInsetLeft: 'cc.SpriteFrame insetLeft',
setInsetRight: 'cc.SpriteFrame insetRight',
setInsetTop: 'cc.SpriteFrame insetTop',
setInsetBottom: 'cc.SpriteFrame insetBottom',
});

// cc.Camera
markFunctionWarning(cc.Camera.prototype, {
getNodeToCameraTransform: 'getWorldToCameraMatrix'
Expand Down
2 changes: 1 addition & 1 deletion extensions/spine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if (!CC_EDITOR || !Editor.isMainProcess) {
sp.spine = require('./lib/spine');
require('./skeleton-texture');
require('./skeleton-data');
require('./skeleton');
require('./Skeleton');
require('./spine-assembler');
}
else {
Expand Down
2 changes: 1 addition & 1 deletion extensions/spine/spine-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
****************************************************************************/

const js = require('../../cocos2d/core/platform/js');
const Skeleton = require('./skeleton');
const Skeleton = require('./Skeleton');
const spine = require('./lib/spine');
const renderer = require('../../cocos2d/core/renderer');
const RenderFlow = require('../../cocos2d/core/renderer/render-flow');
Expand Down
15 changes: 15 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,18 @@ gulp.task('watch-jsb-polyfill', function () {
});

gulp.task('watch-dev-files', ['watch-preview', 'watch-jsb-polyfill']);

gulp.task('test-in-ci', function () {
const { spawn } = require('child_process');
var gulp = process.platform === 'win32' ? 'gulp.cmd' : 'gulp';
var child = spawn(gulp, ['test'], {
stdio: [0, 'pipe', 2]
});
child.stdout.on('data', function (data) {
process.stdout.write(data);
if (data.toString().indexOf(' assertions failed ') !== -1) {
process.exitCode = 1;
process.exit();
}
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"license": "MIT",
"scripts": {
"test": "gulp test"
"test": "gulp test-in-ci"
},
"devDependencies": {
"async": "1.5.2",
Expand Down
33 changes: 33 additions & 0 deletions test/qunit/lib/polyfill-for-phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,36 @@ if (isPhantomJS) {
if (typeof WebGLRenderingContext === 'undefined') {
window.WebGLRenderingContext = function () {};
}

if (!Object.assign) {
Object.defineProperty(Object, 'assign', {
enumerable: false,
configurable: true,
writable: true,
value: function(target) {
'use strict';
if (target === undefined || target === null) {
throw new TypeError('Cannot convert first argument to object');
}

var to = Object(target);
for (var i = 1; i < arguments.length; i++) {
var nextSource = arguments[i];
if (nextSource === undefined || nextSource === null) {
continue;
}
nextSource = Object(nextSource);

var keysArray = Object.keys(Object(nextSource));
for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
}
return to;
}
});
}
2 changes: 2 additions & 0 deletions test/qunit/unit-es5/_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ function _resetGame (w, h) {

cc._Test.eventManager.dispatchCustomEvent('canvas-resize');
}
// Forbid render in test
cc.renderer.render = function () {};
cc.director.purgeDirector();
cc.loader.releaseAll();

Expand Down
13 changes: 13 additions & 0 deletions test/qunit/unit-es5/test-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ test('Animation Component', function () {

entity.x = 400;

cc.director.getScene().addChild(entity);

var clip = new cc.AnimationClip();
clip._duration = 10;
clip._name = 'test';
Expand Down Expand Up @@ -315,6 +317,11 @@ test('Animation Component', function () {
strictEqual(animation.getAnimationState('test'), null, 'should remove state');

animation.stop();

animation.addClip(clip);
animation.play('test');
cc.director.runSceneImmediate(new cc.Scene());
strictEqual(!!(animation._animator && animation._animator.isPlaying), false, 'animation should be stopped after load scene');
});


Expand Down Expand Up @@ -450,6 +457,8 @@ test('EventAnimCurve', function () {
var entity = new cc.Node();
entity.addComponent(MyComp);

cc.director.getScene().addChild(entity);

var animation = entity.addComponent(cc.Animation);

var clip = new cc.AnimationClip();
Expand Down Expand Up @@ -911,6 +920,8 @@ test('EventAnimCurve', function () {
test('stop Animation', function () {
var entity = new cc.Node();
var animation = entity.addComponent(cc.Animation);

cc.director.getScene().addChild(entity);

var clip = new cc.AnimationClip();
clip._name = 'test';
Expand Down Expand Up @@ -1120,6 +1131,8 @@ test('animation callback', function () {
var entity = new cc.Node();
var animation = entity.addComponent(cc.Animation);

cc.director.getScene().addChild(entity);

var clip = new cc.AnimationClip();
clip._name = 'move';
clip._duration = 1;
Expand Down
4 changes: 2 additions & 2 deletions test/qunit/unit-es5/test-asset-library.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
var timerId = setTimeout(function () {
ok(false, 'time out!');
start();
}, 100);
}, 1000);
});
}

Expand All @@ -60,7 +60,7 @@
var timerId = setTimeout(function () {
ok(false, 'time out!');
start();
}, 200);
}, 2000);
});

asyncTest('load asset with depends asset recursively if no cache', function () {
Expand Down
5 changes: 4 additions & 1 deletion test/qunit/unit-es5/test-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,10 @@ test('simplified properties define', function () {
valueType: [cc.Vec2],
node: [cc.Node],
rawAsset: [cc.RawAsset],
asset: [cc.Asset],
asset: {
default: [],
type: cc.Asset
},
}
});

Expand Down
31 changes: 22 additions & 9 deletions test/qunit/unit-es5/test-deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,22 +244,35 @@ if (TestEditorExtends) {
});

testWithTarget('circular reference by object', function (useTarget) {
var MainAsset = cc.Class({
name: 'MainAsset',
extends: cc.Asset,
properties: {
myAsset: {
default: null,
type: cc.Asset
},
}
});

var MyAsset = cc.Class({
name: 'MyAsset',
extends: cc.Asset,
ctor: function () {
this.refSelf = this;
this.refToMain = null;
},
properties: {
refSelf: null,
refToMain: null
refSelf: {
default: null,
},
refToMain: {
default: null,
type: cc.Asset
},
}
});

var asset = new MyAsset();
var mainAsset = { myAsset: asset };
var mainAsset = new MainAsset();
asset.refToMain = mainAsset;
asset.refSelf = asset;
mainAsset.myAsset = asset;

var serializedAsset = Editor.serialize(mainAsset);
delete mainAsset.__id__;
Expand All @@ -271,7 +284,7 @@ if (TestEditorExtends) {

deepEqual(deserializedAsset, mainAsset, 'can ref');

cc.js.unregisterClass(MyAsset);
cc.js.unregisterClass(MainAsset, MyAsset);
});

testWithTarget('circular reference by array', function (useTarget) {
Expand Down
8 changes: 1 addition & 7 deletions test/qunit/unit-es5/test-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,7 @@ asyncTest('Load with dependencies', function () {
depsProgression.expect(depsCount, 'should call progress callback for all ' + depsCount + ' dependencies');
progressCallback.expect(total, 'should call ' + total + ' times progress callback for ' + total + ' resources');
var count = loader.getResCount();
if (isPhantomJS) {
// Test environment doesn't load audio
strictEqual(count, total-1, 'getResCount should return correct count of loaded resources');
}
else {
strictEqual(count, total, 'getResCount should return correct count of loaded resources');
}
strictEqual(count, total, 'getResCount should return correct count of loaded resources');
loader.releaseAll();

start();
Expand Down
7 changes: 3 additions & 4 deletions test/qunit/unit-es5/test-prefab.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
test('saved prefab node', function () {
var nodeToSave = prefab.data;
ok(cc.Node.isNode(nodeToSave), 'Checking prefab data');
ok(!nodeToSave._id, 'The id in prefab data should be cleared');
strictEqual(nodeToSave.scaleX, 123, 'Checking prefab data');
strictEqual(nodeToSave.scaleY, 432, 'Checking prefab data');
var comp = nodeToSave.getComponent(TestScript);
Expand Down Expand Up @@ -128,7 +127,7 @@

ok(newNode.children.length === 2, 'Should load child');
var c = newNode.children[0];
ok(c.getScaleX() === 22 && c.getScaleY() === 11, 'Checking child');
ok(c.scaleX === 22 && c.scaleY === 11, 'Checking child');
});

test('re-instantiate an instantiated node', function () {
Expand Down Expand Up @@ -194,13 +193,13 @@

_Scene.PrefabUtils.revertPrefab(testNode, function () {
ok(testNode.x != prefab.data.x, 'Should not revert root position');
ok(testNode.getScaleX() === 123 && testNode.getScaleY() === 432, 'Revert property of the parent node');
ok(testNode.scaleX === 123 && testNode.scaleY === 432, 'Revert property of the parent node');
ok(testNode.getComponent(TestScript).constructor === TestScript, 'Restore removed component');
ok(testNode.parent === originParent, 'parent should not changed');
ok(testNode.parent.getComponent(TestScript).target === originParent, 'component property of parent should not changed');

ok(testChild.x === prefab.data.children[0].x, 'Revert child position');
ok(testChild.getScaleX() === 22 && testChild.getScaleY() === 11, 'Revert child node');
ok(testChild.scaleX === 22 && testChild.scaleY === 11, 'Revert child node');
ok(testChild.getComponent(TestScript) == null, 'Remove added component');

ok(testNode.getComponent(TestScript).target === testChild, 'Should redirect reference to scene node');
Expand Down
10 changes: 5 additions & 5 deletions test/qunit/unit-es5/test-resources-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
setup: function () {
_resetGame();
Assets = {
'0000001': ['resources/grossini/grossini.png', cc.js._getClassId(cc.Texture2D)],
'123201': ['resources/grossini/grossini', cc.js._getClassId(TestSprite), 1],
'0000000': ['resources/grossini.png', cc.js._getClassId(cc.Texture2D)],
'1232218': ['resources/grossini', cc.js._getClassId(TestSprite), 1], // sprite in texture
'123200': ['resources/grossini', cc.js._getClassId(TestSprite), 1], // sprite in plist
'0000001': ['grossini/grossini.png', cc.js._getClassId(cc.Texture2D)],
'123201': ['grossini/grossini', cc.js._getClassId(TestSprite), 1],
'0000000': ['grossini.png', cc.js._getClassId(cc.Texture2D)],
'1232218': ['grossini', cc.js._getClassId(TestSprite), 1], // sprite in texture
'123200': ['grossini', cc.js._getClassId(TestSprite), 1], // sprite in plist
};
var options = {
libraryPath: assetDir + '/library',
Expand Down
3 changes: 0 additions & 3 deletions test/qunit/unit-es5/test-serialize-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ if (TestEditorExtends) {
'_skewY',
'_anchorPoint',
'_contentSize',
'tag',
'_name',
'_opacity',
'_color',
Expand All @@ -52,7 +51,6 @@ if (TestEditorExtends) {
'_active' : getRandomBool(),
'_anchorPoint' : cc.v2(getRandomDouble(), getRandomDouble()),
'_contentSize' : cc.size(getRandomDouble(), getRandomDouble()),
'tag' : getRandomInt(),
'_name' : nodeName,
'_opacity' : getSpecRandomInt(0, 256),
'_color' : cc.color(getSpecRandomInt(0, 256), getSpecRandomInt(0, 256), getSpecRandomInt(0, 256), getSpecRandomInt(0, 256)),
Expand All @@ -75,7 +73,6 @@ if (TestEditorExtends) {
ret._active = getRandomBool();
ret._anchorPoint = cc.v2(getRandomDouble(), getRandomDouble());
ret._contentSize = cc.size(getRandomDouble(), getRandomDouble());
ret.tag = getRandomInt();
ret._name = nodeName;
ret._opacity = getSpecRandomInt(0, 256);
ret._color = cc.color(getSpecRandomInt(0, 256), getSpecRandomInt(0, 256), getSpecRandomInt(0, 256), getSpecRandomInt(0, 256));
Expand Down
Loading

0 comments on commit 2a3a75e

Please sign in to comment.