-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add test for stale bundle bug (#730)
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
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters