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

Fix recipe test problems #23347

Merged
merged 1 commit into from
Apr 23, 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
4 changes: 0 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,12 @@ jobs:

unit_tests_node10:
executor: node
environment:
FORCE_COLOR: 0
<<: *test_template

unit_tests_node12:
executor:
name: node
image: "12"
environment:
FORCE_COLOR: 0
<<: *test_template

unit_tests_www:
Expand Down
1 change: 1 addition & 0 deletions .jestSetup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.env.GATSBY_RECIPES_NO_COLOR = "true"
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ module.exports = {
: [`default`].concat(useCoverage ? `jest-junit` : []),
testEnvironment: `jest-environment-jsdom-fourteen`,
moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`],
setupFiles: [`<rootDir>/.jestSetup.js`],
}
4 changes: 3 additions & 1 deletion packages/gatsby-recipes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
"babel-preset-gatsby-package": "^0.3.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"strip-ansi": "^6.0.0",
"tmp-promise": "^2.0.2"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-recipes#readme",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Object {
module.exports = {
/* Your site config here */
plugins: [],
}
};
Copy link
Contributor

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?

Copy link
Contributor

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

",
"describe": "Install gatsby-plugin-foo in gatsby-config.js",
"diff": "- Original - 1
Expand All @@ -30,7 +30,7 @@ module.exports = {
/* Your site config here */
- plugins: [],
+ plugins: [\\"gatsby-plugin-foo\\"],
}
};
",
"id": "gatsby-plugin-foo",
"name": "gatsby-plugin-foo",
Expand All @@ -42,7 +42,7 @@ module.exports = {
module.exports = {
/* Your site config here */
plugins: [\\"gatsby-plugin-foo\\"],
}
};
",
}
`;
Expand All @@ -67,7 +67,7 @@ Object {
module.exports = {
/* Your site config here */
plugins: [\\"gatsby-plugin-foo\\"],
}
};
",
"describe": "Install gatsby-plugin-foo in gatsby-config.js",
"diff": "Compared values have no visual difference.",
Expand All @@ -81,7 +81,7 @@ module.exports = {
module.exports = {
/* Your site config here */
plugins: [\\"gatsby-plugin-foo\\"],
}
};
",
}
`;
Expand All @@ -96,7 +96,7 @@ Object {

exports[`gatsby-plugin resource e2e plugin resource test: GatsbyPlugin create plan 1`] = `
Object {
"currentState": "const redish = \`#c5484d\`
"currentState": "const redish = \`#c5484d\`;
module.exports = {
siteMetadata: {
title: \`Bricolage\`,
Expand Down Expand Up @@ -163,7 +163,7 @@ module.exports = {
\`gatsby-plugin-offline\`, // \`gatsby-plugin-preact\`,
\`gatsby-plugin-react-helmet\`,
],
}
};
",
"describe": "Install gatsby-plugin-foo in gatsby-config.js",
"diff": "- Original - 0
Expand All @@ -175,11 +175,11 @@ module.exports = {
\`gatsby-plugin-react-helmet\`,
+ \\"gatsby-plugin-foo\\",
],
}
};
",
"id": "gatsby-plugin-foo",
"name": "gatsby-plugin-foo",
"newState": "const redish = \`#c5484d\`
"newState": "const redish = \`#c5484d\`;
module.exports = {
siteMetadata: {
title: \`Bricolage\`,
Expand Down Expand Up @@ -247,7 +247,7 @@ module.exports = {
\`gatsby-plugin-react-helmet\`,
\\"gatsby-plugin-foo\\",
],
}
};
",
}
`;
Expand All @@ -264,7 +264,7 @@ Object {

exports[`gatsby-plugin resource e2e plugin resource test: GatsbyPlugin update plan 1`] = `
Object {
"currentState": "const redish = \`#c5484d\`
"currentState": "const redish = \`#c5484d\`;
module.exports = {
siteMetadata: {
title: \`Bricolage\`,
Expand Down Expand Up @@ -332,13 +332,13 @@ module.exports = {
\`gatsby-plugin-react-helmet\`,
\\"gatsby-plugin-foo\\",
],
}
};
",
"describe": "Install gatsby-plugin-foo in gatsby-config.js",
"diff": "Compared values have no visual difference.",
"id": "gatsby-plugin-foo",
"name": "gatsby-plugin-foo",
"newState": "const redish = \`#c5484d\`
"newState": "const redish = \`#c5484d\`;
module.exports = {
siteMetadata: {
title: \`Bricolage\`,
Expand Down Expand Up @@ -406,7 +406,7 @@ module.exports = {
\`gatsby-plugin-react-helmet\`,
\\"gatsby-plugin-foo\\",
],
}
};
",
}
`;
33 changes: 29 additions & 4 deletions packages/gatsby-recipes/src/providers/gatsby/plugin.test.js
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
Copy link
Contributor

Choose a reason for hiding this comment

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

What problems was this causing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test run modified fixtures without restoring them.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 },
})
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby-recipes/src/providers/utils/get-diff.js
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 = {
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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
}
19 changes: 14 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
Expand Down Expand Up @@ -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"
Expand Down