From 2b32b08b13e879c2d4f8f53299c2048653fc62e9 Mon Sep 17 00:00:00 2001 From: Rafael Oleza Date: Tue, 27 Feb 2018 14:27:14 -0800 Subject: [PATCH] Pass the sourcemap variable correctly to the transformer Reviewed By: Hypuk Differential Revision: D7102063 fbshipit-source-id: b6162e6f9052099afec02a67e3ea44da2a6ea8be --- .../DeltaBundler/Serializers/Serializers.js | 5 +--- .../__tests__/Serializers-test.js | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/metro/src/DeltaBundler/Serializers/Serializers.js b/packages/metro/src/DeltaBundler/Serializers/Serializers.js index 67605224..5534ed77 100644 --- a/packages/metro/src/DeltaBundler/Serializers/Serializers.js +++ b/packages/metro/src/DeltaBundler/Serializers/Serializers.js @@ -135,10 +135,7 @@ async function _getAllModules( lastModified: Date, deltaTransformer: DeltaTransformer, }> { - const hashedOptions = options; - delete hashedOptions.sourceMapUrl; - - const clientId = '__SERVER__' + stableHash(hashedOptions).toString('hex'); + const clientId = '__SERVER__' + stableHash(options).toString('hex'); const deltaPatcher = DeltaPatcher.get(clientId); diff --git a/packages/metro/src/DeltaBundler/__tests__/Serializers-test.js b/packages/metro/src/DeltaBundler/__tests__/Serializers-test.js index 327895f4..b212bcbc 100644 --- a/packages/metro/src/DeltaBundler/__tests__/Serializers-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/Serializers-test.js @@ -50,12 +50,12 @@ describe('Serializers', () => { postProcessModules.mockImplementation(modules => modules); deltaBundler = { - async getDeltaTransformer() { - return { + getDeltaTransformer: jest.fn().mockReturnValue( + Promise.resolve({ getDelta, getDependenciesFn, - }; - }, + }), + ), getPostProcessModulesFn() { return postProcessModules; }, @@ -101,7 +101,11 @@ describe('Serializers', () => { }); it('should build the full JS bundle', async () => { - expect(await Serializers.fullBundle(deltaBundler, {})).toMatchSnapshot(); + expect( + await Serializers.fullBundle(deltaBundler, { + sourceMapUrl: 'http://localhost:8081/myBundle.js', + }), + ).toMatchSnapshot(); getDelta.mockReturnValueOnce( Promise.resolve({ @@ -121,6 +125,17 @@ describe('Serializers', () => { ).toMatchSnapshot(); }); + it('should pass the sourcemapURL param to the transformer', async () => { + await Serializers.fullBundle(deltaBundler, { + sourceMapUrl: 'http://localhost:8081/myBundle.js', + }); + + expect(deltaBundler.getDeltaTransformer.mock.calls[0][1]).toEqual({ + deltaBundleId: '1234', + sourceMapUrl: 'http://localhost:8081/myBundle.js', + }); + }); + // This test actually does not test the sourcemaps generation logic, which // is already tested in the source-map file. it('should build the full Source Maps', async () => {