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

chore/upgrade greenwood v0.30.0 alpha.7 #107

Merged
merged 13 commits into from
Oct 31, 2024
40 changes: 14 additions & 26 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ The WTR and the full setup is covered in greater detail within [the GreenwoodJS

1. **[Mock Data Requests](https://www.greenwood.dev/guides/ecosystem/web-test-runner/#content-as-data)**

If using Greenwood's Content as Data feature, mocking `fetch` with mock data is necessary.
If using one of Greenwood's Content as Data [Client APIs](/docs/content-as-data/data-client/), mocking `fetch` with mock data is necessary.

#### Examples

Expand Down Expand Up @@ -279,38 +279,26 @@ components/
my-component.stories.js
```

#### _Content as Data_ Stories

When a component requires a `fetch` request for data, the story will need to mock this request before being able to render within the Storybook.

To mock `fetch`, create a `parameter` within the story export object named `fetchMock`. This object contains a `mocks` array with a `matcher` for the localhost network request URL. The `matcher.response` object represents the mocked data to use with the story.

Checkout [the `blog-posts-list.stories.js` story](https://github.com/ProjectEvergreen/www.greenwoodjs.dev/blob/main/src/components/blog-posts-list/blog-posts-list.stories.js) as an example.
Below is an example of a basic Storybook file:

```js
import "./my-custom-element.js";
import pages from "../../stories/mocks/graph.json";
import "./header.js";

export default {
title: "Components/My Custom Element",
parameters: {
// ...other parameters, if necessary...
fetchMock: {
mocks: [
{
matcher: {
url: "http://localhost:1985/graph.json",
response: {
body: pages,
},
},
},
],
},
},
title: "Components/Header",
};

const Template = () => "<app-header></app-header>";

export const Primary = Template.bind({});
```

#### Content as Data

When a component implements one of Greenwood's Content as Data [Client APIs](/docs/content-as-data/data-client/), the story will need to mock this request before being able to render within the Storybook.

See the [Greenwood Storybook docs](/guides/ecosystem/storybook/#content-as-data) for more information and [the _blog-posts-list.stories.js_ story](https://github.com/ProjectEvergreen/www.greenwoodjs.dev/blob/main/src/components/blog-posts-list/blog-posts-list.stories.js) for an example in this project.

## Hosting and Deployment

This project is hosted on Netlify and automatically deploys on each merge into main. Release branches will be curated over the course of a Greenwood release cycle and then merged at the time the new Greenwood release is published to NPM.
5 changes: 5 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import markdown from "@eslint/markdown";
import json from "@eslint/json";
import js from "@eslint/js";
import globals from "globals";
import noOnlyTests from "eslint-plugin-no-only-tests";

export default [
{
Expand Down Expand Up @@ -39,6 +40,10 @@ export default [
...js.configs.recommended.rules,
// turn this off for Prettier
"no-irregular-whitespace": "off",
"no-only-tests/no-only-tests": "error",
},
plugins: {
"no-only-tests": noOnlyTests,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions greenwood.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { greenwoodPluginCssModules } from "@greenwood/plugin-css-modules";
import { greenwoodPluginImportRaw } from "@greenwood/plugin-import-raw";
import { greenwoodPluginCssModules } from "./plugin-css-modules.js";

export default {
activeFrontmatter: true,
activeContent: true,

// would be nice if we could customize these plugins, like appending the autolink headings
// https://github.com/ProjectEvergreen/greenwood/issues/1247
Expand Down
Loading