Skip to content

Commit

Permalink
chore: add test for stale bundle bug (#730)
Browse files Browse the repository at this point in the history
Make sure the default config is free from the bug outlined in #705
  • Loading branch information
Noemi Rozpara authored Apr 29, 2020
1 parent cf90821 commit ab23740
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 additions & 0 deletions e2e/react_native_0_60x/__tests__/refresh.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import path from 'path';
import fs from 'fs';
import { installDeps } from '../../utils/common';
import { cleanup } from '../../utils/bundle';
import { Instance, startServer, stopServer } from '../../utils/server';
import fetch from 'node-fetch';

const PROJECT_FIXTURE = path.join(
__dirname,
'../../../fixtures',
'react_native_with_haul_0_60x'
);
const PROJECT_FIXTURE_MAIN = path.join(PROJECT_FIXTURE, 'App.js');

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));

const makeChangesToSource = (findPhrase, changeTo) => {
const appContents = fs.readFileSync(PROJECT_FIXTURE_MAIN).toString();
const replaceResult = appContents.replace(findPhrase, changeTo);
fs.writeFileSync(PROJECT_FIXTURE_MAIN, replaceResult);
};

describe('test bundle refresh on edit', () => {
const port = 8000;
let instance: Instance;

beforeAll(done => {
installDeps(PROJECT_FIXTURE);
instance = startServer(port, PROJECT_FIXTURE, undefined, done);
});
afterAll(() => {
stopServer(instance);
cleanup(PROJECT_FIXTURE);
makeChangesToSource('Avocado', 'Donut');
});

test('should return updated bundle', async () => {
const url = `http://localhost:${port}/index.android.bundle`;

let res = await fetch(url);
let bundle = await res.text();

expect(bundle).toMatch('Donut');

makeChangesToSource('Donut', 'Avocado');
await sleep(200);

res = await fetch(url);
bundle = await res.text();

expect(bundle).toMatch('Avocado');
expect(bundle).not.toMatch('Donut');
});
});
1 change: 1 addition & 0 deletions fixtures/react_native_with_haul_0_60x/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const App = () => {
<Text style={styles.sectionDescription}>
Read the docs to discover what to do next:
</Text>
<Text>Donut</Text>
</View>
<LearnMoreLinks />
</View>
Expand Down

0 comments on commit ab23740

Please sign in to comment.