-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Fix recipe test problems #23347
Fix recipe test problems #23347
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process.env.GATSBY_RECIPES_NO_COLOR = "true" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
const fs = require(`fs-extra`) | ||
const path = require(`path`) | ||
const tmp = require(`tmp-promise`) | ||
|
||
const plugin = require(`./plugin`) | ||
const { addPluginToConfig, getPluginsFromConfig } = require(`./plugin`) | ||
const resourceTestHelper = require(`../resource-test-helper`) | ||
|
||
const root = path.join(__dirname, `./fixtures/gatsby-starter-blog`) | ||
const helloWorldRoot = path.join( | ||
const STARTER_BLOG_FIXTURE = path.join( | ||
__dirname, | ||
`./fixtures/gatsby-starter-blog` | ||
) | ||
const HELLO_WORLD_FIXTURE = path.join( | ||
__dirname, | ||
`./fixtures/gatsby-starter-hello-world` | ||
) | ||
const name = `gatsby-plugin-foo` | ||
const configPath = path.join(root, `gatsby-config.js`) | ||
|
||
describe(`gatsby-plugin resource`, () => { | ||
let tmpDir | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What problems was this causing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test run modified fixtures without restoring them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think this is the result of prettier resolving a different config (or none at all) so writing back out the config after the last destroy results in a diff. |
||
let starterBlogRoot | ||
let helloWorldRoot | ||
let configPath | ||
beforeAll(async () => { | ||
tmpDir = await tmp.dir({ | ||
unsafeCleanup: true, | ||
}) | ||
starterBlogRoot = path.join(tmpDir.path, `gatsby-starter-blog`) | ||
helloWorldRoot = path.join(tmpDir.path, `gatsby-starter-hello-world`) | ||
configPath = path.join(helloWorldRoot, `gatsby-config.js`) | ||
await fs.ensureDir(starterBlogRoot) | ||
await fs.copy(STARTER_BLOG_FIXTURE, starterBlogRoot) | ||
await fs.ensureDir(helloWorldRoot) | ||
await fs.copy(HELLO_WORLD_FIXTURE, helloWorldRoot) | ||
}) | ||
afterAll(async () => { | ||
if (tmpDir) { | ||
await tmpDir.cleanup() | ||
} | ||
}) | ||
|
||
test(`e2e plugin resource test`, async () => { | ||
await resourceTestHelper({ | ||
resourceModule: plugin, | ||
resourceName: `GatsbyPlugin`, | ||
context: { root }, | ||
context: { root: starterBlogRoot }, | ||
initialObject: { id: name, name }, | ||
partialUpdate: { id: name }, | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const diff = require(`jest-diff`).default | ||
const chalk = require(`chalk`) | ||
const stripAnsi = require(`strip-ansi`) | ||
|
||
module.exports = async (oldVal, newVal) => { | ||
const options = { | ||
|
@@ -12,7 +13,11 @@ module.exports = async (oldVal, newVal) => { | |
expand: false, | ||
} | ||
|
||
const diffText = diff(oldVal, newVal, options) | ||
let diffText = diff(oldVal, newVal, options) | ||
|
||
if (process.env.GATSBY_RECIPES_NO_COLOR) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm wondering if we could do this in the test instead, and not in code? Or do we want people to have this option too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like pass it in as an option into the function? That wouldn't keep it any more hidden. |
||
diffText = stripAnsi(diffText) | ||
} | ||
|
||
return diffText | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22685,11 +22685,6 @@ sudo-prompt@^8.2.0: | |
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-8.2.5.tgz#cc5ef3769a134bb94b24a631cc09628d4d53603e" | ||
integrity sha512-rlBo3HU/1zAJUrkY6jNxDOC9eVYliG6nS4JA8u8KAshITd07tafMc/Br7xQwCSseXwJ2iCcHCE8SNWX3q8Z+kw== | ||
|
||
sudo-prompt@^8.2.0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 |
||
version "8.2.5" | ||
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-8.2.5.tgz#cc5ef3769a134bb94b24a631cc09628d4d53603e" | ||
integrity sha512-rlBo3HU/1zAJUrkY6jNxDOC9eVYliG6nS4JA8u8KAshITd07tafMc/Br7xQwCSseXwJ2iCcHCE8SNWX3q8Z+kw== | ||
|
||
supports-color@6.1.0, supports-color@^6.0.0, supports-color@^6.1.0: | ||
version "6.1.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3" | ||
|
@@ -23204,6 +23199,20 @@ title-case@^2.1.0: | |
no-case "^2.2.0" | ||
upper-case "^1.0.3" | ||
|
||
tmp-promise@^2.0.2: | ||
version "2.0.2" | ||
resolved "https://registry.yarnpkg.com/tmp-promise/-/tmp-promise-2.0.2.tgz#ee605edb10f100954be5dd8b9dbe1bfd56194202" | ||
integrity sha512-zl71nFWjPKW2KXs+73gEk8RmqvtAeXPxhWDkTUoa3MSMkjq3I+9OeknjF178MQoMYsdqL730hfzvNfEkePxq9Q== | ||
dependencies: | ||
tmp "0.1.0" | ||
|
||
tmp@0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.1.0.tgz#ee434a4e22543082e294ba6201dcc6eafefa2877" | ||
integrity sha512-J7Z2K08jbGcdA1kkQpJSqLF6T0tdQqpR2pnSUXsIchbPdTI9v3e85cLW0d6WDhwuAleOV71j2xWs8qMPfK7nKw== | ||
dependencies: | ||
rimraf "^2.6.3" | ||
|
||
tmp@^0.0.33: | ||
version "0.0.33" | ||
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" | ||
|
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.
What's up with the semi's in this file?
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.
probably cause we run prettier on the gatsby-config.js source after we add a plugin — so without a .prettierrc around for tests, it adds semis by default