•  


Fix tests for Node.js v21 (#2609) · nodejs/undici@8ec52cd · GitHub
Skip to content

Commit

Permalink
Fix tests for Node.js v21 ( #2609 )
Browse files Browse the repository at this point in the history
  • Loading branch information
sosukesuzuki authored and mcollina committed Feb 5, 2024
1 parent d3aa574 commit 8ec52cd
Showing 1 changed file with 53 additions and 4 deletions .
57 changes: 53 additions & 4 deletions test/mock-interceptor-unused-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const { test , beforeEach , afterEach } = require ( 'tap' )
const { MockAgent , setGlobalDispatcher } = require ( '..' )
const PendingInterceptorsFormatter = require ( '../lib/mock/pending-interceptors-formatter' )
const util = require ( '../lib/core/util' )

// Since Node.js v21 `console.table` rows are aligned to the left
// https://github.com/nodejs/node/pull/50135
const tableRowsAlignedToLeft = util . nodeMajor >= 21

// Avoid colors in the output for inline snapshots.
const pendingInterceptorsFormatter = new PendingInterceptorsFormatter ( { disableColors : true } )
Expand Down Expand Up @@ -40,7 +45,17 @@ test('1 pending interceptor', t => {

const err = t . throws ( ( ) => mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )

t . same ( err . message , `
t . same ( err . message , tableRowsAlignedToLeft
? `
1 interceptor is pending:
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
│ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '?' │ 0 │ 1 │
└─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
` . trim ( )
: `
1 interceptor is pending:
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
Expand All @@ -61,7 +76,18 @@ test('2 pending interceptors', t => {
. reply ( 204 , 'OK' )
const err = t . throws ( ( ) => withTwoInterceptors . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )

t . same ( err . message , `
t . same ( err . message , tableRowsAlignedToLeft
? `
2 interceptors are pending:
┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
├─────────┼────────┼──────────────────────────┼──────────────┼─────────────┼────────────┼─────────────┼───────────┤
│ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '?' │ 0 │ 1 │
│ 1 │ 'GET' │ 'https://localhost:9999' │ '/some/path' │ 204 │ '?' │ 0 │ 1 │
└─────────┴────────┴──────────────────────────┴──────────────┴─────────────┴────────────┴─────────────┴───────────┘
` . trim ( )
: `
2 interceptors are pending:
┌─────────┬────────┬──────────────────────────┬──────────────┬─────────────┬────────────┬─────────────┬───────────┐
Expand Down Expand Up @@ -123,7 +149,20 @@ test('Variations of persist(), times(), and pending status', async t => {

const err = t . throws ( ( ) => agent . assertNoPendingInterceptors ( { pendingInterceptorsFormatter } ) )

t . same ( err . message , `
t . same ( err . message , tableRowsAlignedToLeft
? `
4 interceptors are pending:
┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
├─────────┼────────┼──────────────────────────┼──────────────────────┼─────────────┼────────────┼─────────────┼───────────┤
│ 0 │ 'GET' │ 'https://example.com' │ '/' │ 200 │ '?' │ 0 │ 1 │
│ 1 │ 'GET' │ 'https://localhost:9999' │ '/persistent/unused' │ 200 │ '?' │ 0 │ Infinity │
│ 2 │ 'GET' │ 'https://localhost:9999' │ '/times/partial' │ 200 │ '?' │ 1 │ 4 │
│ 3 │ 'GET' │ 'https://localhost:9999' │ '/times/unused' │ 200 │ '?' │ 0 │ 2 │
└─────────┴────────┴──────────────────────────┴──────────────────────┴─────────────┴────────────┴─────────────┴───────────┘
` . trim ( )
: `
4 interceptors are pending:
┌─────────┬────────┬──────────────────────────┬──────────────────────┬─────────────┬────────────┬─────────────┬───────────┐
Expand Down Expand Up @@ -172,7 +211,17 @@ test('defaults to rendering output with terminal color when process.env.CI is un

const err = t . throws (
( ) => mockAgentWithOneInterceptor ( ) . assertNoPendingInterceptors ( ) )
t . same ( err . message , `
t . same ( err . message , tableRowsAlignedToLeft
? `
1 interceptor is pending:
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
│ (index) │ Method │ Origin │ Path │ Status code │ Persistent │ Invocations │ Remaining │
├─────────┼────────┼───────────────────────┼──────┼─────────────┼────────────┼─────────────┼───────────┤
│ 0 │ \u001b[32m'GET'\u001b[39m │ \u001b[32m'https://example.com'\u001b[39m │ \u001b[32m'/'\u001b[39m │ \u001b[33m200\u001b[39m │ \u001b[32m'?'\u001b[39m │ \u001b[33m0\u001b[39m │ \u001b[33m1\u001b[39m │
└─────────┴────────┴───────────────────────┴──────┴─────────────┴────────────┴─────────────┴───────────┘
` . trim ( )
: `
1 interceptor is pending:
┌─────────┬────────┬───────────────────────┬──────┬─────────────┬────────────┬─────────────┬───────────┐
Expand Down

0 comments on commit 8ec52cd

Please sign in to comment.
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본