├── public
├── favicon.ico
└── index.html
├── src
├── index.js
├── index.css
├── app.js
└── logo.svg
├── .gitignore
├── test
├── unit
│ └── app.test.js
├── acceptance
│ └── greeting.test.js
└── helpers
│ └── visit.js
├── scripts
└── test.sh
├── README.md
├── .circleci
└── config.yml
└── package.json
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vigetlabs/jest-with-nightmare/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import './index.css'
2 |
3 | import App from './app'
4 | import React from 'react'
5 | import ReactDOM from 'react-dom'
6 |
7 | ReactDOM.render(, document.getElementById('root'))
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | node_modules
5 |
6 | # testing
7 | coverage
8 |
9 | # production
10 | build
11 |
12 | # misc
13 | .DS_Store
14 | .env
15 | npm-debug.log
16 |
--------------------------------------------------------------------------------
/test/unit/app.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import App from '../../src/app'
3 | import {mount} from 'enzyme'
4 |
5 | test('welcomes the user to React', function () {
6 | const wrapper = mount()
7 |
8 | expect(wrapper.text()).toContain('Welcome to React')
9 | })
10 |
--------------------------------------------------------------------------------
/scripts/test.sh:
--------------------------------------------------------------------------------
1 | # This script is used by CircleCI to execute automated tests.
2 |
3 | # Build all assets
4 | yarn build
5 |
6 | # Switch to the build directory
7 | yarn pushstate-server build &
8 |
9 | # Save the PID of the server to a variable
10 | APP_TEST_PID=$(echo $!)
11 |
12 | # Execute tests
13 | PORT=9000 CI=true npm run test:all
14 |
15 | # Kill the server
16 | kill $APP_TEST_PID
17 |
--------------------------------------------------------------------------------
/test/acceptance/greeting.test.js:
--------------------------------------------------------------------------------
1 | import visit from '../helpers/visit'
2 |
3 | describe('When visiting the homepage', function () {
4 |
5 | test('it welcomes the user', async function () {
6 | let page = visit('/')
7 |
8 | let text = await page.evaluate(() => document.body.textContent)
9 | .end()
10 |
11 | expect(text).toContain('Welcome to React')
12 | })
13 |
14 | })
15 |
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: sans-serif;
5 | }
6 |
7 | .app {
8 | text-align: center;
9 | }
10 |
11 | .app-logo {
12 | animation: app-logo-spin infinite 20s linear;
13 | height: 80px;
14 | }
15 |
16 | .app-header {
17 | background-color: #222;
18 | height: 150px;
19 | padding: 20px;
20 | color: white;
21 | }
22 |
23 | .app-intro {
24 | font-size: large;
25 | }
26 |
27 | @keyframes app-logo-spin {
28 | from { transform: rotate(0deg); }
29 | to { transform: rotate(360deg); }
30 | }
31 |
--------------------------------------------------------------------------------
/test/helpers/visit.js:
--------------------------------------------------------------------------------
1 | import nightmare from 'nightmare'
2 | import url from 'url'
3 |
4 | const BASE_URL = url.format({
5 | protocol : process.env.PROTOCOL || 'http',
6 | hostname : process.env.HOST || 'localhost',
7 | port : process.env.PORT || 3000
8 | })
9 |
10 | const DEBUG = process.env.DEBUG || false
11 |
12 | export default function (path='', query={}) {
13 | const location = url.resolve(BASE_URL, path)
14 |
15 | const page = nightmare({
16 | show: DEBUG,
17 | pollInterval: 50
18 | })
19 |
20 | return page.goto(location)
21 | }
22 |
--------------------------------------------------------------------------------
/src/app.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import logo from './logo.svg'
3 |
4 | class App extends Component {
5 |
6 | render() {
7 | return (
8 |
9 |
10 |

11 |
Welcome to React
12 |
13 |
14 | To get started, edit src/App.js and save to reload.
15 |
16 |
17 | )
18 | }
19 |
20 | }
21 |
22 | export default App
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Jest with Nightmare
2 |
3 | [](https://circleci.com/gh/vigetlabs/jest-with-nightmare)
4 |
5 | ## Setup
6 |
7 | ```
8 | npm install
9 | ```
10 |
11 | This project also includes a `yarn.lock` file. Feel free to use that instead:
12 |
13 | ```
14 | brew install yarn
15 | yarn install
16 | ```
17 |
18 | ## Run unit tests
19 |
20 | ```
21 | npm test
22 | ```
23 |
24 | ## Run acceptance tests
25 |
26 | ```
27 | npm test:acceptance
28 | ```
29 |
30 | ## Run all tests
31 |
32 | ```
33 | npm test:all
34 | ```
35 |
--------------------------------------------------------------------------------
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | docker:
5 | - image: circleci/node:8-browsers
6 | working_directory: ~/repo
7 | steps:
8 | - checkout
9 | - restore_cache:
10 | name: "Restore Yarn Package Cache"
11 | keys:
12 | - yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }}
13 | - yarn-packages-{{ .Branch }}
14 | - yarn-packages-master
15 | - yarn-packages-
16 | - run:
17 | name: "Install Dependencies"
18 | command: yarn install
19 | - run:
20 | name: "Test"
21 | command: bash -e scripts/test.sh
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jest-with-nightmare",
3 | "version": "0.1.0",
4 | "private": true,
5 | "devDependencies": {
6 | "enzyme": "^2.5.1",
7 | "nightmare": "^2.7.0",
8 | "pushstate-server": "^3.0.1",
9 | "react-addons-test-utils": "^15.3.2",
10 | "react-scripts": "0.6.1"
11 | },
12 | "dependencies": {
13 | "react": "15.4.1",
14 | "react-dom": "15.4.1"
15 | },
16 | "scripts": {
17 | "start": "react-scripts start",
18 | "build": "react-scripts build",
19 | "test": "react-scripts test --env=jsdom test/unit",
20 | "test:acceptance": "react-scripts test --env=jsdom test/acceptance",
21 | "test:all": "react-scripts test --env=jsdom test",
22 | "test:cov": "react-scripts test --env=jsdom test --coverage"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 | React App
17 |
18 |
19 |
20 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------