-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
test(integration/gatsby-cli): use sandboxed directory to "globally" install gatsby-cli #27056
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
const path = require(`path`) | ||
const execa = require(`execa`) | ||
const fs = require(`fs-extra`) | ||
|
||
module.exports = async () => { | ||
console.log( | ||
`Installing "gatsby-cli" in sandbox directory: "${process.env.GLOBAL_GATSBY_CLI_LOCATION}"` | ||
) | ||
console.log( | ||
`Tests will use "${process.env.GLOBAL_GATSBY_CLI_LOCATION}/node_modules/.bin/gatsby" CLI to invoke commands` | ||
) | ||
|
||
await fs.ensureDir(process.env.GLOBAL_GATSBY_CLI_LOCATION) | ||
|
||
await fs.outputJson( | ||
path.join(process.env.GLOBAL_GATSBY_CLI_LOCATION, `package.json`), | ||
{ | ||
dependencies: { | ||
"gatsby-cli": "latest", | ||
}, | ||
} | ||
) | ||
|
||
const gatsbyDevLocation = path.join( | ||
__dirname, | ||
`..`, | ||
`..`, | ||
`packages`, | ||
`gatsby-dev-cli`, | ||
`dist`, | ||
`index.js` | ||
) | ||
|
||
await execa.node(gatsbyDevLocation, [`--force-install`, `--scan-once`], { | ||
cwd: process.env.GLOBAL_GATSBY_CLI_LOCATION, | ||
stdio: `inherit`, | ||
env: { | ||
// we don't want to run gatsby-dev in with NODE_ENV=test | ||
NODE_ENV: `production`, | ||
}, | ||
}) | ||
} |
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 @@ | ||
const fs = require(`fs`) | ||
const path = require(`path`) | ||
const os = require(`os`) | ||
const baseConfig = require(`../jest.config.js`) | ||
|
||
// install global gatsby-cli to tmp dir to simulate sandbox | ||
const GLOBAL_GATSBY_CLI_LOCATION = (process.env.GLOBAL_GATSBY_CLI_LOCATION = fs.mkdtempSync( | ||
path.join(os.tmpdir(), `gatsby-cli-`) | ||
)) | ||
|
||
module.exports = { | ||
...baseConfig, | ||
globalSetup: "<rootDir>/integration-tests/gatsby-cli/jest.boot.js", | ||
rootDir: `../../`, | ||
globals: { | ||
GLOBAL_GATSBY_CLI_LOCATION, | ||
}, | ||
} |
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 |
---|---|---|
@@ -1,15 +1,22 @@ | ||
#!/bin/bash | ||
set -e # bail on errors | ||
|
||
SRC_PATH=$1 | ||
CUSTOM_COMMAND="${2:-yarn test}" | ||
GATSBY_PATH="${CIRCLE_WORKING_DIRECTORY:-../../}" | ||
|
||
# cypress docker does not support sudo and does not need it, but the default node executor does | ||
command -v gatsby-dev || command -v sudo && sudo npm install -g gatsby-dev-cli || npm install -g gatsby-dev-cli && | ||
command -v gatsby-dev || command -v sudo && sudo npm install -g gatsby-dev-cli || npm install -g gatsby-dev-cli | ||
|
||
# setting up child integration test link to gatsby packages | ||
cd "$SRC_PATH" && | ||
gatsby-dev --set-path-to-repo "$GATSBY_PATH" && | ||
gatsby-dev --force-install --scan-once && # install _all_ files in gatsby/packages | ||
chmod +x ./node_modules/.bin/gatsby && # this is sometimes necessary to ensure executable | ||
sh -c "$CUSTOM_COMMAND" && | ||
cd "$SRC_PATH" | ||
gatsby-dev --set-path-to-repo "$GATSBY_PATH" | ||
gatsby-dev --force-install --scan-once # install _all_ files in gatsby/packages | ||
if test -f "./node_modules/.bin/gatsby"; then | ||
chmod +x ./node_modules/.bin/gatsby # this is sometimes necessary to ensure executable | ||
echo "Gatsby bin chmoded" | ||
else | ||
echo "Gatsby bin doesn't exist. Skipping chmod." | ||
fi | ||
sh -c "$CUSTOM_COMMAND" | ||
echo "e2e test run succeeded" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped chaining commands with
&&
in favour of this so the script fails when any command fails (with exception toif
statement conditions in this case)check https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html for
set
command (and-e
flag in particular) explanationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to showcase that this continue to fail tests properly - https://app.circleci.com/pipelines/github/gatsbyjs/gatsby/50132/workflows/a257b5b7-1e8c-4de1-9854-77c7e530725b is the intentionally not passing jest test ( from temporary draft PR just to test that - #27182 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and reason for dropping chaining is that becomes unreadable with conditional commands - like the chmod that is only done if the file actually exists that I added in this PR)