diff --git a/cocos2d/core/components/CCComponent.js b/cocos2d/core/components/CCComponent.js index c320999af9..30e45e7da8 100644 --- a/cocos2d/core/components/CCComponent.js +++ b/cocos2d/core/components/CCComponent.js @@ -155,7 +155,7 @@ var _callLateUpdate = CC_EDITOR ? function (event) { // Yes, the id might have a conflict problem once every 365 days // if the game runs at 60 FPS and each frame 4760273 counts of new HashObject's id are requested. var CompId = 0; -var IdPrefix = CC_DEV && ('Comp' + Editor.NonUuidMark); +var IdPrefix = CC_DEV && ('Comp' + Editor.UuidUtils.NonUuidMark); var getNewId = CC_DEV && function () { return IdPrefix + (++CompId); }; @@ -175,8 +175,8 @@ var Component = cc.Class({ extends: cc.Object, ctor: function () { - if (CC_EDITOR) { - Editor._AssetsWatcher.initComponent(this); + if (CC_EDITOR && !CC_TEST) { + _Scene.AssetsWatcher.initComponent(this); } // dont reset _id when destroyed @@ -247,8 +247,8 @@ var Component = cc.Class({ get: function () {}, set: function (value) { if (this.__scriptUuid !== value) { - if (value && Editor.isUuid(value._uuid)) { - var classId = Editor.compressUuid(value._uuid); + if (value && Editor.UuidUtils.isUuid(value._uuid)) { + var classId = Editor.UuidUtils.compressUuid(value._uuid); var NewComp = cc.js._getClassById(classId); if (cc.isChildClassOf(NewComp, cc.Component)) { cc.warn('Sorry, replacing component script is not yet implemented.'); @@ -564,7 +564,7 @@ var Component = cc.Class({ callOnLostFocusInTryCatch(this); } } - Editor._AssetsWatcher.start(this); + _Scene.AssetsWatcher.start(this); } if (this._enabled) { @@ -604,7 +604,7 @@ var Component = cc.Class({ // onDestroy if (CC_EDITOR) { - Editor._AssetsWatcher.stop(this); + _Scene.AssetsWatcher.stop(this); if (cc.engine._isPlaying || this.constructor._executeInEditMode) { if (this.onDestroy) { callOnDestroyInTryCatch(this); diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index d21554528e..51272f533e 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -120,7 +120,7 @@ var AssetLibrary = { if (CC_EDITOR) { Editor.sendRequestToCore( 'scene:query-asset-info-by-uuid', uuid, function (info) { if (info) { - Editor.onRawAssetUsed(info.url, uuid); + Editor.UuidCache.cache(info.url, uuid); var ctor = Editor.assets[info.type]; if (ctor) { var isRawAsset = !cc.isChildClassOf(ctor, Asset); diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index 68f5941353..f640cd8124 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -417,7 +417,7 @@ function define (className, baseClasses, mixins, constructor, options) { JS._setClassId(uuid, cls); if (CC_EDITOR) { cc.Component._addMenuItem(cls, 'i18n:MAIN_MENU.component.scripts/' + className, -1); - cls.prototype.__scriptUuid = Editor.decompressUuid(uuid); + cls.prototype.__scriptUuid = Editor.UuidUtils.decompressUuid(uuid); } } frame.beh = cls; diff --git a/cocos2d/core/platform/utils.js b/cocos2d/core/platform/utils.js index fb34510757..67130ae479 100644 --- a/cocos2d/core/platform/utils.js +++ b/cocos2d/core/platform/utils.js @@ -77,10 +77,13 @@ if (CC_DEV) { if (CC_TEST) { // editor mocks using in unit tests if (typeof Editor === 'undefined') { - Editor = {}; + Editor = { + UuidUtils: { + NonUuidMark: '.', + uuid: function () { + return '' + ((new Date()).getTime() + Math.random()); + } + } + }; } - Editor.uuid = function () { - return '' + ((new Date()).getTime() + Math.random()); - }; - Editor.NonUuidMark = '.'; } diff --git a/cocos2d/core/sprites/CCSpriteFrame.js b/cocos2d/core/sprites/CCSpriteFrame.js index addb630055..c5f341cf10 100644 --- a/cocos2d/core/sprites/CCSpriteFrame.js +++ b/cocos2d/core/sprites/CCSpriteFrame.js @@ -494,7 +494,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{ uuid = url._uuid; } else { - uuid = Editor.urlToUuid(url); + uuid = Editor.UuidCache.urlToUuid(url); } } var capInsets = undefined; diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index f546d3a14d..693e069448 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -178,7 +178,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ */ uuid: { get: function () { - return this._id || (this._id = window.Editor ? Editor.uuid() : ''); + return this._id || (this._id = window.Editor ? Editor.UuidUtils.uuid() : ''); } }, diff --git a/gulpfile.js b/gulpfile.js index d1c5ef54ab..7f8ea49f26 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -33,7 +33,7 @@ paths = { test: { src: 'test/qunit/unit/**/*.js', runner: 'test/qunit/lib/qunit-runner.html', - jsEntryEditorExtends: '../editor/share/engine-extends/index.js', // only available in editor + jsEntryEditorExtends: '../editor/test-utils/engine-extends-entry.js', // only available in editor dest: 'bin/cocos2d-js-for-test.js', destEditorExtends: 'bin/cocos2d-js-extends-for-test.js' }, diff --git a/test/qunit/lib/polyfill-for-phantom.js b/test/qunit/lib/polyfill-for-phantom.js index 2612406315..9b0c82ac9c 100644 --- a/test/qunit/lib/polyfill-for-phantom.js +++ b/test/qunit/lib/polyfill-for-phantom.js @@ -61,4 +61,40 @@ if (isPhantomJS) { // polyfill var video = document.createElement("video"); video.constructor.prototype.canPlayType = function () { return ''; }; + + (function () { + var log = console.log; + console.log = function () { + var str = arguments[0]; + str = '' + str; + if (str && str.length > 110) { + log.call(console, "(Can not output this too long log)"); + } + else { + log.apply(console, arguments); + } + } + var warn = console.warn; + console.warn = function () { + var str = arguments[0]; + str = '' + str; + if (str && str.length > 110) { + warn.call(console, "(Can not output this too long warn)"); + } + else { + warn.apply(console, arguments); + } + } + var error = console.error; + console.error = function () { + var str = arguments[0]; + str = '' + str; + if (str && str.length > 110) { + error.call(console, "(Can not output this too long error)"); + } + else { + error.apply(console, arguments); + } + } + })(); } diff --git a/test/qunit/unit/_init.js b/test/qunit/unit/_init.js index 1c627e5738..f616ac39ae 100644 --- a/test/qunit/unit/_init.js +++ b/test/qunit/unit/_init.js @@ -125,6 +125,7 @@ Editor.log = cc.log; Editor.warn = cc.warn; Editor.error = cc.error; Editor.info = cc.info; +Editor.UuidCache = {}; var assetDir = '../test/qunit/assets'; diff --git a/test/qunit/unit/test-serialize.js b/test/qunit/unit/test-serialize.js index d39db6e6b0..4694d19200 100644 --- a/test/qunit/unit/test-serialize.js +++ b/test/qunit/unit/test-serialize.js @@ -385,8 +385,8 @@ } } }); - var restore = Editor.urlToUuid; - Editor.urlToUuid = function (url) { + var restore = Editor.UuidCache.urlToUuid; + Editor.UuidCache.urlToUuid = function (url) { return { foo: '01', bar: '02' @@ -412,7 +412,7 @@ }; deepEqual(actual, expected, 'could be serialized'); - Editor.urlToUuid = restore; + Editor.UuidCache.urlToUuid = restore; cc.js.unregisterClass(Data); });