forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an Integration Test for the default Gatsby Wrappers
* Add `npm run setup` to setup symlinks for the test suite. * Add a note about `npm run setup` in CONTRIBUTING * Add `npm run test-integration` to run the slower tests.
- Loading branch information
Showing
15 changed files
with
192 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,6 @@ examples/blog/public/ | |
*.un~ | ||
dist | ||
bin/published.js | ||
|
||
# Build Path of Test Fixtures | ||
test/**/public |
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
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,41 @@ | ||
#!/usr/bin/env node | ||
|
||
var path = require('path') | ||
var fs = require('fs-extra') | ||
var Promise = require('bluebird') | ||
|
||
var mkdir = Promise.promisify(fs.mkdir) | ||
var symlink = Promise.promisify(fs.symlink) | ||
var readdir = Promise.promisify(fs.readdir) | ||
var remove = Promise.promisify(fs.remove) | ||
|
||
var nodeModulesDirectory = path.join(process.cwd(), 'node_modules') | ||
var gatsbyDirectory = path.join(nodeModulesDirectory, 'gatsby') | ||
var fixturesDirectory = path.join(process.cwd(), 'test', 'fixtures') | ||
|
||
function linkNodeModules (directory) { | ||
var fixtureNodeModules = path.join(fixturesDirectory, directory, 'node_modules') | ||
|
||
return remove(fixtureNodeModules) | ||
.then(() => symlink(nodeModulesDirectory, fixtureNodeModules)) | ||
} | ||
|
||
function linkGatsby () { | ||
var gatsbyPackagePath = path.join(process.cwd(), 'package.json') | ||
var gatsbyDistPath = path.join(process.cwd(), 'dist') | ||
var fixturePackagePath = path.join(gatsbyDirectory, 'package.json') | ||
var fixtureDistPath = path.join(gatsbyDirectory, 'dist') | ||
|
||
return remove(gatsbyDirectory) | ||
.then(() => mkdir(gatsbyDirectory)) | ||
.then(() => { | ||
return Promise.all([ | ||
symlink(gatsbyPackagePath, fixturePackagePath), | ||
symlink(gatsbyDistPath, fixtureDistPath) | ||
]) | ||
}) | ||
} | ||
|
||
linkGatsby() | ||
.then(() => readdir(fixturesDirectory)) | ||
.then(fixtures => fixtures.map(linkNodeModules)) |
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,14 @@ | ||
'use strict'; | ||
|
||
// This file is auto-written and used by Gatsby to require | ||
// files from your pages directory. | ||
module.exports = function (callback) { | ||
var context = require.context('./pages', true); | ||
if (module.hot) { | ||
module.hot.accept(context.id, function () { | ||
context = require.context('./pages', true); | ||
return callback(context); | ||
}); | ||
} | ||
return callback(context); | ||
}; |
Empty file.
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,29 @@ | ||
import React from 'react' | ||
import { prefixLink } from 'gatsby-helpers' | ||
|
||
module.exports = React.createClass({ | ||
displayName: 'HTML', | ||
propTypes: { | ||
body: React.PropTypes.string, | ||
}, | ||
render () { | ||
const { body } = this.props | ||
|
||
return ( | ||
<html lang="en"> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<meta httpEquiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0 maximum-scale=5.0" | ||
/> | ||
</head> | ||
<body className="landing-page"> | ||
<div id="react-mount" dangerouslySetInnerHTML={{ __html: body }} /> | ||
<script src={prefixLink('/bundle.js')} /> | ||
</body> | ||
</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,15 @@ | ||
import React from 'react' | ||
|
||
export default class Template extends React.Component { | ||
static get propTypes () { | ||
return { children: React.PropTypes.any } | ||
} | ||
|
||
render () { | ||
return ( | ||
<main> | ||
{this.props.children} | ||
</main> | ||
) | ||
} | ||
} |
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,2 @@ | ||
<h1>html</h1> | ||
<p>This is a page with the .html extension.</p> |
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 @@ | ||
--- | ||
--- | ||
# md | ||
|
||
This is a page with the .md extension. |
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,42 @@ | ||
import test from 'ava' | ||
import path from 'path' | ||
import Promise from 'bluebird' | ||
import fsExtra from 'fs-extra' | ||
import { exec, jsdom } from '../support' | ||
const fs = Promise.promisifyAll(fsExtra) | ||
|
||
const starterPath = path.resolve('../', 'fixtures', 'starter-wrappers') | ||
const buildPath = path.join(starterPath, 'public') | ||
|
||
test.serial('can build the starter', async t => { | ||
await fs.remove(buildPath) | ||
|
||
const exitCode = await exec('gatsby', ['build'], { cwd: starterPath }) | ||
const bundle = await fs.statAsync(path.join(buildPath, 'bundle.js')) | ||
|
||
t.is(exitCode, 0) | ||
t.truthy(bundle) | ||
}) | ||
|
||
test('html/index.html has an h1 that states file extention', async t => { | ||
const { document } = await jsdom(path.join(buildPath, 'html/index.html')) | ||
t.truthy(document) | ||
|
||
const heading = document.querySelector('h1') | ||
t.truthy(heading) | ||
|
||
const headingText = heading.textContent | ||
t.is(headingText, 'html') | ||
}) | ||
|
||
test('md/index.html has an h1 that states file extention', async t => { | ||
const { document } = await jsdom(path.join(buildPath, 'md/index.html')) | ||
t.truthy(document) | ||
|
||
// MD wrapper spits out an h1 tag. Shouldn't it be consistent with HTML | ||
const heading = document.querySelectorAll('h1')[1] | ||
t.truthy(heading) | ||
|
||
const headingText = heading.textContent | ||
t.is(headingText, 'md') | ||
}) |
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,18 @@ | ||
import jsdomlib from 'jsdom' | ||
import Promise from 'bluebird' | ||
import { spawn } from 'child_process' | ||
|
||
export function exec (command, args, options) { | ||
return new Promise((resolve, reject) => { | ||
const child = spawn(command, args, options) | ||
child.on('exit', code => resolve(code)) | ||
child.on('error', error => reject(error)) | ||
child.stdout.on('data', data => { console.log(data.toString()) }) | ||
child.stderr.on('data', data => { console.error(data.toString()) }) | ||
}) | ||
} | ||
|
||
export function jsdom (html) { | ||
const env = Promise.promisify(jsdomlib.env) | ||
return env(html) | ||
} |