-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mod: Use execa * mod: Connect IO to the front process by default * Test "yarn start" * "starts GraphiQL" should fail. Should downgrade express-graphql to 0.8.9. * Downgrade express-graphql for quick fix for #1822
- Loading branch information
1 parent
364cd04
commit 3477228
Showing
8 changed files
with
437 additions
and
41 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
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
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,79 @@ | ||
import assert from 'assert'; | ||
import path from 'path'; | ||
import { readFile, writeFile } from '../lib/fs'; | ||
import { | ||
killApp, | ||
waitApp, | ||
timeout, | ||
openBrowser, | ||
getUrl, | ||
} from '../lib/test-fns'; | ||
import { spawn } from '../lib/cp'; | ||
|
||
const startApp = (cwd, port) => | ||
spawn('yarn', ['start', '--silent'], { | ||
cwd, | ||
env: { PORT: String(port) }, | ||
}); | ||
|
||
describe('yarn start', () => { | ||
const port = 3033; | ||
const cwd = path.resolve(__dirname, '../..'); | ||
const app = startApp(cwd, port); | ||
let browser; | ||
let page; | ||
|
||
beforeAll(async () => { | ||
await waitApp(port); | ||
[browser, page] = await openBrowser(port); | ||
}, 60 * 1000); | ||
|
||
afterAll(async () => { | ||
await browser.close(); | ||
await killApp(app); | ||
}); | ||
|
||
it('launches the App', async () => { | ||
const expect = 'React.js News'; | ||
const actual = await page.$$eval('h1', es => es[1].textContent); | ||
assert.deepStrictEqual(actual, expect); | ||
}); | ||
|
||
it( | ||
'does Hot Module Reload', | ||
async () => { | ||
const sourcePath = 'src/routes/home/Home.js'; | ||
const sourceAbsPath = path.join(cwd, sourcePath); | ||
const expect = 'HMR!!!'; | ||
const defaultH1 = '<h1>React.js News</h1>'; | ||
const modifiedH1 = `<h1>${expect}</h1>`; | ||
|
||
const modifySource = async () => { | ||
const content = await readFile(sourceAbsPath); | ||
if (!content.includes(defaultH1)) | ||
throw new Error('This test cannot run. Check "defaultH1".'); | ||
await writeFile(sourceAbsPath, content.replace(defaultH1, modifiedH1)); | ||
}; | ||
|
||
const resetSource = async () => { | ||
const content = await readFile(sourceAbsPath); | ||
await writeFile(sourceAbsPath, content.replace(modifiedH1, defaultH1)); | ||
}; | ||
|
||
await modifySource(); | ||
await timeout(3 * 1000); | ||
const actual = await page.$$eval('h1', es => es[1].textContent); | ||
assert.deepStrictEqual(actual, expect); | ||
|
||
await resetSource(); | ||
}, | ||
30 * 1000, | ||
); | ||
|
||
it('starts GraphiQL', async () => { | ||
const expect = 'GraphiQL'; | ||
await page.goto(`${getUrl(port)}/graphql`); | ||
const actual = await page.$eval('.title', e => e.textContent); | ||
assert.deepStrictEqual(actual, expect); | ||
}); | ||
}); |
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
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
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,50 @@ | ||
import terminate from 'terminate'; | ||
import i from 'log-symbols'; | ||
import waitOn from 'wait-on'; | ||
import puppeteer from 'puppeteer'; | ||
|
||
export function success(...args) { | ||
return console.info(i.success, ...args); | ||
} | ||
|
||
export function info(...args) { | ||
return console.info(i.info, ...args); | ||
} | ||
|
||
export function getUrl(port) { | ||
return `http://localhost:${port}`; | ||
} | ||
|
||
export async function waitApp(port) { | ||
const url = getUrl(port); | ||
await waitOn({ | ||
resources: [url], | ||
timeout: 60 * 1000, | ||
}); | ||
} | ||
|
||
export async function killApp(app) { | ||
info(`Terminating app ${app.pid}...`); | ||
await new Promise((resolve, reject) => { | ||
terminate(app.pid, err => { | ||
if (err) return reject(err); | ||
return resolve(); | ||
}); | ||
}); | ||
success(`App ${app.pid} was terminated`); | ||
} | ||
|
||
export function timeout(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
export async function openBrowser(port) { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
page.on('pageerror', err => { | ||
throw new Error(`The page got an error: ${err}`); | ||
}); | ||
const url = getUrl(port); | ||
await page.goto(url); | ||
return [browser, page]; | ||
} |
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
Oops, something went wrong.