Skip to content

Commit

Permalink
Fix HMR plugin on the OpenSource React Native transformer
Browse files Browse the repository at this point in the history
Summary: This fixes facebook/react-native#21490

Reviewed By: jeanlauliac

Differential Revision: D10216508

fbshipit-source-id: d857918e281e0d1c02644bb7fcbe201026d2224a
  • Loading branch information
rafeca authored and facebook-github-bot committed Oct 5, 2018
1 parent a3dec63 commit e595178
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should create a server 1`] = `
exports[`Metro development server serves bundles via HTTP should serve deveopment bundles 1`] = `
Object {
"Bar": Object {
"foo": "foo",
"type": "bar",
},
"Foo": Object {
"asset": Object {
"__packager_asset": true,
"hash": "77d45c1f7fa73c0f6c444a830dc42f67",
"height": 8,
"httpServerLocation": "/assets",
"name": "test",
"scales": Array [
1,
],
"type": "png",
"width": 8,
},
"type": "foo",
},
"TypeScript": Object {
"B": [Function],
"test": true,
"type": "TypeScript",
},
}
`;

exports[`Metro development server serves bundles via HTTP should serve production bundles 1`] = `
Object {
"Bar": Object {
"foo": "foo",
Expand Down
52 changes: 37 additions & 15 deletions packages/metro/src/integration_tests/__tests__/server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,55 @@ jest.unmock('cosmiconfig');

jasmine.DEFAULT_TIMEOUT_INTERVAL = 60 * 1000;

it('should create a server', async () => {
const config = await Metro.loadConfig({
config: require.resolve('../metro.config.js'),
});

const httpServer = await Metro.runServer(config, {
reporter: {update() {}},
});
describe('Metro development server serves bundles via HTTP', () => {
let config;
let httpServer;

try {
async function downloadAndExec(path: string): mixed {
const response = await fetch(
`http://localhost:${
config.server.port
}/TestBundle.bundle?platform=ios&dev=false&minify=true`,
'http://localhost:' + config.server.port + path,
);

const body = await response.text();

if (!response.ok) {
console.error(body);

throw new Error(
'Metro server responded with status code: ' + response.status,
);
}

expect(execBundle(body)).toMatchSnapshot();
} finally {
httpServer.close();
return execBundle(body);
}

beforeEach(async () => {
config = await Metro.loadConfig({
config: require.resolve('../metro.config.js'),
});

httpServer = await Metro.runServer(config, {
reporter: {update() {}},
});
});

afterEach(() => {
httpServer.close();
});

it('should serve deveopment bundles', async () => {
expect(
await downloadAndExec(
'/TestBundle.bundle?platform=ios&dev=true&minify=false',
),
).toMatchSnapshot();
});

it('should serve production bundles', async () => {
expect(
await downloadAndExec(
'/TestBundle.bundle?platform=ios&dev=false&minify=true',
),
).toMatchSnapshot();
});
});
5 changes: 4 additions & 1 deletion packages/metro/src/reactNativeTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ function buildBabelConfig(filename, options, plugins?: BabelPlugins = []) {
config.plugins = extraPlugins.concat(config.plugins, plugins);

if (options.dev && options.hot) {
const hmrConfig = makeHMRConfig(options, filename);
const hmrConfig = makeHMRConfig(
options,
path.resolve(options.projectRoot, filename),
);
config = Object.assign({}, config, hmrConfig);
}

Expand Down

0 comments on commit e595178

Please sign in to comment.