From 676c1c3a450e39c6e72a4672ee4dcfee2fe7dbcf Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Fri, 11 Sep 2015 13:26:28 -0700 Subject: [PATCH] Fix server tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @​public Invoking an extra promise caused failures in the promise-based tests. This fixes them. Reviewed By: @vjeux Differential Revision: D2432431 --- .../src/Server/__tests__/Server-test.js | 69 ++++++++++--------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/react-packager/src/Server/__tests__/Server-test.js b/react-packager/src/Server/__tests__/Server-test.js index af7542c7..7d0c20a6 100644 --- a/react-packager/src/Server/__tests__/Server-test.js +++ b/react-packager/src/Server/__tests__/Server-test.js @@ -155,7 +155,7 @@ describe('processRequest', () => { }); }); - pit('rebuilds the bundles that contain a file when that file is changed', () => { + it('rebuilds the bundles that contain a file when that file is changed', () => { const bundleFunc = jest.genMockFunction(); bundleFunc .mockReturnValueOnce( @@ -178,21 +178,25 @@ describe('processRequest', () => { requestHandler = server.processRequest.bind(server); - return makeRequest(requestHandler, 'mybundle.bundle?runModule=true') - .then(response => { + makeRequest(requestHandler, 'mybundle.bundle?runModule=true') + .done(response => { expect(response).toEqual('this is the first source'); expect(bundleFunc.mock.calls.length).toBe(1); - triggerFileChange('all','path/file.js', options.projectRoots[0]); - jest.runAllTimers(); - jest.runAllTimers(); - }) - .then(() => { - expect(bundleFunc.mock.calls.length).toBe(2); - return makeRequest(requestHandler, 'mybundle.bundle?runModule=true') - .then(response => - expect(response).toEqual('this is the rebuilt source') - ); }); + + jest.runAllTicks(); + + triggerFileChange('all','path/file.js', options.projectRoots[0]); + jest.runAllTimers(); + jest.runAllTicks(); + + expect(bundleFunc.mock.calls.length).toBe(2); + + makeRequest(requestHandler, 'mybundle.bundle?runModule=true') + .done(response => + expect(response).toEqual('this is the rebuilt source') + ); + jest.runAllTicks(); }); }); @@ -259,30 +263,33 @@ describe('processRequest', () => { }); describe('buildbundle(options)', () => { - it('Calls the bundler with the correct args', () => { - server.buildBundle({ + pit('Calls the bundler with the correct args', () => { + return server.buildBundle({ entryFile: 'foo file' - }); - expect(Bundler.prototype.bundle).toBeCalledWith( - 'foo file', - true, - undefined, - true, - undefined + }).then(() => + expect(Bundler.prototype.bundle).toBeCalledWith( + 'foo file', + true, + undefined, + true, + undefined + ) ); }); }); describe('buildBundleFromUrl(options)', () => { - it('Calls the bundler with the correct args', () => { - server.buildBundleFromUrl('/path/to/foo.bundle?dev=false&runModule=false'); - expect(Bundler.prototype.bundle).toBeCalledWith( - 'path/to/foo.js', - false, - '/path/to/foo.map?dev=false&runModule=false', - false, - undefined - ); + pit('Calls the bundler with the correct args', () => { + return server.buildBundleFromUrl('/path/to/foo.bundle?dev=false&runModule=false') + .then(() => + expect(Bundler.prototype.bundle).toBeCalledWith( + 'path/to/foo.js', + false, + '/path/to/foo.map?dev=false&runModule=false', + false, + undefined + ) + ); }); }); });