-
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.
test(integration-tests/gatsby-cli): install cli to sandbox directory,…
… so it can't use any accidental node_modules
- Loading branch information
Showing
5 changed files
with
80 additions
and
21 deletions.
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