Skip to content

Commit 87ae2c4

Browse files
authored
test(logger-plugin): assert console.info() in nock/msw
1 parent d7b4e4b commit 87ae2c4

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

test/e2e/msw.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpResponse, http } from 'msw';
22
import { setupServer } from 'msw/node';
33
import request from 'supertest';
4-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
4+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
55

66
import { createApp, createProxyMiddleware } from './test-kit.js';
77

@@ -27,6 +27,8 @@ describe('E2E msw', () => {
2727
});
2828

2929
it('proxies GET requests to a msw mocked target', async () => {
30+
await using consoleInfoSpy = await vi.spyOn(console, 'info');
31+
3032
server.use(
3133
http.get(`${target}/api/hello`, () => {
3234
return new HttpResponse('hello from msw', { status: 200 });
@@ -40,13 +42,17 @@ describe('E2E msw', () => {
4042
pathFilter: '/api',
4143
// Keep msw-based e2e stable and aligned with nock e2e transport path.
4244
followRedirects: true,
45+
logger: console,
4346
}),
4447
),
4548
);
4649

4750
const response = await agent.get('/api/hello').expect(200);
4851

4952
expect(response.text).toBe('hello from msw');
53+
expect(consoleInfoSpy).toHaveBeenCalledWith(
54+
'[HPM] GET /api/hello -> http://localhost:45678/api/hello [200]',
55+
);
5056
});
5157

5258
it('forwards query string to the msw mocked target', async () => {

test/e2e/nock.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import nock from 'nock';
22
import request from 'supertest';
3-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
3+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
44

55
import { createApp, createProxyMiddleware } from './test-kit.js';
66

@@ -26,13 +26,16 @@ describe('E2E nock', () => {
2626
});
2727

2828
it('proxies GET requests to a nock mocked target', async () => {
29+
await using consoleInfoSpy = await vi.spyOn(console, 'info');
30+
2931
const agent = request(
3032
createApp(
3133
createProxyMiddleware({
3234
target,
3335
pathFilter: '/api',
3436
// Keep nock-based e2e stable: avoid the default socket-connect piping path.
3537
followRedirects: true,
38+
logger: console,
3639
}),
3740
),
3841
);
@@ -42,6 +45,9 @@ describe('E2E nock', () => {
4245
const response = await agent.get('/api/hello').expect(200);
4346

4447
expect(response.text).toBe('hello from nock');
48+
expect(consoleInfoSpy).toHaveBeenCalledWith(
49+
'[HPM] GET /api/hello -> http://localhost:45678/api/hello [200]',
50+
);
4551
});
4652

4753
it('forwards query string to the nock mocked target', async () => {

0 commit comments

Comments
 (0)