-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore(gatsby-cli): Add integration tests for `gatsby develop` * add skip tests to add later
- Loading branch information
1 parent
12c61a6
commit ff51768
Showing
5 changed files
with
202 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import spawn from "cross-spawn" | ||
import { GatsbyCLI, removeFolder } from "../test-helpers" | ||
import strip from "strip-ansi" | ||
|
||
const timeout = seconds => | ||
new Promise(resolve => { | ||
setTimeout(resolve, seconds * 1000) | ||
}) | ||
|
||
const MAX_TIMEOUT = 2147483647 | ||
jest.setTimeout(MAX_TIMEOUT) | ||
|
||
describe(`gatsby develop`, () => { | ||
const cwd = `gatsby-sites/gatsby-develop` | ||
|
||
beforeAll(() => removeFolder(`${cwd}/.cache`)) | ||
beforeAll(() => removeFolder(`${cwd}/public`)) | ||
afterAll(() => removeFolder(`${cwd}/.cache`)) | ||
afterAll(() => removeFolder(`${cwd}/public`)) | ||
|
||
it(`starts a gatsby site on port 8000`, async () => { | ||
// 1. Start the `gatsby develop` command | ||
const [childProcess, getLogs] = GatsbyCLI.from(cwd).invokeAsync(`develop`) | ||
|
||
// 2. Wait for the build process to finish | ||
await timeout(10) | ||
|
||
// 3. Get the process identifier for what is running on port 8000 | ||
const res = spawn.sync("lsof", ["-i", ":8000", "-t"]) | ||
const portPID = Number(/\d+/.exec(res.output?.toString())[0]) | ||
|
||
// 4. kill the `gatsby develop` command so we can get logs | ||
spawn.sync("kill", [childProcess.pid]) | ||
|
||
// 5. Make sure the process we started was the one on gatsby port | ||
expect(portPID).toEqual(childProcess.pid) | ||
|
||
// 6. Make sure logs for the user contain expected results | ||
const logs = getLogs() | ||
logs.should.contain(`success open and validate gatsby-configs`) | ||
logs.should.contain(`success load plugins`) | ||
logs.should.contain(`success onPreInit`) | ||
logs.should.contain(`success initialize cache`) | ||
logs.should.contain(`success copy gatsby files`) | ||
logs.should.contain(`success onPreBootstrap`) | ||
logs.should.contain(`success createSchemaCustomization`) | ||
logs.should.contain(`success source and transform nodes`) | ||
logs.should.contain(`success building schema`) | ||
logs.should.contain(`success createPages`) | ||
logs.should.contain(`success createPagesStatefully`) | ||
logs.should.contain(`success onPreExtractQueries`) | ||
logs.should.contain(`success update schema`) | ||
logs.should.contain(`success extract queries from components`) | ||
logs.should.contain(`success write out requires`) | ||
logs.should.contain(`success write out redirect data`) | ||
logs.should.contain(`success onPostBootstrap`) | ||
logs.should.contain(`info bootstrap finished`) | ||
logs.should.contain( | ||
`You can now view gatsby-starter-default in the browser.` | ||
) | ||
logs.should.contain(`http://localhost:8000/`) | ||
logs.should.contain( | ||
`View GraphiQL, an in-browser IDE, to explore your site's data and schema` | ||
) | ||
logs.should.contain(`http://localhost:8000/___graphql`) | ||
logs.should.contain(`Note that the development build is not optimized.`) | ||
logs.should.contain(`To create a production build, use gatsby build`) | ||
}) | ||
|
||
it.skip(`starts a gatsby site on port 9000 with -p 9000`, () => {}) | ||
it.skip(`starts a gatsby site at a diffent host with -h`, () => {}) | ||
it.skip(`starts a gatsby site with ssl using -S`, () => {}) | ||
it.skip(`starts a gatsby site with cert file using -c`, () => {}) | ||
it.skip(`starts a gatsby site with key file using -k`, () => {}) | ||
it.skip(`starts a gatsby site with -open-tracing-config-file`, () => {}) | ||
}) |
69 changes: 69 additions & 0 deletions
69
integration-tests/gatsby-cli/gatsby-sites/gatsby-develop/.gitignore
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,69 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variable files | ||
.env* | ||
|
||
# gatsby files | ||
.cache/ | ||
public | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Yarn | ||
yarn-error.log | ||
.pnp/ | ||
.pnp.js | ||
# Yarn Integrity file | ||
.yarn-integrity |
37 changes: 37 additions & 0 deletions
37
integration-tests/gatsby-cli/gatsby-sites/gatsby-develop/package.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,37 @@ | ||
{ | ||
"name": "gatsby-starter-default", | ||
"private": true, | ||
"description": "A simple starter to get up and developing quickly with Gatsby", | ||
"version": "0.1.0", | ||
"author": "Kyle Mathews <mathews.kyle@gmail.com>", | ||
"dependencies": { | ||
"gatsby": "^2.19.45", | ||
"prop-types": "^15.7.2", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"react-helmet": "^5.2.1" | ||
}, | ||
"devDependencies": { | ||
"prettier": "^1.19.1" | ||
}, | ||
"keywords": [ | ||
"gatsby" | ||
], | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "gatsby build", | ||
"develop": "gatsby develop", | ||
"format": "prettier --write \"**/*.{js,jsx,json,md}\"", | ||
"start": "npm run develop", | ||
"serve": "gatsby serve", | ||
"clean": "gatsby clean", | ||
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gatsbyjs/gatsby-starter-default" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/gatsbyjs/gatsby/issues" | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/gatsby-cli/gatsby-sites/gatsby-develop/src/pages/index.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,2 @@ | ||
import React from "react" | ||
export default () => <div>Hi</div> |
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