Skip to content

Commit

Permalink
feat(etc) : Configuring the package local test environment (#70)
Browse files Browse the repository at this point in the history
* ✨ Apps/approuter add

* ✨ Apps/pagesrouter add

* 🚧 App router funnel add

* ✨ App router e2e test add

* ✨ Pages router e2e add

* chore: folder name change apps -> examples | nextjs prefix add

* chore: remove package.lock.json & add pnpm.lock
  • Loading branch information
XionWCFM authored Sep 27, 2024
1 parent 0b1a5af commit 559aa8d
Show file tree
Hide file tree
Showing 33 changed files with 888 additions and 38 deletions.
41 changes: 41 additions & 0 deletions examples/nextjs-app-router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
36 changes: 36 additions & 0 deletions examples/nextjs-app-router/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [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.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

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.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Binary file added examples/nextjs-app-router/app/favicon.ico
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/nextjs-app-router/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

19 changes: 19 additions & 0 deletions examples/nextjs-app-router/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { Metadata } from 'next';
import './globals.css';

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
9 changes: 9 additions & 0 deletions examples/nextjs-app-router/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use client';
import dynamic from 'next/dynamic';
const TestAppRouterFunnel = dynamic(() =>
import('../src/funnel').then(({ TestAppRouterFunnel }) => TestAppRouterFunnel),
);
export default function Home() {
//A pre-render error occurs in @use-funnel/browser 0.0.5 version.
return <TestAppRouterFunnel />;
}
19 changes: 19 additions & 0 deletions examples/nextjs-app-router/e2e/app-router-funnel.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test, expect } from '@playwright/test';

const APP_ROUTER_LOCAL_URL = 'http://localhost:3100/';

test('can move the steps of the funnel using history.push.', async ({ page }) => {
await page.goto(APP_ROUTER_LOCAL_URL);

await expect(page.getByText('start')).toBeVisible();

await expect(page.getByRole('button', { name: 'next' })).toBeVisible();

await page.getByRole('button', { name: 'next' }).click();

await expect(page.getByText('end')).toBeVisible();

await page.goBack();

await expect(page.getByText('start')).toBeVisible();
});
4 changes: 4 additions & 0 deletions examples/nextjs-app-router/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};

export default nextConfig;
28 changes: 28 additions & 0 deletions examples/nextjs-app-router/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "nextjs-app-router",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev -p 3100",
"build": "next build",
"start": "next start",
"lint": "next lint",
"e2e": "pnpm exec playwright test"
},
"dependencies": {
"@use-funnel/browser": "workspace:^",
"@use-funnel/core": "workspace:^",
"next": "14.2.13",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@playwright/test": "^1.47.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
80 changes: 80 additions & 0 deletions examples/nextjs-app-router/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// dotenv.config({ path: path.resolve(__dirname, '.env') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
/* 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,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
timeout: 10000,
/* 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('/')`. */
// baseURL: 'http://127.0.0.1:3000',

/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},

/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'pnpm run dev',
url: 'http://127.0.0.1:3100',
reuseExistingServer: !process.env.CI,
},
});
8 changes: 8 additions & 0 deletions examples/nextjs-app-router/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
28 changes: 28 additions & 0 deletions examples/nextjs-app-router/src/funnel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use client';
import { useFunnel } from '@use-funnel/browser';

export const TestAppRouterFunnel = () => {
const funnel = useFunnel<FunnelState>({ id: FUNNEL_ID, initial: { step: 'start', context: {} } });
return (
<funnel.Render
start={({ history }) => (
<div>
<p>start</p>

<button onClick={() => history.push('end')}>next</button>
</div>
)}
end={() => <div>end</div>}
/>
);
};

const FUNNEL_ID = 'test-app-router-funnel';

type StartProps = {};
type EndProps = {};

type FunnelState = {
start: StartProps;
end: EndProps;
};
12 changes: 12 additions & 0 deletions examples/nextjs-app-router/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from 'tailwindcss';

const config: Config = {
content: [
'./pages/**/*.{js,ts,jsx,tsx,mdx}',
'./components/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {},
plugins: [],
};
export default config;
27 changes: 27 additions & 0 deletions examples/nextjs-app-router/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"types": ["@types/node"],
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"~/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
41 changes: 41 additions & 0 deletions examples/nextjs-pages-router/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
Loading

0 comments on commit 559aa8d

Please sign in to comment.