Skip to content

Commit

Permalink
chore(gatsby-cli): Add tests for gatsby repl (#22740)
Browse files Browse the repository at this point in the history
  • Loading branch information
blainekasten committed Apr 3, 2020
1 parent 1161794 commit 480a928
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 2 deletions.
3 changes: 1 addition & 2 deletions integration-tests/gatsby-cli/__tests__/develop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import spawn from "cross-spawn"
import { GatsbyCLI } from "../test-helpers"

const timeout = seconds =>
Expand All @@ -23,7 +22,7 @@ describe(`gatsby develop`, () => {
await timeout(10)

// 3. kill the `gatsby develop` command so we can get logs
spawn.sync("kill", [childProcess.pid])
childProcess.kill()

// 4. Make sure logs for the user contain expected results
const logs = getLogs()
Expand Down
51 changes: 51 additions & 0 deletions integration-tests/gatsby-cli/__tests__/repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { GatsbyCLI } from "../test-helpers"

const timeout = seconds =>
new Promise(resolve => {
setTimeout(resolve, seconds * 1000)
})

const MAX_TIMEOUT = 2147483647
jest.setTimeout(MAX_TIMEOUT)

describe(`gatsby repl`, () => {
const cwd = `gatsby-sites/gatsby-repl`

beforeAll(() => GatsbyCLI.from(cwd).invoke(`clean`))
afterAll(() => GatsbyCLI.from(cwd).invoke(`clean`))

it(`starts a gatsby site on port 8000`, async () => {
// 1. Start the `gatsby develop` command
const [childProcess, getLogs] = GatsbyCLI.from(cwd).invokeAsync(`repl`)

// 2. Wait for the build process to finish
await timeout(4)

// 3. Kill the repl
childProcess.kill()

// 4. Make assertions
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`)

// This is the actual repl prompt
logs.should.contain(`gatsby >`)
})
})
69 changes: 69 additions & 0 deletions integration-tests/gatsby-cli/gatsby-sites/gatsby-repl/.gitignore
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 integration-tests/gatsby-cli/gatsby-sites/gatsby-repl/package.json
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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import React from "react"
export default () => <div>Hi</div>

0 comments on commit 480a928

Please sign in to comment.