diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml new file mode 100644 index 0000000..9f96598 --- /dev/null +++ b/.github/workflows/continuous-integration.yml @@ -0,0 +1,46 @@ +name: CI +on: + pull_request: + push: + branches: + - main + +jobs: + prettier: + name: Prettier + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: "npm" + - name: Install dependencies + run: npm install --frozen-lockfile + - name: Run code formatting check + run: npm run fmt:check + playwright-tests: + name: Playwright tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 20 + cache: "npm" + - uses: actions/cache@v3 + id: playwright-cache + with: + path: | + ~/.cache/ms-playwright + key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }} + - name: Install dependencies + run: npm ci + - name: Install dependencies + run: | + npx playwright install-deps + npx playwright install + if: steps.playwright-cache.outputs.cache-hit != 'true' + - name: Run tests + run: | + npx playwright test diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml deleted file mode 100644 index 467190b..0000000 --- a/.github/workflows/playwright.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Playwright Tests -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] -jobs: - test: - timeout-minutes: 60 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 - with: - node-version: lts/* - - name: Install dependencies - run: npm ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v4 - if: always() - with: - name: playwright-report - path: playwright-report/ - retention-days: 30 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..27b33f2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,29 @@ +# Contributing Guide + +Thank you for considering contributing to near-directory! Here are some guidelines to help you get started. + +## Getting Started + +To contribute to near-directory, follow these steps: + +1. Fork the repository on GitHub. +2. Clone your forked repository to your local machine. +3. Make your changes locally. +4. Test your changes to ensure they work as expected. +5. Commit your changes with descriptive commit messages. We like [Semantic Commit Messages](https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716). +6. Push your changes to your fork on GitHub. +7. Create a pull request to the main repository. + +## Code Style + +Please follow the existing code style and conventions used in the project. + +## Testing + +This repository uses playwright tests, which can be found in [/playwright-tests](./playwright-tests/). Ensure that your changes include appropriate tests and that existing tests pass. + +## Submitting Issues + +If you encounter any issues or have feature requests, please submit them through GitHub issues. Include as much detail as possible to help us understand and address the problem efficiently. + +Thank you for your interest in contributing to near-directory! Your contributions are greatly appreciated. diff --git a/README.md b/README.md index e92e053..855d884 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,35 @@ -# Near Directory + + + + -- Old Version: [Near Catalog](https://dev.near.org/nearcatalog.near/widget/Index) -- Designs: [Figma](https://www.figma.com/design/I9qRE8BQA8dfFYyYrFRnnm/NBH-Ongoing-Design-Files?node-id=245-2&t=KbwqZF8zbf7uFCt4-0) -- Live Demo: [Near Directory](https://near-directory-nextjs.vercel.app/) +
-This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). +near landscape +
+
+

+ Ecosystem directory for NEAR Protocol. +

-## Getting Started +
-### Cloning the repo +
+ Table of Contents -```bash -git clone https://github.com/NEARBuilders/near-directory-nextjs.git -``` +- [Getting Started](#getting-started) + - [Installing dependencies](#installing-dependencies) + - [Running the app](#running-the-app) + - [Building for production](#building-for-production) + - [Running tests](#running-tests) +- [Project Structure](#project-structure) + - [Routes](#routes) + - [Global State](#global-state) +- [Contributing](#contributing) + +
+ +## Getting Started ### Installing dependencies @@ -28,38 +45,57 @@ First, run the development server: npm run dev ``` -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. +Open [http://localhost:3000](http://localhost:3000) in your browser to see the result. + +### Building for production + +```bash +npm run build +``` + +### Running tests -This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. +```bash +npm run test +``` -## Routes +See the full [testing guide](./playwright-tests/README.md). -The routes are defined in the `app` folder. There are three main pages: +## Project Structure -- `/`: This is the home page of the application. It displays a list of projects that are available on the NEAR platform. -- `/project/:projectId`: This is the page that displays the details of a specific project. It includes information about the project, such as the name, description, and the list of tags associated with the project. -- `/category/:categoryId`: This is the page that displays a list of projects that are associated with a specific category. +This is a [Next.js](https://nextjs.org/) project bootstrapped with [create-next-app](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). -## Global State +It uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load [Inter](https://fonts.google.com/specimen/Inter), a custom Google Font. -[zustand](https://github.com/pmndrs/zustand) is used to manage global state. It is a state management library that provides a simple and scalable solution for managing application state in a React or Preact application. +### Routes -The state is stored in the `store` folder. There are two stores that are used in this project: +This project uses the [Next.js App Router](https://nextjs.org/docs/app), and so the routes are defined in the `app` folder. There are three main pages: + +- `/`: Home page of the application. It displays a list of projects that are available on the NEAR platform. +- `/project/:projectId`: Displays the details of a specific project. It includes information about the project, such as the name, description, and the list of tags associated with the project. +- `/category/:categoryId`: Displays a list of projects that are associated with a specific category. -- `search-store.ts`: This store manages the search state, including the search query and the tags that are selected. -- `tags-modal-store.ts`: This store manages the state of the tags modal for mobile devices. +### Global State -## Learn More +[zustand](https://github.com/pmndrs/zustand) is used to manage global state. It is a state management library that provides a simple and scalable solution for managing application state in a React or Preact application. -To learn more about Next.js, take a look at the following resources: +The state is stored in the `store` folder. There are two stores that are used in this project: -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. +- `search-store.ts`: Manages the search state, including the search query and the tags that are selected. +- `tags-modal-store.ts`: Manages the state of the tags modal for mobile devices. -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! +## Contributing -## Deploy on Vercel +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. +If you're interested in contributing to this project, please read the [contribution guide](./CONTRIBUTING). -Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. +
+ +Near Builders + +
diff --git a/package.json b/package.json index 39ad5fc..e912d3b 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "build": "next build", "start": "next start", "lint": "next lint", + "test": "npx playwright test", + "test:ui": "npx playwright test --ui", "fmt": "prettier --write .", "fmt:check": "prettier --check ." }, diff --git a/playwright-tests/README.md b/playwright-tests/README.md new file mode 100644 index 0000000..1633b86 --- /dev/null +++ b/playwright-tests/README.md @@ -0,0 +1,65 @@ +# Testing Guide + +This project uses [playwright](https://playwright.dev/) for end-to-end testing. Please become familiar with this documentation. + +## Writing tests + +Tests should be written for each change or addition to the codebase. +If a new feature is introduced, tests should be written to validate its functionality. If a bug is fixed, tests should be written to prevent regression. Writing tests not only safeguards against future breaks by other developers but also accelerates development by minimizing manual coding and browser interactions. + +When writing tests, remember to: + +- Test user-visible behavior +- Make tests as isolated as possible +- Avoid testing third-party dependencies + +> **[LEARN BEST PRACTICES](https://playwright.dev/docs/best-practices)** + +See the [cookbook](#cookbook) for help in covering scenerios. It is possible to [generate tests](https://playwright.dev/docs/codegen) via the [VS Code Extension](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright). + +## Running tests + +To run the tests, you may do so through the command line: + +```cmd +npm run test +``` + +With playwright's interactive testing UI: + +```cmd +npm run test:ui +``` + +Or through VS Code, see [Getting started - VS Code](https://playwright.dev/docs/getting-started-vscode). + +## Recording video + +You may automatically record video with your tests by setting + +``` +use: { + video: "on" +} +``` + +in the [playwright.config.js](../playwright.config.js). After running tests, you will find the output as a `.webm` in `./test-results`. Then, [convert to MP4](https://video.online-convert.com/convert/webm-to-mp4) and share. + +It is encouraged to include video in pull requests in order to demonstrate functionality and prove thorough testing. + +## Cookbook + +### Mocking fetch requests + +If you are testing a component that makes fetch requests, you can mock them using the [fetch](https://playwright.dev/docs/api/class-fetch) API. + +```javascript +await page.route("**/api/hello", (route) => { + return route.fulfill({ + status: 200, + body: "Hello, World!", + }); +}); +``` + +Currently, we add this to the `beforeEach` hook in the test file. This way we do not have to mock the requests for every test. diff --git a/tests/category.spec.ts b/playwright-tests/tests/category.spec.ts similarity index 100% rename from tests/category.spec.ts rename to playwright-tests/tests/category.spec.ts diff --git a/tests/home.spec.ts b/playwright-tests/tests/home.spec.ts similarity index 100% rename from tests/home.spec.ts rename to playwright-tests/tests/home.spec.ts diff --git a/tests/project.spec.ts b/playwright-tests/tests/project.spec.ts similarity index 100% rename from tests/project.spec.ts rename to playwright-tests/tests/project.spec.ts diff --git a/playwright.config.ts b/playwright.config.ts index 7e96ffd..8204cad 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -11,17 +11,16 @@ import { defineConfig, devices } from "@playwright/test"; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - testDir: "./tests", + testDir: "./playwright-tests/tests", /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ forbidOnly: !!process.env.CI, /* Retry on CI only */ retries: process.env.CI ? 2 : 0, - /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: process.env.CI ? "100%" : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ - reporter: "html", + reporter: "line", /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { /* Base URL to use in actions like `await page.goto('/')`. */ @@ -37,7 +36,6 @@ export default defineConfig({ name: "chromium", use: { ...devices["Desktop Chrome"] }, }, - { name: "firefox", use: { ...devices["Desktop Firefox"] }, @@ -68,6 +66,7 @@ export default defineConfig({ // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, // }, ], + outputDir: "test-results/", /* Run your local dev server before starting the tests */ webServer: {