Skip to content

Commit

Permalink
test: transform jest unspecific tests to native runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Apr 10, 2024
1 parent b56d540 commit ad2200f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 8 additions & 7 deletions test/jest/interceptor.test.js → test/interceptor.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict'

const { strictEqual, deepStrictEqual } = require('node:assert')
const { describe, beforeEach, afterEach, test } = require('node:test')
const { createServer } = require('node:http')
const { Agent, request } = require('../../index')
const DecoratorHandler = require('../../lib/handler/decorator-handler')
/* global expect */
const { Agent, request } = require('../index')
const DecoratorHandler = require('../lib/handler/decorator-handler')

const defaultOpts = { keepAliveTimeout: 10, keepAliveMaxTimeout: 10 }

Expand Down Expand Up @@ -41,7 +42,7 @@ describe('interceptors', () => {

// Assert that the requests are run on different interceptors (different Clients)
const requestCounts = interceptors.map(x => x.requestCount)
expect(requestCounts).toEqual([1, 1])
deepStrictEqual(requestCounts, [1, 1])
})

test('interceptors are applied in the correct order', async () => {
Expand All @@ -54,7 +55,7 @@ describe('interceptors', () => {

const assertHeaderInterceptor = (dispatch) => {
return (opts, handler) => {
expect(opts.headers).toEqual(['foo', 'bar'])
deepStrictEqual(opts.headers, ['foo', 'bar'])
return dispatch(opts, handler)
}
}
Expand Down Expand Up @@ -82,7 +83,7 @@ describe('interceptors', () => {
return (opts, handler) => {
class ResultInterceptor extends DecoratorHandler {
onHeaders (statusCode, headers, resume) {
expect(headers).toEqual([])
deepStrictEqual(headers, [])
return super.onHeaders(statusCode, headers, resume)
}
}
Expand Down Expand Up @@ -192,6 +193,6 @@ describe('interceptors with NtlmRequestHandler', () => {
const agent = new Agent(opts)
const origin = new URL(`http://localhost:${server.address().port}`)
const { statusCode } = await request(origin, { dispatcher: agent, headers: [] })
expect(statusCode).toEqual(200)
strictEqual(statusCode, 200)
})
})
15 changes: 6 additions & 9 deletions test/jest/issue-1757.test.js → test/issue-1757.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const { Dispatcher, setGlobalDispatcher, MockAgent } = require('../..')

/* global expect, it */
const { deepStrictEqual, strictEqual } = require('node:assert')
const { test } = require('node:test')
const { Dispatcher, setGlobalDispatcher, fetch, MockAgent } = require('..')

class MiniflareDispatcher extends Dispatcher {
constructor (inner, options) {
Expand All @@ -23,10 +23,7 @@ class MiniflareDispatcher extends Dispatcher {
}
}

it('https://github.com/nodejs/undici/issues/1757', async () => {
// fetch isn't exported in <16.8
const { fetch } = require('../..')

test('https://github.com/nodejs/undici/issues/1757', async () => {
const mockAgent = new MockAgent()
const mockClient = mockAgent.get('http://localhost:3000')
mockAgent.disableNetConnect()
Expand All @@ -53,6 +50,6 @@ it('https://github.com/nodejs/undici/issues/1757', async () => {
body: JSON.stringify({ foo: 'bar' })
})

expect(response.json()).resolves.toMatchObject({ foo: 'bar' })
expect(response.status).toBe(200)
deepStrictEqual(await response.json(), { foo: 'bar' })
strictEqual(response.status, 200)
})

0 comments on commit ad2200f

Please sign in to comment.