Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/components/BrowserTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React, { Component } from 'react'
import { Button } from 'stardust'
import autobind from 'autobind-decorator'

import browserTest from '../content/lib/browser/runBrowserTest'

const initialState = { status: null, err: null, stdout: null, stderr: null }

export default class BrowserTests extends Component {
state = initialState

@autobind
testYahoo() {
this.setState({ ...initialState, status: '...running' })

browserTest('yahoo')
.then(res => {
this.setState({ ...res, status: 'passed' })
})
.catch(err => {
this.setState({ ...err, status: 'failed' })
})
}

render() {
return (
<div>
<Button onClick={this.testYahoo}>Test Yahoo</Button>
<pre>{JSON.stringify(this.state, null, 2)}</pre>
</div>
)
}
}
3 changes: 3 additions & 0 deletions app/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export default class App extends Component {
<Link className='item' to='/assignments'>
Assignments
</Link>
<Link className='item' to='/browser-tests'>
Browser Tests
</Link>
<Link className='item' to='/profile'>
Profile
</Link>
Expand Down
10 changes: 10 additions & 0 deletions app/containers/BrowserTestsPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { Component } from 'react'
import BrowserTests from '../components/BrowserTests'

export default class AssignmentsPage extends Component {
render() {
return (
<BrowserTests />
)
}
}
14 changes: 14 additions & 0 deletions app/content/lib/browser/runBrowserTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cp from 'child_process'
import Promise from 'bluebird'

const runNightmare = (testPath) => new Promise((resolve, reject) => {
cp.execFile(`node`, [`app/content/lib/browser/${testPath}.js`], (err, stdout, stderr) => {
if (err) {
reject({ err, stdout, stderr })
} else {
resolve({ err, stdout, stderr })
}
})
})

export default runNightmare
11 changes: 11 additions & 0 deletions app/content/lib/browser/yahoo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Nightmare from 'nightmare'
const nightmare = Nightmare({ show: true })

nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('#uh-search-button')
.wait('#main')
.evaluate(() => document.querySelector('#main .searchCenterMiddle li a').href)
.end()
.then((x) => console.log(x))
2 changes: 2 additions & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import App from './containers/App'
import HomePage from './containers/HomePage'
import CounterPage from './containers/CounterPage'
import AssignmentsPage from './containers/AssignmentsPage'
import BrowserTestsPage from './containers/BrowserTestsPage'
import ProfilePage from './containers/ProfilePage'

export default (
<Route path='/' component={App}>
<IndexRoute component={HomePage} />
<Route path='/counter' component={CounterPage} />
<Route path='/assignments' component={AssignmentsPage} />
<Route path='/browser-tests' component={BrowserTestsPage} />
<Route path='/profile' component={ProfilePage} />
</Route>
)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"highlight.js": "^9.2.0",
"invariant": "^2.2.0",
"jquery": "^2.2.1",
"nightmare": "^2.2.0",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react-markdown": "^2.1.0",
Expand Down