mirror of
https://github.com/status-im/metro.git
synced 2025-01-14 04:54:27 +00:00
metro-bundler: upgrade jest to 20.1
Summary: This put it on par with the version we use on other projects. This new version breaks assumptions about the way Promise/ticks/timers use to work, and I was not able to make it work properly synchronously. Since it's fragile anyway (because rely on Promise and feature internals), I propose the switch to async as done in this changeset. If `res.end` is not called, tests will just timeout instead. Reviewed By: cpojer Differential Revision: D5423823 fbshipit-source-id: 015e808a2cf2b8297a36b16feeb811a6e745a835
This commit is contained in:
parent
2ee051599a
commit
4399621d36
@ -26,7 +26,7 @@
|
|||||||
"glob": "^7.1.1",
|
"glob": "^7.1.1",
|
||||||
"istanbul-api": "^1.1.0",
|
"istanbul-api": "^1.1.0",
|
||||||
"istanbul-lib-coverage": "^1.0.0",
|
"istanbul-lib-coverage": "^1.0.0",
|
||||||
"jest": "^19.0.2",
|
"jest": "20.1.0-chi.1",
|
||||||
"lerna": "^2.0.0-rc.5",
|
"lerna": "^2.0.0-rc.5",
|
||||||
"micromatch": "^2.3.11",
|
"micromatch": "^2.3.11",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
jest.mock('../../worker-farm', () => () => () => {})
|
jest.mock('../../worker-farm', () => () => () => {})
|
||||||
.mock('worker-farm', () => () => () => {})
|
.mock('worker-farm', () => () => () => {})
|
||||||
.mock('timers', () => ({setImmediate: fn => setTimeout(fn, 0)}))
|
|
||||||
.mock('uglify-js')
|
.mock('uglify-js')
|
||||||
.mock('crypto')
|
.mock('crypto')
|
||||||
.mock(
|
.mock(
|
||||||
@ -25,13 +24,13 @@ jest.mock('../../worker-farm', () => () => () => {})
|
|||||||
.mock('../../lib/GlobalTransformCache');
|
.mock('../../lib/GlobalTransformCache');
|
||||||
|
|
||||||
describe('processRequest', () => {
|
describe('processRequest', () => {
|
||||||
let Bundler, Server, AssetServer, Promise, symbolicate;
|
let Bundler, Server, AssetServer, symbolicate;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
jest.useFakeTimers();
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
Bundler = require('../../Bundler');
|
Bundler = require('../../Bundler');
|
||||||
Server = require('../');
|
Server = require('../');
|
||||||
AssetServer = require('../../AssetServer');
|
AssetServer = require('../../AssetServer');
|
||||||
Promise = require('promise');
|
|
||||||
symbolicate = require('../symbolicate');
|
symbolicate = require('../symbolicate');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -339,11 +338,14 @@ describe('processRequest', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should hold on to request and inform on change', () => {
|
it('should hold on to request and inform on change', done => {
|
||||||
|
jest.useRealTimers();
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
server.onFileChange('all', options.projectRoots[0] + 'path/file.js');
|
server.onFileChange('all', options.projectRoots[0] + 'path/file.js');
|
||||||
jest.runAllTimers();
|
res.end.mockImplementation(value => {
|
||||||
expect(res.end).toBeCalledWith(JSON.stringify({changed: true}));
|
expect(value).toBe(JSON.stringify({changed: true}));
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not inform changes on disconnected clients', () => {
|
it('should not inform changes on disconnected clients', () => {
|
||||||
@ -357,30 +359,38 @@ describe('processRequest', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('/assets endpoint', () => {
|
describe('/assets endpoint', () => {
|
||||||
it('should serve simple case', () => {
|
beforeEach(() => {
|
||||||
|
jest.useRealTimers();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should serve simple case', done => {
|
||||||
const req = scaffoldReq({url: '/assets/imgs/a.png'});
|
const req = scaffoldReq({url: '/assets/imgs/a.png'});
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
res.end.mockImplementation(value => {
|
||||||
expect(res.end).toBeCalledWith('i am image');
|
expect(value).toBe('i am image');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should parse the platform option', () => {
|
it('should parse the platform option', done => {
|
||||||
const req = scaffoldReq({url: '/assets/imgs/a.png?platform=ios'});
|
const req = scaffoldReq({url: '/assets/imgs/a.png?platform=ios'});
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
res.end.mockImplementation(value => {
|
||||||
expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios');
|
expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios');
|
||||||
expect(res.end).toBeCalledWith('i am image');
|
expect(value).toBe('i am image');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should serve range request', () => {
|
it('should serve range request', done => {
|
||||||
const req = scaffoldReq({
|
const req = scaffoldReq({
|
||||||
url: '/assets/imgs/a.png?platform=ios',
|
url: '/assets/imgs/a.png?platform=ios',
|
||||||
headers: {range: 'bytes=0-3'},
|
headers: {range: 'bytes=0-3'},
|
||||||
@ -391,24 +401,28 @@ describe('processRequest', () => {
|
|||||||
AssetServer.prototype.get.mockImplementation(() => Promise.resolve(mockData));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve(mockData));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
res.end.mockImplementation(value => {
|
||||||
expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios');
|
expect(AssetServer.prototype.get).toBeCalledWith('imgs/a.png', 'ios');
|
||||||
expect(res.end).toBeCalledWith(mockData.slice(0, 4));
|
expect(value).toBe(mockData.slice(0, 4));
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should serve assets files\'s name contain non-latin letter', () => {
|
it('should serve assets files\'s name contain non-latin letter', done => {
|
||||||
const req = scaffoldReq({url: '/assets/imgs/%E4%B8%BB%E9%A1%B5/logo.png'});
|
const req = scaffoldReq({url: '/assets/imgs/%E4%B8%BB%E9%A1%B5/logo.png'});
|
||||||
const res = {end: jest.fn(), setHeader: jest.fn()};
|
const res = {end: jest.fn(), setHeader: jest.fn()};
|
||||||
|
|
||||||
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
AssetServer.prototype.get.mockImplementation(() => Promise.resolve('i am image'));
|
||||||
|
|
||||||
server.processRequest(req, res);
|
server.processRequest(req, res);
|
||||||
jest.runAllTimers();
|
res.end.mockImplementation(value => {
|
||||||
expect(AssetServer.prototype.get).toBeCalledWith(
|
expect(AssetServer.prototype.get).toBeCalledWith(
|
||||||
'imgs/\u{4E3B}\u{9875}/logo.png',
|
'imgs/\u{4E3B}\u{9875}/logo.png',
|
||||||
undefined
|
undefined
|
||||||
);
|
);
|
||||||
expect(res.end).toBeCalledWith('i am image');
|
expect(value).toBe('i am image');
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user