-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a more sophisticated template for end-to-end testing. #1187
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1a6736f
Use a more sophisticated template for end-to-end testing.
wdhorton f551a37
Not publish integration tests to npm
3b07599
Use "commander" for cli argv handling
6b16b80
Handle different scripts version forms and exits without a name given
a5979af
Prepare the commands for testing with a template
07476b9
Fix dev "template" path
4f9be9c
Add various features to test
63f71cf
Test various features separately
0db6de9
Test language features
e142b7c
Comment unused e2e.sh lines
9c9edd3
Add "development" tests
3b609bd
Test environment variables
b869df0
Test webpack plugins
101e3e2
Replace kitchensink README
f43252a
Switch integration tests from jest to mocha
EnoahNetzach 4c80379
Use `fs-extra`
EnoahNetzach ebca9e6
Use the correct folders
EnoahNetzach b35516b
Do some cleanup
EnoahNetzach cd6420c
Print a better message for `--template`
EnoahNetzach aeebbdb
Test `npm start` with and without https
EnoahNetzach c5805c2
Separate fast e2e testing from kitchensink testing
EnoahNetzach bc9edfa
Hide `--internal-testing-template` (former `--template`) CLI option
EnoahNetzach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/fixtures |
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,3 @@ | ||
{ | ||
"presets": ["latest"] | ||
} |
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 @@ | ||
REACT_APP_FILE_ENV_MESSAGE=fromtheenvfile |
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,8 @@ | ||
[ignore] | ||
<PROJECT_ROOT>/node_modules/fbjs/.* | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[options] |
10 changes: 10 additions & 0 deletions
10
packages/react-scripts/fixtures/kitchensink/.template.dependencies.json
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,10 @@ | ||
{ | ||
"dependencies": { | ||
"babel-preset-latest": "6.16.0", | ||
"babel-register": "6.18.0", | ||
"babel-polyfill": "6.20.0", | ||
"chai": "3.5.0", | ||
"jsdom": "9.8.3", | ||
"mocha": "3.2.0" | ||
} | ||
} |
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,15 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
|
||
# testing | ||
coverage | ||
|
||
# production | ||
build | ||
|
||
# misc | ||
.DS_Store | ||
.env | ||
npm-debug.log |
24 changes: 24 additions & 0 deletions
24
packages/react-scripts/fixtures/kitchensink/integration/env.test.js
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,24 @@ | ||
import { expect } from 'chai' | ||
import initDOM from './initDOM' | ||
|
||
describe('Integration', () => { | ||
describe('Environment variables', () => { | ||
it('NODE_PATH', async () => { | ||
const doc = await initDOM('node-path') | ||
|
||
expect(doc.getElementById('feature-node-path').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('shell env variables', async () => { | ||
const doc = await initDOM('shell-env-variables') | ||
|
||
expect(doc.getElementById('feature-shell-env-variables').textContent).to.equal('fromtheshell.') | ||
}) | ||
|
||
it('file env variables', async () => { | ||
const doc = await initDOM('file-env-variables') | ||
|
||
expect(doc.getElementById('feature-file-env-variables').textContent).to.equal('fromtheenvfile.') | ||
}) | ||
}) | ||
}) |
62 changes: 62 additions & 0 deletions
62
packages/react-scripts/fixtures/kitchensink/integration/initDOM.js
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,62 @@ | ||
const fs = require('fs') | ||
const http = require('http') | ||
const jsdom = require('jsdom') | ||
const path = require('path') | ||
|
||
let getMarkup | ||
let resourceLoader | ||
// this value could be tweaked in order to let the resource | ||
// retriever get every file and jsdom execute react | ||
let timeToWaitForJsToExecute | ||
|
||
if (process.env.E2E_FILE) { | ||
const file = path.isAbsolute(process.env.E2E_FILE) | ||
? process.env.E2E_FILE | ||
: path.join(process.cwd(), process.env.E2E_FILE) | ||
|
||
const markup = fs.readFileSync(file, 'utf8') | ||
getMarkup = () => markup | ||
|
||
resourceLoader = (resource, callback) => callback( | ||
null, | ||
fs.readFileSync(path.join(path.dirname(file), resource.url.pathname), 'utf8') | ||
) | ||
|
||
timeToWaitForJsToExecute = 0 | ||
} else if (process.env.E2E_URL) { | ||
getMarkup = () => new Promise(resolve => { | ||
http.get(process.env.E2E_URL, (res) => { | ||
let rawData = '' | ||
res.on('data', chunk => rawData += chunk) | ||
res.on('end', () => resolve(rawData)) | ||
}) | ||
}) | ||
|
||
resourceLoader = (resource, callback) => { | ||
return resource.defaultFetch(callback) | ||
} | ||
|
||
timeToWaitForJsToExecute = 100 | ||
} else { | ||
it.only('can run jsdom (at least one of "E2E_FILE" or "E2E_URL" environment variables must be provided)', () => { | ||
expect(new Error('This isn\'t the error you are looking for.')).toBeUndefined() | ||
}) | ||
} | ||
|
||
export default feature => new Promise(async resolve => { | ||
const markup = await getMarkup() | ||
const host = process.env.E2E_URL || 'http://localhost:3000' | ||
const doc = jsdom.jsdom(markup, { | ||
features : { | ||
FetchExternalResources : ['script', 'css'], | ||
ProcessExternalResources : ['script'], | ||
}, | ||
resourceLoader, | ||
url: `${host}#${feature}`, | ||
virtualConsole: jsdom.createVirtualConsole().sendTo(console), | ||
}) | ||
|
||
doc.defaultView.addEventListener('load', () => { | ||
setTimeout(() => resolve(doc), timeToWaitForJsToExecute) | ||
}, false) | ||
}) |
96 changes: 96 additions & 0 deletions
96
packages/react-scripts/fixtures/kitchensink/integration/syntax.test.js
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,96 @@ | ||
import { expect } from 'chai' | ||
import initDOM from './initDOM' | ||
|
||
describe('Integration', () => { | ||
describe('Language syntax', () => { | ||
it('array destructuring', async () => { | ||
const doc = await initDOM('array-destructuring') | ||
|
||
expect(doc.getElementById('feature-array-destructuring').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('array spread', async () => { | ||
const doc = await initDOM('array-spread') | ||
|
||
expect(doc.getElementById('feature-array-spread').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('async/await', async () => { | ||
const doc = await initDOM('async-await') | ||
|
||
expect(doc.getElementById('feature-async-await').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('class properties', async () => { | ||
const doc = await initDOM('class-properties') | ||
|
||
expect(doc.getElementById('feature-class-properties').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('computed properties', async () => { | ||
const doc = await initDOM('computed-properties') | ||
|
||
expect(doc.getElementById('feature-computed-properties').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('custom interpolation', async () => { | ||
const doc = await initDOM('custom-interpolation') | ||
|
||
expect(doc.getElementById('feature-custom-interpolation').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('default parameters', async () => { | ||
const doc = await initDOM('default-parameters') | ||
|
||
expect(doc.getElementById('feature-default-parameters').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('destructuring and await', async () => { | ||
const doc = await initDOM('destructuring-and-await') | ||
|
||
expect(doc.getElementById('feature-destructuring-and-await').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('generators', async () => { | ||
const doc = await initDOM('generators') | ||
|
||
expect(doc.getElementById('feature-generators').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('object destructuring', async () => { | ||
const doc = await initDOM('object-destructuring') | ||
|
||
expect(doc.getElementById('feature-object-destructuring').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('object spread', async () => { | ||
const doc = await initDOM('object-spread') | ||
|
||
expect(doc.getElementById('feature-object-spread').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('promises', async () => { | ||
const doc = await initDOM('promises') | ||
|
||
expect(doc.getElementById('feature-promises').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('rest + default', async () => { | ||
const doc = await initDOM('rest-and-default') | ||
|
||
expect(doc.getElementById('feature-rest-and-default').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('rest parameters', async () => { | ||
const doc = await initDOM('rest-parameters') | ||
|
||
expect(doc.getElementById('feature-rest-parameters').childElementCount).to.equal(4) | ||
}) | ||
|
||
it('template interpolation', async () => { | ||
const doc = await initDOM('template-interpolation') | ||
|
||
expect(doc.getElementById('feature-template-interpolation').childElementCount).to.equal(4) | ||
}) | ||
}) | ||
}) |
44 changes: 44 additions & 0 deletions
44
packages/react-scripts/fixtures/kitchensink/integration/webpack.test.js
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,44 @@ | ||
import { expect } from 'chai' | ||
import initDOM from './initDOM' | ||
|
||
describe('Integration', () => { | ||
describe('Webpack plugins', () => { | ||
it('css inclusion', async () => { | ||
const doc = await initDOM('css-inclusion') | ||
|
||
expect(doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')) | ||
.to.match(/#feature-css-inclusion\{background:.+;color:.+}/) | ||
}) | ||
|
||
it('image inclusion', async () => { | ||
const doc = await initDOM('image-inclusion') | ||
|
||
expect(doc.getElementById('feature-image-inclusion').src).to.match(/^data:image\/jpeg;base64.+==$/) | ||
}) | ||
|
||
it('no ext inclusion', async () => { | ||
const doc = await initDOM('no-ext-inclusion') | ||
|
||
expect(doc.getElementById('feature-no-ext-inclusion').textContent) | ||
.to.equal('This is just a file without an extension.') | ||
}) | ||
|
||
it('json inclusion', async () => { | ||
const doc = await initDOM('json-inclusion') | ||
|
||
expect(doc.getElementById('feature-json-inclusion').textContent).to.equal('This is an abstract.') | ||
}) | ||
|
||
it('svg inclusion', async () => { | ||
const doc = await initDOM('svg-inclusion') | ||
|
||
expect(doc.getElementById('feature-svg-inclusion').src).to.match(/\/static\/media\/logo\..+\.svg$/) | ||
}) | ||
|
||
it('unknown ext inclusion', async () => { | ||
const doc = await initDOM('unknown-ext-inclusion') | ||
|
||
expect(doc.getElementById('feature-unknown-ext-inclusion').textContent).to.equal('Whoooo, spooky!.') | ||
}) | ||
}) | ||
}) |
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
packages/react-scripts/fixtures/kitchensink/public/index.html
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,12 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to
'--template <path-to-template>', 'use a non-standard application template'
.