forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integration test for the rewritePath function
* Also updates the `spawn` support function to reject a promise if given a non-zero exit code.
- Loading branch information
Showing
8 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
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,7 @@ | ||
exports.rewritePath = function rewritePath (parsedPath) { | ||
if (parsedPath.name === 'move-me') { | ||
return '/moved/' | ||
} else { | ||
return undefined | ||
} | ||
} |
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> | ||
<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,3 @@ | ||
--- | ||
--- | ||
# This will not be moved |
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 @@ | ||
--- | ||
--- | ||
# This will be moved |
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 test from 'ava' | ||
import path from 'path' | ||
import Promise from 'bluebird' | ||
import { spawn } from '../support' | ||
import fse from 'fs-extra' | ||
const fs = Promise.promisifyAll(fse) | ||
|
||
const fixturePath = path.resolve('../fixtures/path-rewrite') | ||
const buildPath = path.resolve(fixturePath, 'public') | ||
const gatsby = path.resolve('../../bin', 'gatsby.js') | ||
|
||
test.before('build the site', async () => { | ||
await fs.remove(buildPath) | ||
await spawn(gatsby, ['build'], { cwd: fixturePath }) | ||
}) | ||
|
||
test('the move-me file has been moved', async t => { | ||
const movedPath = path.resolve(buildPath, 'moved', 'index.html') | ||
const file = await fs.statAsync(movedPath) | ||
|
||
t.truthy(file) | ||
}) | ||
|
||
test('the dont-move-me file has not been moved', async t => { | ||
const dontMovePath = path.resolve(buildPath, 'dont-move-me', 'index.html') | ||
const file = await fs.statAsync(dontMovePath) | ||
|
||
t.truthy(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