Сообщения

Сообщения за июль, 2025

End-to-End testing of a Next.js application using Playwright and MSW. Continue

This article is a continuation of the previous one «End-to-End Testing of a Next.js Application Using Playwright and MSW» , and aims to explain why we ultimately opt to use a separate mock server despite the fact that it’s possible to mock current requests directly within the test environment. Initially, using the @mswjs/http-middleware library to start a separate server wasn't part of the plan. The idea was to hook into the existing server within the test environment. To do this, we add a .env.test file with the following contents: APP_ENV=test And in the main layout file app/layout.tsx , we’ll use this environment variable to determine whether the mock server should be enabled or not: import { server } from '@/mocks/server'; // only TEST ENV: run server.listen for e2e-testing if (process.env.APP_ENV === 'test') {     server.listen({         onUnhandledRequest(request) {           ...

e2e тестирование nextsj приложения с playwright & msw. Продолжение

Эта статья продолжает предыдущую «e2e тестирование nextsj приложения с playwright & msw»  , вернее поясняет почему мы приходим к варианту работы с отдельным сервером, тогда как можно замокать текущие запросы в текущем окружении. Изначально не предполагалось использовать  @mswjs/http-middleware библиотеку для запуска отдельного сервера, а слушать текущий сервер в тестовом окружении. Для этого добавим файл  .env.test со следующим содержимым: APP_ENV=test А в главном лайауте  app/layout.tsx  будем использовать эту переменную окружения чтобы определить слушать ли сервер или нет: import { server } from '@/mocks/server'; // only TEST ENV: run server.listen for e2e-testing if (process.env.APP_ENV === 'test') {     server.listen({         onUnhandledRequest(request) {             console.log('Unhandled %s %s', request.method, request.url);    ...