Skip to content
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"plugins": ["@typescript-eslint"],
"globals": { "globalThis": false },
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/consistent-type-imports": "error"
}
},
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ jobs:
enableCrossOsArchive: true

- name: Run Unit Tests
run: npx turbo test:ci
run: npx turbo test:unit -- --coverage
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}

- name: Run Storybook Tests
run: npx turbo test:storybook
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
Expand Down
4 changes: 3 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const decorators = [
}
`}
</style>
<Story />
<div data-test-id="story-root">
<Story />
</div>
</NodeDataProvider>
</LocaleProvider>
</SiteProvider>
Expand Down
14 changes: 14 additions & 0 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// TODO: Convert this to ESM once the bug is resolved
// https://github.com/storybookjs/test-runner/issues/293

const config = {
async postRender(page, _context) {
const rootElementId = '[data-test-id="story-root"]';
const rootElement = await page.locator(rootElementId);
const content = await rootElement.innerHTML();
expect(content).toBeDefined();
expect(content).toMatchSnapshot();
},
};

module.exports = config;
15 changes: 11 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Thank you for your interest in contributing to the Node.js Website. Before you p

```bash
git clone git@github.com:<GITHUB_ID>/nodejs.org.git # SSH
gh repo clone <GITHUB_ID>/nodejs.org # GitHub CLI
git clone https://github.com/<GITHUB_ID>/nodejs.org.git # HTTPS
gh repo clone <GITHUB_ID>/nodejs.org # GitHub CLI
```

3. Change into the nodejs.org directory.
Expand All @@ -36,7 +36,9 @@ cd nodejs.org
4. Create a remote for keeping your fork as well as your local clone up-to-date.

```bash
git remote add upstream git@github.com:nodejs/nodejs.org.git
git remote add upstream git@github.com:nodejs/nodejs.org.git # SSH
git remote add upstream https://github.com/nodejs/nodejs.org.git # HTTPS
gh repo sync nodejs/nodejs.org # GitHub CLI
```

5. Create a new branch for your work.
Expand Down Expand Up @@ -102,7 +104,10 @@ We also offer other commands that offer you assistance during your local develop
- **Usage:** `npx turbo scripts:release-post -- --version=vXX.X.X --force`
- `npx turbo storybook` starts Storybook's local server
- `npx turbo storybook:build` builds Storybook as a static web application for publishing
- `npx turbo test` runs jest (unit-tests) locally
- `npx turbo test` runs all tests locally
- `npx turbo test:unit` runs jest (unit-tests) locally
- `npx turbo test:storybook` runs storybook test-runner tests
- `npx turbo test:storybook:snapshot` generates and updates snapshots for all storybook components.

## Creating Components

Expand Down Expand Up @@ -178,7 +183,7 @@ Commits should be signed. You can read more about [Commit Signing][] here.

Each new feature or bug fix should be accompanied by a unit test (when deemed valuable). We use [Jest][] as our test runner and [React Testing Library][] for our React unit tests.

We also use [Storybook][] to document our components. Each component should have a storybook story that documents the component's usage.
We also use [Storybook][] to document our components. Each component should have a storybook story that documents the component's usage. Snapshot testing of our components is directly done by taking snapshot of all Storybook stories, using [Storybook Test Runner][] and [Playwright][].

### General Guidelines for Unit Tests

Expand Down Expand Up @@ -299,6 +304,8 @@ If something is missing here, or you feel something is not well described, feel
[Jest]: https://jestjs.io/
[React Testing Library]: https://testing-library.com/docs/react-testing-library/intro/
[Storybook]: https://storybook.js.org/
[Storybook Test Runner]: https://storybook.js.org/addons/@storybook/test-runner#dom-snapshot-recipe
[Playwright]: https://playwright.dev/
[`react-intl`]: https://formatjs.io/docs/react-intl/
[Next.js]: https://nextjs.org/
[MDX]: https://mdxjs.com/
Expand Down
25 changes: 25 additions & 0 deletions components/Api/DataTag/__snapshots__/index.stories.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Api/DataTag Blue smoke-test 1`] = `
<span class="DataTag_dataTag__xyqF4"
data-tag="M"
>
M
</span>
`;

exports[`Api/DataTag Red smoke-test 1`] = `
<span class="DataTag_dataTag__xyqF4"
data-tag="E"
>
E
</span>
`;

exports[`Api/DataTag Yellow smoke-test 1`] = `
<span class="DataTag_dataTag__xyqF4"
data-tag="C"
>
C
</span>
`;

This file was deleted.

25 changes: 0 additions & 25 deletions components/Api/DataTag/__tests__/index.test.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions components/Api/JsonLink/__snapshots__/index.stories.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Api/JsonLink Default smoke-test 1`] = `
<div class="JsonLink_json__0XIkR">
<a href="https://nodejs.org/docs/latest-v18.x/api/documentation.json">
<span>
View as JSON
</span>
<svg stroke="currentColor"
fill="currentColor"
stroke-width="0"
viewbox="0 0 640 512"
class="JsonLink_FaRobotIcon__KvHGw"
height="1em"
width="1em"
xmlns="http://www.w3.org/2000/svg"
>
<path d="M32,224H64V416H32A31.96166,31.96166,0,0,1,0,384V256A31.96166,31.96166,0,0,1,32,224Zm512-48V448a64.06328,64.06328,0,0,1-64,64H160a64.06328,64.06328,0,0,1-64-64V176a79.974,79.974,0,0,1,80-80H288V32a32,32,0,0,1,64,0V96H464A79.974,79.974,0,0,1,544,176ZM264,256a40,40,0,1,0-40,40A39.997,39.997,0,0,0,264,256Zm-8,128H192v32h64Zm96,0H288v32h64ZM456,256a40,40,0,1,0-40,40A39.997,39.997,0,0,0,456,256Zm-8,128H384v32h64ZM640,256V384a31.96166,31.96166,0,0,1-32,32H576V224h32A31.96166,31.96166,0,0,1,640,256Z">
</path>
</svg>
</a>
</div>
`;
29 changes: 29 additions & 0 deletions components/Api/JsonLink/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.json {
display: flex;
flex-wrap: wrap;

a {
color: var(--color-text-secondary);
font-family: var(--sans-serif);
font-size: 1.4rem;
font-weight: var(--font-weight-regular);
margin-left: 0;
text-decoration: none !important;
text-transform: uppercase;
vertical-align: middle;

span {
font-weight: var(--font-weight-regular);
vertical-align: middle;
}

&:hover {
color: var(--brand-light);
}

.FaRobotIcon {
margin-left: 0.5rem;
vertical-align: middle;
}
}
}
14 changes: 14 additions & 0 deletions components/Api/JsonLink/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import JsonLink from './index';
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

type Story = StoryObj<typeof JsonLink>;
type Meta = MetaObj<typeof JsonLink>;

export const Default: Story = {
args: {
version: 'v18',
fileName: 'documentation',
},
};

export default { component: JsonLink } as Meta;
22 changes: 22 additions & 0 deletions components/Api/JsonLink/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { FormattedMessage } from 'react-intl';
import { FaRobot } from 'react-icons/fa';
import styles from './index.module.scss';
import type { FC } from 'react';

type JsonLinkProps = {
fileName: string;
version: string;
};

const JsonLink: FC<JsonLinkProps> = ({ fileName, version }) => (
<div className={styles.json}>
<a
href={`https://nodejs.org/docs/latest-${version}.x/api/${fileName}.json`}
>
<FormattedMessage id="components.api.jsonLink.title" tagName="span" />
<FaRobot className={styles.FaRobotIcon} />
</a>
</div>
);

export default JsonLink;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Api/Stability Default smoke-test 1`] = `
<div class="Stability_stability__U0Zm0 Stability_stabilityLevel0__ygvXd">
Stability: 0 - Insert the text of your Alert here
</div>
`;
36 changes: 36 additions & 0 deletions components/Api/Stability/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.stability {
border-radius: 4px;
color: #fff;
line-height: 1.5;
margin: 0 0 1rem;
padding: 1rem;

p {
display: inline;
margin: 0;
}

a {
color: #fff;

code {
color: #fff !important;
}
}

&Level0 {
background-color: var(--danger5);
}

&Level1 {
background-color: var(--warning4);
}

&Level2 {
background-color: var(--brand5);
}

&Level3 {
background-color: var(--info5);
}
}
24 changes: 24 additions & 0 deletions components/Api/Stability/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Stability from './index';
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

type Story = StoryObj<typeof Stability>;
type Meta = MetaObj<typeof Stability>;

export const Default: Story = {
args: {
stability: 0,
children: 'Insert the text of your Alert here',
},
argTypes: {
stability: {
control: {
type: 'range',
min: 0,
max: 3,
step: 1,
},
},
},
};

export default { component: Stability } as Meta;
23 changes: 23 additions & 0 deletions components/Api/Stability/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { FormattedMessage } from 'react-intl';
import styles from './index.module.scss';
import type { PropsWithChildren, FC } from 'react';

type StabilityProps = PropsWithChildren<{ stability: number }>;

const getStabilityClass = (stability: number) => {
const style = styles[`stabilityLevel${stability}`];
if (!style) throw new Error(`Unknown stability level: ${stability}`);
return style;
};

const Stability: FC<StabilityProps> = ({ stability, children }) => (
<div className={`${styles.stability} ${getStabilityClass(stability)}`}>
<FormattedMessage
id="components.api.stability"
values={{ level: stability }}
/>
{children}
</div>
);

export default Stability;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Article/Alert Default smoke-test 1`] = `
<div class="Alert_alert__qjYPQ">
This is an alert
</div>
`;
Loading