Skip to content

Commit 793f5c2

Browse files
committed
chore: reform package.json scripts, fix e2e and verify node env for vitest
1 parent 6c109e2 commit 793f5c2

File tree

12 files changed

+67
-19
lines changed

12 files changed

+67
-19
lines changed
File renamed without changes.

.github/workflows/playwright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Install dependencies
1717
run: npm install -g pnpm && pnpm install
1818
- name: Install Playwright Browsers
19-
run: pnpm exec playwright install --with-deps
19+
run: pnpm exec playwright install --with-deps chromium
2020
- name: Run Playwright tests
2121
run: pnpm exec playwright test
2222
- uses: actions/upload-artifact@v4

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.next
22
dist
3-
.cache
43
package-lock.json
54
public
65
node_modules

.prettierrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"bracketSpacing": true,
88
"singleAttributePerLine": true,
99
"endOfLine": "lf",
10-
"plugins": ["prettier-plugin-tailwindcss"]
10+
"plugins": ["prettier-plugin-tailwindcss"],
11+
"tailwindFunctions": ["clsx", "cn", "cva"]
1112
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This is a [Next.js](https://nextjs.org/) 14 Boilerplate project base on [`create
3131

3232
- i18n
3333
- ~~E2E test~~
34-
- Zustand
34+
- Zustand, too simplify, maybe RTK if needed
3535
- after gpr, run pnpm install automatically
3636
- how to update rsc in client?
3737
- Update to Next.js 15

e2e/app.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ test('app journey', async ({ page }) => {
1717
await expect(footerText).toBeVisible()
1818

1919
const navLinks = page.locator('nav a')
20-
const expectedLinksText = ['Loading', 'dashboard', 'todo demos', 'GitHub']
20+
const expectedLinksText = [
21+
'Loading',
22+
'dashboard',
23+
'line chart',
24+
'todo demos',
25+
'GitHub',
26+
]
2127

2228
for (let i = 0; i < expectedLinksText.length; i++) {
2329
const linkText = await navLinks.nth(i).textContent()
@@ -31,7 +37,7 @@ test('app journey', async ({ page }) => {
3137
page.getByRole('heading', { name: 'Show loading UI and streaming' }),
3238
).toBeVisible()
3339

34-
await navLinks.nth(2).click()
40+
await navLinks.nth(3).click()
3541
await expect(page).toHaveURL('/todo')
3642
await expect(
3743
page.getByRole('heading', { name: 'Todo demo with RCC' }),

lib/server/read-file.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @vitest-environment node
2+
3+
import * as fs from 'fs/promises'
4+
import { beforeEach, describe, expect, it, vi } from 'vitest'
5+
6+
import { readFile } from './read-file'
7+
8+
vi.mock('fs/promises')
9+
10+
describe('readFile function', () => {
11+
beforeEach(() => {
12+
vi.resetAllMocks()
13+
})
14+
15+
it('should read file content successfully', async () => {
16+
const mockContent = 'This is the file content'
17+
const mockPath = '/path/to/file.txt'
18+
19+
vi.mocked(fs.readFile).mockResolvedValue(mockContent)
20+
21+
const result = await readFile(mockPath)
22+
23+
expect(result).toBe(mockContent)
24+
expect(fs.readFile).toHaveBeenCalledWith(mockPath, 'utf8')
25+
})
26+
27+
it('should throw an error when file reading fails', async () => {
28+
const mockPath = '/path/to/nonexistent/file.txt'
29+
const mockError = new Error('File not found')
30+
31+
vi.mocked(fs.readFile).mockRejectedValue(mockError)
32+
33+
await expect(readFile(mockPath)).rejects.toThrow(
34+
`Error reading file: ${mockPath}. Error: ${mockError}`,
35+
)
36+
})
37+
})
File renamed without changes.
File renamed without changes.

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
"name": "next-js-boilerplate",
33
"version": "0.1.0",
44
"private": true,
5+
"type": "module",
56
"scripts": {
7+
"preinstall": "npx only-allow pnpm",
8+
"prepare": "husky",
9+
"dev": "next dev | pino-pretty",
10+
"dev:turbo": "next dev --turbo | pino-pretty",
611
"build": "next build",
712
"build-analyze": "cross-env ANALYZE=true pnpm run build",
813
"check-types": "tsc --noEmit --pretty",
9-
"dev": "next dev | pino-pretty",
10-
"dev:turbo": "next dev --turbo | pino-pretty",
11-
"preinstall": "npx only-allow pnpm",
1214
"lint": "next lint",
13-
"lint-fix": "next lint --fix && pnpm run prettier:fix",
14-
"prepare": "husky",
15-
"prettier:fix": "prettier '**/*.{js,jsx,ts,tsx,json,md}' --write",
16-
"start": "next build && cp -r dist/static dist/standalone/dist/static && cp -r public dist/standalone/public && node dist/standalone/server.js",
15+
"lint-and-format-fix": "next lint --fix && pnpm run prettier:fix",
16+
"format:fix": "prettier '**/*.{js,jsx,ts,tsx,json,md}' --write",
17+
"preview": "next build && cp -r dist/static dist/standalone/dist/static && cp -r public dist/standalone/public && node dist/standalone/server.js",
1718
"test": "vitest run",
1819
"test:coverage": "vitest run --coverage",
19-
"test:e2e": "playwright test",
20-
"test:watch": "vitest"
20+
"test:watch": "vitest",
21+
"test:e2e": "playwright test"
2122
},
2223
"dependencies": {
2324
"@radix-ui/react-accordion": "^1.2.0",

playwright.config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { dirname, join } from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
14
import { defineConfig, devices } from '@playwright/test'
2-
import path from 'path'
35

46
/**
57
* Read environment variables from file.
@@ -13,14 +15,16 @@ const PORT = process.env.PORT || 3000
1315
// Set webServer.url and use.baseURL with the location of the WebServer respecting the correct set port
1416
const baseURL = `http://localhost:${PORT}`
1517

18+
const __filename = fileURLToPath(import.meta.url)
19+
const __dirname = dirname(__filename)
1620
/**
1721
* See https://playwright.dev/docs/test-configuration.
1822
*/
1923
export default defineConfig({
2024
// Timeout per test
2125
timeout: 30 * 1000,
2226
// Test directory
23-
testDir: path.join(__dirname, 'e2e'),
27+
testDir: join(__dirname, 'e2e'),
2428
/* Run tests in files in parallel */
2529
fullyParallel: true,
2630
/* Fail the build on CI if you accidentally left test.only in the source code. */
@@ -38,7 +42,7 @@ export default defineConfig({
3842
// Run your local dev server before starting the tests:
3943
// https://playwright.dev/docs/test-advanced#launching-a-development-web-server-during-the-tests
4044
webServer: {
41-
command: process.env.CI ? 'pnpm run start' : 'pnpm run dev:turbo',
45+
command: process.env.CI ? 'pnpm run preview' : 'pnpm run dev:turbo',
4246
url: baseURL,
4347
timeout: 2 * 60 * 1000,
4448
reuseExistingServer: !process.env.CI,

postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = {
1+
export default {
22
plugins: {
33
tailwindcss: {},
44
autoprefixer: {},

0 commit comments

Comments
 (0)