Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gatsby cli repl test #22740

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might fail because of that on slow CIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i realize that. I was just going to do the skateboard implementation and improve it later if it needed more stability. So far it's seemed to have worked.


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

// 4. Make assertions
const logs = getLogs()
logs.should.contain(`success open and validate gatsby-configs`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be tested? All those lines are kinda flaky and subject to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the point of this is to make sure the user experience is managed. So for now this is what's happening, and if it changes we should know. So I like having these tests for now.

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>