Skip to content

Upgrading Babel, Jest, fixing RN compat #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions babel-jest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const babelJest = require('babel-jest');

module.exports = babelJest.createTransformer({
presets: ['es2015', 'react', 'stage-2'],
plugins: [],
});
26 changes: 17 additions & 9 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ var uglify = require('gulp-uglify');
var BUILD = process.env.PARSE_BUILD || 'browser';
var VERSION = require('./package.json').version;

var PRESETS = {
'browser': ['es2015', 'react', 'stage-2'],
'node': ['es2015', 'react', 'stage-2'],
'react-native': ['react'],
};
var PLUGINS = {
'browser': ['inline-package-json', 'transform-inline-environment-variables', 'transform-runtime'],
'node': ['inline-package-json', 'transform-inline-environment-variables', 'transform-runtime'],
'react-native': ['inline-package-json', 'transform-inline-environment-variables'],
};

var DEV_HEADER = (
'/**\n' +
' * Parse JavaScript SDK v' + VERSION + '\n' +
Expand Down Expand Up @@ -42,15 +53,12 @@ gulp.task('compile', function() {
};
return gulp.src('src/*.js')
.pipe(babel({
experimental: true,
optional: [
'runtime',
'utility.inlineEnvironmentVariables'
],
plugins: [
'inline-package-json',
require('./vendor/babel-plugin-dead-code-elimination')
],
presets: PRESETS[BUILD],
plugins: PLUGINS[BUILD],
}))
// Second pass to kill BUILD-switched code
.pipe(babel({
plugins: ['minify-dead-code-elimination'],
}))
.pipe(gulp.dest(path.join('lib', BUILD)));
});
Expand Down
2 changes: 1 addition & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": {
"express": "^4.13.4",
"mocha": "^2.4.5",
"parse-server": "^2.1.1"
"parse-server": "2.2.17"
},
"scripts": {
"test": "mocha --reporter dot -t 5000"
Expand Down
21 changes: 14 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse",
"version": "1.9.1",
"version": "1.9.2",
"description": "The Parse JavaScript SDK",
"homepage": "https://www.parse.com",
"keywords": [
Expand Down Expand Up @@ -28,25 +28,31 @@
"react-native": false
},
"dependencies": {
"babel-runtime": "^5.8.20",
"babel-runtime": "^6.11.6",
"ws": "^1.0.1",
"xmlhttprequest": "^1.7.0"
},
"devDependencies": {
"babel-jest": "~5.3.0",
"babel-jest": "^15.0.0",
"babel-plugin-flow-comments": "^1.0.9",
"babel-plugin-inline-package-json": "~1.0.1",
"babel-plugin-inline-package-json": "~2.0.0",
"babel-plugin-minify-dead-code-elimination": "0.0.2",
"babel-plugin-transform-inline-environment-variables": "^6.8.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-2": "^6.13.0",
"browserify": "^11.0.1",
"codecov.io": "^0.1.6",
"gulp": "^3.9.0",
"gulp-babel": "^5.2.0",
"gulp-babel": "^6.1.2",
"gulp-derequire": "^2.1.0",
"gulp-insert": "^0.5.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^1.4.0",
"jasmine-reporters": "~1.0.0",
"jest-cli": "~0.5.0",
"jest-cli": "^15.1.1",
"vinyl-source-stream": "^1.1.0"
},
"scripts": {
Expand All @@ -55,6 +61,7 @@
"test": "PARSE_BUILD=node jest"
},
"jest": {
"automock": true,
"collectCoverage": true,
"testPathDirs": [
"src/"
Expand All @@ -63,7 +70,7 @@
"/node_modules/",
"/test_helpers/"
],
"scriptPreprocessor": "node_modules/babel-jest",
"scriptPreprocessor": "babel-jest.js",
"setupTestFrameworkScriptFile": "setup-jest.js"
}
}
3 changes: 0 additions & 3 deletions src/LiveQueryClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ export default class LiveQueryClient extends EventEmitter {
};

this.socket.onerror = (error) => {
console.log("error on socket");
this._handleWebSocketError(error);
};
}
Expand Down Expand Up @@ -440,8 +439,6 @@ export default class LiveQueryClient extends EventEmitter {

if (this.reconnectHandle) {
clearTimeout(this.reconnectHandle);
} else {
console.info('attempting to reconnect');
}

this.reconnectHandle = setTimeout((() => {
Expand Down
32 changes: 16 additions & 16 deletions src/Parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ Object.defineProperty(Parse, 'liveQueryServerURL', {
});
/** End setters **/

Parse.ACL = require('./ParseACL');
Parse.ACL = require('./ParseACL').default;
Parse.Analytics = require('./Analytics');
Parse.Cloud = require('./Cloud');
Parse.CoreManager = require('./CoreManager');
Parse.Config = require('./ParseConfig');
Parse.Error = require('./ParseError');
Parse.FacebookUtils = require('./FacebookUtils');
Parse.File = require('./ParseFile');
Parse.GeoPoint = require('./ParseGeoPoint');
Parse.Installation = require('./ParseInstallation');
Parse.Object = require('./ParseObject');
Parse.Config = require('./ParseConfig').default;
Parse.Error = require('./ParseError').default;
Parse.FacebookUtils = require('./FacebookUtils').default;
Parse.File = require('./ParseFile').default;
Parse.GeoPoint = require('./ParseGeoPoint').default;
Parse.Installation = require('./ParseInstallation').default;
Parse.Object = require('./ParseObject').default;
Parse.Op = {
Set: ParseOp.SetOp,
Unset: ParseOp.UnsetOp,
Expand All @@ -110,16 +110,16 @@ Parse.Op = {
AddUnique: ParseOp.AddUniqueOp,
Relation: ParseOp.RelationOp
};
Parse.Promise = require('./ParsePromise');
Parse.Promise = require('./ParsePromise').default;
Parse.Push = require('./Push');
Parse.Query = require('./ParseQuery');
Parse.Relation = require('./ParseRelation');
Parse.Role = require('./ParseRole');
Parse.Session = require('./ParseSession');
Parse.Query = require('./ParseQuery').default;
Parse.Relation = require('./ParseRelation').default;
Parse.Role = require('./ParseRole').default;
Parse.Session = require('./ParseSession').default;
Parse.Storage = require('./Storage');
Parse.User = require('./ParseUser');
Parse.LiveQuery = require('./ParseLiveQuery');
Parse.LiveQueryClient = require('./LiveQueryClient');
Parse.User = require('./ParseUser').default;
Parse.LiveQuery = require('./ParseLiveQuery').default;
Parse.LiveQueryClient = require('./LiveQueryClient').default;

Parse._request = function(...args) {
return CoreManager.getRESTController().request.apply(null, args);
Expand Down
2 changes: 1 addition & 1 deletion src/ParseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class ParseFile {
file: data,
type: specifiedType
};
} else if (data && typeof data.base64 !== 'undefined') {
} else if (data && typeof data.base64 === 'string') {
const base64 = data.base64;
var commaIndex = base64.indexOf(',');

Expand Down
4 changes: 2 additions & 2 deletions src/ParsePromise.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ export default class ParsePromise {
* @param {Function} continuation the callback.
*/
_continueWith(continuation) {
return this.then(function() {
return continuation(arguments, null);
return this.then(function(...args) {
return continuation(args, null);
}, function(error) {
return continuation(null, error);
});
Expand Down
4 changes: 3 additions & 1 deletion src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import ParsePromise from './ParsePromise';

import type { RequestOptions, FullOptions } from './RESTController';

type BatchOptions = FullOptions & { batchSize?: number };

export type WhereClause = {
[attr: string]: mixed;
};
Expand Down Expand Up @@ -407,7 +409,7 @@ export default class ParseQuery {
* @return {Parse.Promise} A promise that will be fulfilled once the
* iteration has completed.
*/
each(callback: (obj: ParseObject) => any, options?: FullOptions): ParsePromise {
each(callback: (obj: ParseObject) => any, options?: BatchOptions): ParsePromise {
options = options || {};

if (this._order || this._skip || (this._limit >= 0)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ParseUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default class ParseUser extends ParseObject {
});
},
error: (provider, error) => {
if (options.error) {
if (typeof options.error === 'function') {
options.error(this, error);
}
promise.reject(error);
Expand Down
3 changes: 2 additions & 1 deletion src/StorageController.react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*/

import ParsePromise from './ParsePromise';
import { AsyncStorage } from 'react-native';
// RN packager nonsense
import { AsyncStorage } from 'react-native/Libraries/react-native/react-native.js';

var StorageController = {
async: 1,
Expand Down
33 changes: 0 additions & 33 deletions src/__mocks__/react-native.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/__tests__/Analytics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jest.dontMock('../ParsePromise');

var Analytics = require('../Analytics');
var CoreManager = require('../CoreManager');
var ParsePromise = require('../ParsePromise');
var ParsePromise = require('../ParsePromise').default;

var defaultController = CoreManager.getAnalyticsController();

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Cloud-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.dontMock('../ParsePromise');

var Cloud = require('../Cloud');
var CoreManager = require('../CoreManager');
var ParsePromise = require('../ParsePromise');
var ParsePromise = require('../ParsePromise').default;

var defaultController = CoreManager.getCloudController();

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/Hooks-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.dontMock('../ParsePromise');

var Hooks = require('../ParseHooks');
var CoreManager = require('../CoreManager');
var ParsePromise = require('../ParsePromise');
var ParsePromise = require('../ParsePromise').default;

var defaultController = CoreManager.getHooksController();

Expand Down
14 changes: 6 additions & 8 deletions src/__tests__/InstallationController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ jest.dontMock('../InstallationController');
jest.dontMock('../ParsePromise');
jest.dontMock('../Storage');
jest.dontMock('../StorageController.default');
jest.dontMock('./test_helpers/asyncHelper');

var CoreManager = require('../CoreManager');
var InstallationController = require('../InstallationController');
var Storage = require('../Storage');
var asyncHelper = require('./test_helpers/asyncHelper');

describe('InstallationController', () => {
beforeEach(() => {
Expand All @@ -27,15 +25,15 @@ describe('InstallationController', () => {
InstallationController._clearCache();
});

it('generates a new installation id when there is none', asyncHelper((done) => {
it('generates a new installation id when there is none', (done) => {
InstallationController.currentInstallationId().then((iid) => {
expect(typeof iid).toBe('string');
expect(iid.length).toBeGreaterThan(0);
done();
});
}));
});

it('caches the installation id', asyncHelper((done) => {
it('caches the installation id', (done) => {
var iid = null;
InstallationController.currentInstallationId().then((i) => {
iid = i;
Expand All @@ -45,9 +43,9 @@ describe('InstallationController', () => {
expect(i).toBe(iid);
done();
});
}));
});

it('permanently stores the installation id', asyncHelper((done) => {
it('permanently stores the installation id', (done) => {
var iid = null;
InstallationController.currentInstallationId().then((i) => {
iid = i;
Expand All @@ -57,5 +55,5 @@ describe('InstallationController', () => {
expect(i).toBe(iid);
done();
});
}));
});
});
7 changes: 4 additions & 3 deletions src/__tests__/LiveQueryClient-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ jest.dontMock('../unsavedChildren');
jest.dontMock('../ParseACL');
jest.dontMock('../ParseQuery');
jest.dontMock('../LiveQuerySubscription');
jest.useFakeTimers();

var LiveQueryClient = require('../LiveQueryClient');
var ParseObject = require('../ParseObject');
var ParseQuery = require('../ParseQuery');
var LiveQueryClient = require('../LiveQueryClient').default;
var ParseObject = require('../ParseObject').default;
var ParseQuery = require('../ParseQuery').default;
var events = require('events');

describe('LiveQueryClient', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/ParseACL-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ mockRole.prototype.getName = function() {
}
jest.setMock('../ParseRole', mockRole);

var ParseACL = require('../ParseACL');
var ParseUser = require('../ParseUser');
var ParseACL = require('../ParseACL').default;
var ParseUser = require('../ParseUser').default;
var ParseRole = require('../ParseRole');

describe('ParseACL', () => {
Expand Down
Loading