From db4d56dd930b3dbde8f26fb5895496178ae90c56 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 19 Oct 2016 16:48:15 +0800 Subject: [PATCH 1/2] support es6 for testing engine-extends --- gulp/tasks/test.js | 46 +++++++++++++++++------- gulpfile.js | 6 ++-- test/qunit/unit/test-json-pack-unpack.js | 5 +++ 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/gulp/tasks/test.js b/gulp/tasks/test.js index 4a28e45025..d03a23b378 100644 --- a/gulp/tasks/test.js +++ b/gulp/tasks/test.js @@ -33,26 +33,48 @@ const Gulp = require('gulp'); const Fb = require('gulp-fb'); const Buffer = require('vinyl-buffer'); const HandleErrors = require('../util/handleErrors'); -const EventStream = require('event-stream'); +const Es = require('event-stream'); const Utils = require('./utils'); -exports.build = function (sourceFile, outputFile, callback) { - var jsEntryEditorExtends = '../editor/test-utils/engine-extends-entry.js'; - - if (Fs.existsSync(jsEntryEditorExtends)) { - sourceFile = [sourceFile, jsEntryEditorExtends] - } - - Utils.createBundler(sourceFile) +exports.build = function (sourceFile, outputFile, sourceFileForExtends, outputFileForExtends, callback) { + var engine = Utils.createBundler(sourceFile) .ignore('./bin/modular-cocos2d-cut.js') .bundle() .on('error', HandleErrors.handler) .pipe(HandleErrors()) .pipe(Source(Path.basename(outputFile))) .pipe(Buffer()) - .pipe(Gulp.dest(Path.dirname(outputFile))) - .on('end', callback); + .pipe(Gulp.dest(Path.dirname(outputFile))); + + if (Fs.existsSync(sourceFileForExtends)) { + var Babelify; + try { + Babelify = require('babelify'); + } catch (e) { + console.error('Please run "npm install babelify".'); + throw e; + } + var engineExtends = Utils.createBundler(sourceFileForExtends) + .ignore('./bin/modular-cocos2d-cut.js') + .transform(Babelify, { + presets: ["es2015"], + ast: false, + highlightCode: false, + sourceMaps: true, + compact: false + }) + .bundle() + .on('error', HandleErrors.handler) + .pipe(HandleErrors()) + .pipe(Source(Path.basename(outputFileForExtends))) + .pipe(Buffer()) + .pipe(Gulp.dest(Path.dirname(outputFileForExtends))); + Es.merge(engine, engineExtends).on('end', callback); + } + else { + engine.on('end', callback); + } }; exports.clean = function (list, callback) { @@ -63,7 +85,7 @@ exports.unit = function (outDir, libs, callback) { var title = 'Cocos2d-JS Test Suite'; if (Fs.existsSync('./bin/cocos2d-js-extends-for-test.js')) { libs.push('./bin/cocos2d-js-extends-for-test.js'); - title += ' (Editor Extends Included)' + title += ' (Editor Extends Included)'; } return Gulp.src('test/qunit/unit/**/*.js', { read: false, base: './' }) .pipe(Fb.toFileList()) diff --git a/gulpfile.js b/gulpfile.js index 3262a89ad5..0322b66f90 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -122,10 +122,12 @@ gulp.task('clean-test', function (done) { }); gulp.task('build-test', ['build-modular-cocos2d', 'clean-test'], function (done) { - Test.build('./index.js', './bin/cocos2d-js-for-test.js', done); + Test.build('./index.js', './bin/cocos2d-js-for-test.js', + '../editor/test-utils/engine-extends-entry.js','./bin/cocos2d-js-extends-for-test.js', + done); }); -gulp.task('unit-runner', [], function (done) { +gulp.task('unit-runner', ['build-test'], function (done) { Test.unit('./bin', [ './bin/cocos2d-js-for-test.js' ], done); diff --git a/test/qunit/unit/test-json-pack-unpack.js b/test/qunit/unit/test-json-pack-unpack.js index b202ce2684..878abd24a5 100644 --- a/test/qunit/unit/test-json-pack-unpack.js +++ b/test/qunit/unit/test-json-pack-unpack.js @@ -1,6 +1,11 @@ module('JSON packer/unpacker'); (function () { + + if (!TestEditorExtends) { + return; + } + var KEY1 = 'amitabha'; var JSON1 = { __born__: 1985, From ea90fb1da9291424928855491561ba4fee58845c Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 19 Oct 2016 16:49:13 +0800 Subject: [PATCH 2/2] remove loadingItem.deserializeInfo --- cocos2d/core/load-pipeline/uuid-loader.js | 3 ++- cocos2d/core/platform/CCAssetLibrary.js | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/load-pipeline/uuid-loader.js b/cocos2d/core/load-pipeline/uuid-loader.js index 77604f6f6d..d27d399b4c 100644 --- a/cocos2d/core/load-pipeline/uuid-loader.js +++ b/cocos2d/core/load-pipeline/uuid-loader.js @@ -210,7 +210,7 @@ function loadUuid (item, callback) { return Object; }; - var tdInfo = CC_JSB ? new cc.deserialize.Details() : (item.deserializeInfo || _tdInfo); + var tdInfo = CC_JSB ? new cc.deserialize.Details() : _tdInfo; var asset; try { @@ -221,6 +221,7 @@ function loadUuid (item, callback) { }); } catch (e) { + tdInfo.reset(); var err = CC_JSB ? (e + '\n' + e.stack) : e.stack; callback( new Error('Uuid Loader: Deserialize asset [' + item.id + '] failed : ' + err) ); return; diff --git a/cocos2d/core/platform/CCAssetLibrary.js b/cocos2d/core/platform/CCAssetLibrary.js index 4d06b9a20b..d62ab80a52 100644 --- a/cocos2d/core/platform/CCAssetLibrary.js +++ b/cocos2d/core/platform/CCAssetLibrary.js @@ -63,8 +63,6 @@ var AssetLibrary = { * @param {Boolean} options.readMainCache - Default is true. If false, the asset and all its depends assets will reload and create new instances from library. * @param {Boolean} options.writeMainCache - Default is true. If true, the result will cache to AssetLibrary, and MUST be unload by user manually. * @param {Asset} options.existingAsset - load to existing asset, this argument is only available in editor - * @param {deserialize.Details} options.deserializeInfo - specified a DeserializeInfo object if you want, - * this parameter is only available in editor. * @private */ loadAsset: function (uuid, callback, options) { @@ -77,9 +75,6 @@ var AssetLibrary = { id: uuid, type: 'uuid' }; - if (options && options.deserializeInfo) { - item.deserializeInfo = options.deserializeInfo; - } if (options && options.existingAsset) { item.existingAsset = options.existingAsset; }