-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add browser test for graphql (#5263)
- Loading branch information
Showing
13 changed files
with
178 additions
and
38 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
fixtures/browser/graphql-with-mjs/__snapshots__/index.test.js.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`graphql with mjs entrypoint correctly bundles files in development 1`] = `"Pikachu"`; | ||
|
||
exports[`graphql with mjs entrypoint correctly bundles files in production 1`] = `"Pikachu"`; |
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,56 @@ | ||
const { | ||
bootstrap, | ||
startDevelopmentServer, | ||
startProductionServer, | ||
} = require('../../utils'); | ||
const puppeteer = require('puppeteer'); | ||
|
||
beforeEach(async () => { | ||
await bootstrap({ directory: global.testDirectory, template: __dirname }); | ||
global.appDevPort = await startDevelopmentServer({ | ||
directory: global.testDirectory, | ||
}); | ||
global.appProdPort = await startProductionServer({ | ||
directory: global.testDirectory, | ||
}); | ||
// Wait for serve to boot up | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
}); | ||
|
||
// https://github.com/facebook/create-react-app/issues/5234 | ||
// https://github.com/facebook/create-react-app/pull/5258 | ||
describe('graphql with mjs entrypoint', () => { | ||
it('correctly bundles files in development', async () => { | ||
const browser = await puppeteer.launch({ headless: true }); | ||
try { | ||
const page = await browser.newPage(); | ||
await page.goto(`http://localhost:${global.appDevPort}/`); | ||
await page.waitForSelector('.Pokemon-Name-Data'); | ||
const output = await page.evaluate(() => { | ||
return Array.from( | ||
document.getElementsByClassName('Pokemon-Name-Data') | ||
).pop().innerHTML; | ||
}); | ||
expect(output).toMatchSnapshot(); | ||
} finally { | ||
browser.close(); | ||
} | ||
}); | ||
|
||
it('correctly bundles files in production', async () => { | ||
const browser = await puppeteer.launch({ headless: true }); | ||
try { | ||
const page = await browser.newPage(); | ||
await page.goto(`http://localhost:${global.appProdPort}/`); | ||
await page.waitForSelector('.Pokemon-Name-Data'); | ||
const output = await page.evaluate(() => { | ||
return Array.from( | ||
document.getElementsByClassName('Pokemon-Name-Data') | ||
).pop().innerHTML; | ||
}); | ||
expect(output).toMatchSnapshot(); | ||
} finally { | ||
browser.close(); | ||
} | ||
}); | ||
}); |
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
File renamed without changes.
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,63 @@ | ||
import React, { Component } from 'react'; | ||
import ApolloClient, { gql } from 'apollo-boost'; | ||
import { ApolloProvider, Query } from 'react-apollo'; | ||
|
||
const GET_PIKA = gql` | ||
{ | ||
pokemon(name: "Pikachu") { | ||
name | ||
} | ||
} | ||
`; | ||
|
||
const client = new ApolloClient({ | ||
uri: 'https://graphql-pokemon.now.sh/graphql', | ||
}); | ||
|
||
class Pokemon extends Component { | ||
render() { | ||
const { name } = this.props.pokemon; | ||
return ( | ||
<h1> | ||
Pokemon name: <span className="Pokemon-Name-Data">{name}</span> | ||
</h1> | ||
); | ||
} | ||
} | ||
|
||
class Data extends Component { | ||
state = {}; | ||
componentDidCatch() { | ||
this.setState({ hasError: true }); | ||
} | ||
render() { | ||
const { hasError } = this.state; | ||
return hasError ? ( | ||
<div className="Pokemon-Name-Data">Error :(</div> | ||
) : ( | ||
<Query query={GET_PIKA}> | ||
{({ loading, error, data }) => { | ||
if (loading) { | ||
return <div>Loading...</div>; | ||
} | ||
if (error) { | ||
return <div className="Pokemon-Name-Data">Error :(</div>; | ||
} | ||
return <Pokemon pokemon={data.pokemon} />; | ||
}} | ||
</Query> | ||
); | ||
} | ||
} | ||
|
||
class App extends Component { | ||
render() { | ||
return ( | ||
<ApolloProvider client={client}> | ||
<Data /> | ||
</ApolloProvider> | ||
); | ||
} | ||
} | ||
|
||
export default App; |
File renamed without changes.
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,7 @@ | ||
module.exports = { | ||
testEnvironment: 'node', | ||
testMatch: ['**/*.test.js'], | ||
testPathIgnorePatterns: ['/src/', 'node_modules'], | ||
setupTestFrameworkScriptFile: './setupBrowserTests.js', | ||
forceExit: true, | ||
}; |
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,9 @@ | ||
const fs = require('fs-extra'); | ||
const tempy = require('tempy'); | ||
beforeEach(() => { | ||
global.testDirectory = tempy.directory(); | ||
jest.setTimeout(1000 * 60 * 5); | ||
}); | ||
afterEach(() => { | ||
fs.removeSync(global.testDirectory); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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