Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
LekoArts authored Jul 25, 2022
2 parents 69902ec + 82172de commit 7e9b55c
Show file tree
Hide file tree
Showing 53 changed files with 128 additions and 310 deletions.
2 changes: 1 addition & 1 deletion docs/docs/debugging-html-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const isBrowser = typeof window !== "undefined"
export default function MyComponent() {
let loggedIn = false
if (isBrowser) {
window.localstorage.getItem("isLoggedIn") === "true"
window.localStorage.getItem("isLoggedIn") === "true"
}

return <div>Am I logged in? {loggedIn}</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/how-to/styling/using-local-fonts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This guide uses the Gatsby [default starter](https://github.com/gatsbyjs/gatsby-

Get started by using local fonts by adding them to your project. Copy the font file into your Gatsby project, for example, `src/fonts/fontname.woff2`.

**NOTE:** It’s recommended to limit custom font usage to only the essential needed for performance.
**NOTE:** For performance reasons, it’s recommended to limit the number of custom fonts added.

The Gatsby default starter project adds [browser safe font](https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#Default_fonts) styling in the `layout.css` file.

Expand Down
45 changes: 22 additions & 23 deletions docs/docs/how-to/testing/end-to-end-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ To run Gatsby's development server and Cypress at the same time, you'll use the
npm install --save-dev cypress start-server-and-test
```

We also want the URLs used by `cy.visit()` or `cy.request()` to be prefixed, hence you have to create the file `cypress.json` at the root of your project with the following content:
You need to create a config file for Cypress at the root of the project called `cypress.config.js`. You can use it to preface the URLs used by `cy.visit()` or `cy.request` as well as set the folder the tests are in by adding the following:

```json:title=cypress.json
{
"baseUrl": "http://localhost:8000/"
}
```js:title=cypress.config.js
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:8000',
specPattern: "cypress/e2e"
}
})
```

Last but not least you add additional scripts to your `package.json` to run Cypress:
You also need to add additional scripts to your `package.json` to run Cypress:

```json:title=package.json
{
Expand All @@ -37,7 +42,7 @@ Last but not least you add additional scripts to your `package.json` to run Cypr

Type `npm run test:e2e` in your command line and see Cypress running for the first time. A folder named `cypress` will be created at the root of your project and a new application window will pop up. [Cypress' getting started guide](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#) is a good start to learn how to write tests!

_Important note_: If you are running Gatsby with the `--https` flag, whether using your own or automatically generated certificates, you will also need to tell `start-server-and-test` to disable HTTPS certificate checks (otherwise it will wait forever and never actually launch Cypress. You do this by passing in an environmental variable: `START_SERVER_AND_TEST_INSECURE=1`. [start-server-and-test docs](https://github.com/bahmutov/start-server-and-test#disable-https-certificate-checks)).
**Please note:** If you are running Gatsby with the `--https` flag, whether using your own or automatically generated certificates, you will also need to tell `start-server-and-test` to disable HTTPS certificate checks (otherwise it will wait forever and never actually launch Cypress. You do this by passing in an environmental variable: `START_SERVER_AND_TEST_INSECURE=1`. [start-server-and-test docs](https://github.com/bahmutov/start-server-and-test#disable-https-certificate-checks)).

This means your `test:e2e` script would look like this:

Expand Down Expand Up @@ -75,26 +80,16 @@ To use cypress-axe, you have to install the `cypress-axe` and [axe-core](https:/
npm install --save-dev cypress-axe axe-core @testing-library/cypress
```

Then you add the `cypress-axe` and `@testing-library/cypress` commands in `cypress/support/index.js`:
Then you add the `cypress-axe` and `@testing-library/cypress` commands in `cypress/support/e2e.js`:

```js:title=cypress/support/index.js
import "./commands"
```js:title=cypress/support/e2e.js
//highlight-start
import "cypress-axe"
import "@testing-library/cypress/add-commands"
//highlight-end
```

Cypress will look for tests inside the `cypress/integration` folder, but you can change the default test folder if you want. Because you're writing end-to-end tests, create a new folder called `cypress/e2e`, and use it as your `integrationFolder` in your `cypress.json`:

```json:title=cypress.json
{
"baseUrl": "http://localhost:8000/",
"integrationFolder": "cypress/e2e" // highlight-line
}
```

Create a new file inside `cypress/e2e` folder and name it `accessibility.test.js`.
Create a folder inside the cypress folder and a new file inside `cypress/e2e` folder and name it `accessibility.test.js`.

You'll use the `beforeEach` hook to run some commands before each test. This is what they do:

Expand All @@ -109,7 +104,8 @@ Finally, inside the first test, you'll use the `checkA11y` command from `cypress

describe("Accessibility tests", () => {
beforeEach(() => {
cy.visit("/").get("main").injectAxe()
cy.visit("/").get("main")
cy.injectAxe()
})
it("Has no detectable accessibility violations on load", () => {
cy.checkA11y()
Expand All @@ -132,7 +128,8 @@ The following test is for the [gatsby-default-starter](https://github.com/gatsby

describe("Accessibility tests", () => {
beforeEach(() => {
cy.visit("/").get("main").injectAxe()
cy.visit("/").get("main")
cy.injectAxe()
})
it("Has no detectable accessibility violations on load", () => {
cy.checkA11y()
Expand All @@ -156,11 +153,13 @@ You'll now write another test for the `gatsby-default-starter` homepage. In this

describe("Accessibility tests", () => {
beforeEach(() => {
cy.visit("/").get("main").injectAxe()
cy.visit("/").get("main")
cy.injectAxe()
})
it("Has no detectable accessibility violations on load", () => {
cy.checkA11y()
})

it("Navigates to page 2 and checks for accessibility violations", () => {
cy.findByText(/go to page 2/i)
.click()
Expand Down
1 change: 1 addition & 0 deletions docs/docs/reference/built-in-components/gatsby-head.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ You'll need to be aware of these things when using Gatsby Head:
- The `Head` function needs to return valid JSX.
- Valid tags inside the `Head` function are: `link`, `meta`, `style`, `title`, `base`, `script`, and `noscript`.
- Data block `<script>` tags such as `<script type="application/ld+json">` can go in the `Head` function, but dynamic scripts are better loaded with the [Gatsby Script Component](/docs/reference/built-in-components/gatsby-script/) in your pages or components.
- Using the Head API and [react-helmet](https://github.com/nfl/react-helmet) in the same page is not supported as it can generate unexpected results.

## Properties

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/tutorial/part-1/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ To connect your code on GitHub to your Gatsby Cloud account, do the following:
![The new fields. "Base Branch" is set to "main", "Base Directory" is set to "/", and "Site Name" is set to "my-first-gatsby-site-main".](./05-add-site-details.png)
1. Gatsby Cloud will ask you if you want to add any integrations to your site. For future projects, this might be useful if you want to use a CMS. Gatsby Cloud will also ask if you want to add any environment variables. Again, this may useful for future projects, but for now, scroll past and click the **"Build Site"** button.
1. Gatsby Cloud will ask you if you want to add any integrations to your site. For future projects, this might be useful if you want to use a CMS. Gatsby Cloud will also ask if you want to add any environment variables. Again, this may be useful for future projects, but for now, scroll past and click the **"Build Site"** button.
![The "Integrations" tab of the "Add a site" screen.](./06-integrations-and-environment-variables.png)
Expand Down
10 changes: 9 additions & 1 deletion docs/tutorial/remark-plugin-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ However, if the sub-plugin is published and installed via npm, simply refer to i

When modifying nodes, you'll want to walk the tree and then implement new functionality on specific nodes.

A node module to help with is [unist-util-visit](https://github.com/syntax-tree/unist-util-visit), a walker for `unist` nodes. For reference, Unist (Unified Syntax Tree) is a standard for Markdown syntax trees and parsers that include well known parsers in the Gatsby world like Remark and MDX.
A node module to help with this is [unist-util-visit](https://github.com/syntax-tree/unist-util-visit), a walker for `unist` nodes. For reference, Unist (Unified Syntax Tree) is a standard for Markdown syntax trees and parsers that include well known parsers in the Gatsby world like Remark and MDX.

As an example from `unist-util-visit`'s README file, it allows for an interface to visit particular nodes based on a particular type:

Expand All @@ -208,6 +208,14 @@ function visitor(node) {

Here, it finds all text nodes and will `console.log` the nodes. The second argument can be replaced with any type described in Unist's [Markdown AST (mdast) specification](https://github.com/syntax-tree/mdast#nodes) including types such as `paragraph`, `blockquote`, `link`, `image` or in our usecase, `heading`.

To be able to use `unist-util-visit`, install it into your plugin:

```shell
npm install unist-util-visit@^2
```

**Please note**: You're installing v2 of `unist-util-visit` as newer major versions are ESM and Gatsby doesn't fully support that yet.

With this technique in mind, you can similarly traverse the AST from your plugin and add additional functionality, like so:

```js:title=plugins/gatsby-remark-purple-headers/index.js
Expand Down
2 changes: 1 addition & 1 deletion examples/using-cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Gatsby example site that shows how to write accessibility tests with Cypress and
- `npm install`
- `npm run test:e2e`

See the [End-to-End Testing](https://www.gatsbyjs.com/docs/end-to-end-testing/) guide for a walkthrough and more details.
See the [End-to-End Testing](https://www.gatsbyjs.com/docs/how-to/testing/end-to-end-testing/) guide for a walkthrough and more details.
8 changes: 8 additions & 0 deletions examples/using-cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:8000',
specPattern: "cypress/e2e"
}
})
4 changes: 0 additions & 4 deletions examples/using-cypress/cypress.json

This file was deleted.

5 changes: 2 additions & 3 deletions examples/using-cypress/cypress/e2e/accessibility.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/// <reference types="Cypress" />

describe("Accessibility tests", () => {
beforeEach(() => {
cy.visit("/").get("main").injectAxe()
cy.visit("/").get("main")
cy.injectAxe()
})
it("Has no detectable accessibility violations on load", () => {
cy.checkA11y()
Expand Down
21 changes: 0 additions & 21 deletions examples/using-cypress/cypress/plugins/index.js

This file was deleted.

28 changes: 1 addition & 27 deletions examples/using-cypress/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,5 @@ module.exports = {
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
`gatsby-plugin-react-helmet`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
{
resolve: `gatsby-plugin-manifest`,
options: {
name: `gatsby-starter-default`,
short_name: `starter`,
start_url: `/`,
background_color: `#663399`,
theme_color: `#663399`,
display: `minimal-ui`,
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
},
},
// this (optional) plugin enables Progressive Web App + Offline functionality
// To learn more, visit: https://gatsby.dev/offline
// `gatsby-plugin-offline`,
],
plugins: [],
}
3 changes: 3 additions & 0 deletions examples/using-cypress/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.onRenderBody = ({ setHtmlAttributes }) => {
setHtmlAttributes({ lang: `en` })
}
27 changes: 8 additions & 19 deletions examples/using-cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"clean": "gatsby clean",
"cy:open": "cypress open",
Expand All @@ -18,25 +16,16 @@
},
"dependencies": {
"gatsby": "next",
"gatsby-image": "next",
"gatsby-plugin-manifest": "next",
"gatsby-plugin-offline": "next",
"gatsby-plugin-react-helmet": "next",
"gatsby-plugin-sharp": "next",
"gatsby-source-filesystem": "next",
"gatsby-transformer-sharp": "next",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-helmet": "^5.2.1"
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@testing-library/cypress": "^5.3.1",
"axe-core": "^3.5.5",
"cypress": "^4.12.1",
"cypress-axe": "^0.8.1",
"prettier": "2.1.1",
"start-server-and-test": "^1.11.3"
"@testing-library/cypress": "^8.0.3",
"axe-core": "^4.4.3",
"cypress": "^10.3.1",
"cypress-axe": "^1.0.0",
"start-server-and-test": "^1.14.0"
},
"keywords": [
"gatsby"
Expand Down
32 changes: 0 additions & 32 deletions examples/using-cypress/src/components/image.js

This file was deleted.

7 changes: 0 additions & 7 deletions examples/using-cypress/src/components/layout.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/**
* Layout component that queries for data
* with Gatsby's useStaticQuery component
*
* See: https://www.gatsbyjs.com/docs/use-static-query/
*/

import React from "react"
import PropTypes from "prop-types"
import { useStaticQuery, graphql } from "gatsby"
Expand Down
Loading

0 comments on commit 7e9b55c

Please sign in to comment.