Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ next-env.d.ts

*storybook.log
storybook-static

# Playwright
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright/.auth/
17 changes: 17 additions & 0 deletions e2e/tests/profile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from '@playwright/test';

test('나의 프로필 페이지로 접속 시 마이페이지로 리다이렉트 되는 지 테스트', async ({ page }) => {
// 나의 프로필 페이지 방문
await page.goto('/profile/1');

// redirect 대기
await expect(page).toHaveURL('/mypage');
});

test('존재하지 않는 프로필 페이지로 접속 시 404 리다이렉트 되는 지 테스트', async ({ page }) => {
// 나의 프로필 페이지 방문
await page.goto('/profile/4');

// redirect 대기
await expect(page.getByTestId('not-found-user')).toBeVisible();
});
Comment on lines 1 to 17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, check if the file exists and read its content
cat -n e2e/tests/profile.test.ts

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 637


🏁 Script executed:

# Look for Playwright configuration
find . -type f -name "playwright.config.*" | head -5

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 93


🏁 Script executed:

# Check for any baseURL configuration
git ls-files | grep -E "playwright|test" | head -20

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 658


🏁 Script executed:

# Read the Playwright configuration to verify baseURL and browsers
cat -n playwright.config.ts

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 2769


Profile E2E tests are straightforward and align with routing behavior

  • Using page.goto('/profile/1') with expect(page).toHaveURL('/mypage') aligns with the baseURL configuration (http://localhost:3000).
  • The not-found case via getByTestId('not-found-user') matches the component change and should be robust.

The comment on line 12 needs updating: it says "나의 프로필 페이지 방문" (visiting my profile page) but should reflect that it's testing a non-existent profile (e.g., "존재하지 않는 프로필 페이지 방문").

🤖 Prompt for AI Agents
In e2e/tests/profile.test.ts around lines 1 to 17, the inline comment on line 12
incorrectly reads "나의 프로필 페이지 방문" but this test visits a non-existent profile;
update that comment to "존재하지 않는 프로필 페이지 방문" so it accurately describes the test
case and leave the rest of the test unchanged.

4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const customJestConfig = {
'^@/(.*)$': '<rootDir>/src/$1',
},
testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
coveragePathIgnorePatterns: ['/node_modules/'],
testPathIgnorePatterns: ['/node_modules/'],
coveragePathIgnorePatterns: ['/node_modules/', '/.next/', '/e2e/'],
testPathIgnorePatterns: ['/node_modules/', '/.next/', '/e2e/'],
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
"sprite": "node scripts/sprite/generate-sprite.cjs"
"test:playwright": "playwright test",
"test:playwright:ui": "playwright test --ui"
},
"devEngines": {
"runtime": {
Expand Down Expand Up @@ -61,6 +62,7 @@
"@commitlint/config-conventional": "^20.0.0",
"@eslint/eslintrc": "^3",
"@faker-js/faker": "^10.1.0",
"@playwright/test": "^1.57.0",
"@storybook/addon-a11y": "^10.0.5",
"@storybook/addon-docs": "^10.0.5",
"@storybook/nextjs": "^10.1.4",
Expand All @@ -79,6 +81,7 @@
"@typescript-eslint/parser": "^8.46.1",
"babel-plugin-react-compiler": "^1.0.0",
"chromatic": "^13.3.4",
"dotenv": "^17.2.3",
"eslint": "^9",
"eslint-config-next": "16.0.1",
"eslint-config-prettier": "^10.1.8",
Expand Down
78 changes: 78 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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.test') });

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e/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,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* 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://localhost: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 dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});
58 changes: 53 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/(user)/profile/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Link from 'next/link';

const ProfileNotFound = () => {
return (
<div>
<div data-testid='not-found-user'>
<h2>존재하지 않는 유저입니다.</h2>
<Link href='/'>메인으로 돌아가기</Link>
</div>
Expand Down
13 changes: 3 additions & 10 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,16 @@ declare global {
}
}

const config = {
enabledInDevelopment: true,
enabledInProduction: true,
onUnhandledRequest: 'bypass' as const, // bypass | warn | error
};

export const initMocks = async () => {
// MSW 활성화 여부 확인
const isDev = process.env.NODE_ENV === 'development';
const shouldEnable = isDev ? config.enabledInDevelopment : config.enabledInProduction;
const shouldEnable = process.env.NEXT_PUBLIC_MSW_ENABLED === 'true';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

fd -t f "browser|index" src/mock

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 108


🏁 Script executed:

cat -n src/mock/index.ts

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 1525


🏁 Script executed:

cat -n src/mock/browser.ts

Repository: WeGo-Together/WeGo_FrontEnd

Length of output: 661


MSW init flow looks correct; one small type import polish

  • The env gate (NEXT_PUBLIC_MSW_ENABLED === 'true') cleanly centralizes MSW control for both server and client.
  • Caching window.mswWorker avoids duplicate workers across HMR, which is good.
  • Handler wiring is correct: worker is created without handlers in ./browser, then handlers are injected via worker.use() on first init and reset via worker.resetHandlers() on HMR—no duplication.

One improvement:

Mark SetupWorker as a type-only import (line 3) to clarify it's used only for the type annotation on line 10:

-import { SetupWorker } from 'msw/browser';
+import type { SetupWorker } from 'msw/browser';

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
src/mock/index.ts around line 16: the SetupWorker symbol is used only for a type
annotation (on line 10) but is imported as a regular value import; change the
import to a type-only import (e.g., import type { SetupWorker } from 'msw') so
TypeScript drops it from emitted JS and clarifies intent, leaving the rest of
the file unchanged.

if (!shouldEnable) return;

if (typeof window === 'undefined') {
// Server
const { server } = await import('./server');
server.listen({
onUnhandledRequest: config.onUnhandledRequest,
onUnhandledRequest: 'bypass',
});
console.log('🔶 MSW Server ready');
} else {
Expand All @@ -41,7 +34,7 @@ export const initMocks = async () => {
worker.use(...handlers);
// 최초 실행: start()
await worker.start({
onUnhandledRequest: config.onUnhandledRequest,
onUnhandledRequest: 'bypass',
});
console.log('🔷 MSW Client ready');
} else {
Expand Down