Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: move to node test runner #106

Merged
merged 17 commits into from
Feb 9, 2025
Merged
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ jobs:
with:
license-check: true
lint: true
node-versions: '["18", "20", "22"]'
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@
"@types/node": "^22.0.0",
"after": "0.8.2",
"benchmark": "^2.1.4",
"c8": "^10.1.3",
"eslint": "^9.17.0",
"neostandard": "^0.12.0",
"supertest": "6.3.4",
"tap": "^21.0.0",
"tsd": "^0.31.0"
},
"scripts": {
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:coverage": "tap --coverage-report=html",
"test:coverage": "c8 --reporter html node --test",
"test:typescript": "tsd",
"test:unit": "tap"
"test:unit": "node --test"
},
"pre-commit": [
"lint",
Expand Down
6 changes: 3 additions & 3 deletions test/collapseLeadingSlashes.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { collapseLeadingSlashes } = require('../lib/collapseLeadingSlashes')

test('collapseLeadingSlashes', function (t) {
Expand All @@ -16,7 +16,7 @@ test('collapseLeadingSlashes', function (t) {
]
t.plan(testCases.length)

for (let i = 0; i < testCases.length; ++i) {
t.strictSame(collapseLeadingSlashes(testCases[i][0]), testCases[i][1])
for (const testCase of testCases) {
t.assert.deepStrictEqual(collapseLeadingSlashes(testCase[0]), testCase[1])
}
})
6 changes: 3 additions & 3 deletions test/containsDotFile.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { containsDotFile } = require('../lib/containsDotFile')

test('containsDotFile', function (t) {
Expand All @@ -12,7 +12,7 @@ test('containsDotFile', function (t) {
]
t.plan(testCases.length)

for (let i = 0; i < testCases.length; ++i) {
t.strictSame(containsDotFile(testCases[i][0].split('/')), testCases[i][1], testCases[i][0])
for (const testCase of testCases) {
t.assert.deepStrictEqual(containsDotFile(testCase[0].split('/')), testCase[1], testCase[0])
}
})
6 changes: 3 additions & 3 deletions test/isUtf8MimeType.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { isUtf8MimeType } = require('../lib/isUtf8MimeType')

test('isUtf8MimeType', function (t) {
Expand All @@ -16,7 +16,7 @@ test('isUtf8MimeType', function (t) {
]
t.plan(testCases.length)

for (let i = 0; i < testCases.length; ++i) {
t.strictSame(isUtf8MimeType(testCases[i][0], 'test'), testCases[i][1])
for (const testCase of testCases) {
t.assert.deepStrictEqual(isUtf8MimeType(testCase[0], 'test'), testCase[1])
}
})
33 changes: 15 additions & 18 deletions test/mime.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const path = require('node:path')
const request = require('supertest')
const send = require('..')
const { shouldNotHaveHeader, createServer } = require('./utils')

const fixtures = path.join(__dirname, 'fixtures')

test('send.mime', function (t) {
test('send.mime', async function (t) {
t.plan(2)

t.test('should be exposed', function (t) {
await t.test('should be exposed', function (t) {
t.plan(1)
t.ok(send.mime)
t.assert.ok(send.mime)
})

t.test('.default_type', function (t) {
await t.test('.default_type', async function (t) {
t.plan(3)

t.before(() => {
Expand All @@ -27,33 +27,30 @@ test('send.mime', function (t) {
send.mime.default_type = this.default_type
})

t.test('should change the default type', function (t) {
t.plan(1)
await t.test('should change the default type', async function (t) {
send.mime.default_type = 'text/plain'

request(createServer({ root: fixtures }))
await request(createServer({ root: fixtures }))
.get('/no_ext')
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect(200, err => t.error(err))
.expect(200)
})

t.test('should not add Content-Type for undefined default', function (t) {
t.plan(2)
await t.test('should not add Content-Type for undefined default', async function (t) {
t.plan(1)
send.mime.default_type = undefined

request(createServer({ root: fixtures }))
await request(createServer({ root: fixtures }))
.get('/no_ext')
.expect(shouldNotHaveHeader('Content-Type', t))
.expect(200, err => t.error(err))
.expect(200)
})

t.test('should return Content-Type without charset', function (t) {
t.plan(1)

request(createServer({ root: fixtures }))
await t.test('should return Content-Type without charset', async function (t) {
await request(createServer({ root: fixtures }))
.get('/images/node-js.png')
.expect('Content-Type', 'image/png')
.expect(200, err => t.error(err))
.expect(200)
})
})
})
18 changes: 9 additions & 9 deletions test/normalizeList.test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { normalizeList } = require('../lib/normalizeList')

test('normalizeList', function (t) {
const testCases = [
[undefined, new Error('test must be array of strings or false')],
[undefined, new TypeError('test must be array of strings or false')],
[false, []],
[[], []],
['', ['']],
[[''], ['']],
[['a'], ['a']],
['a', ['a']],
[true, new Error('test must be array of strings or false')],
[1, new Error('test must be array of strings or false')],
[[1], new Error('test must be array of strings or false')]
[true, new TypeError('test must be array of strings or false')],
[1, new TypeError('test must be array of strings or false')],
[[1], new TypeError('test must be array of strings or false')]
]
t.plan(testCases.length)

for (let i = 0; i < testCases.length; ++i) {
if (testCases[i][1] instanceof Error) {
t.throws(() => normalizeList(testCases[i][0], 'test'), testCases[i][1])
for (const testCase of testCases) {
if (testCase[1] instanceof Error) {
t.assert.throws(() => normalizeList(testCase[0], 'test'), testCase[1])
} else {
t.strictSame(normalizeList(testCases[i][0], 'test'), testCases[i][1])
t.assert.deepStrictEqual(normalizeList(testCase[0], 'test'), testCase[1])
}
}
})
92 changes: 46 additions & 46 deletions test/parseBytesRange.test.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const { parseBytesRange } = require('../lib/parseBytesRange')

test('parseBytesRange', function (t) {
test('parseBytesRange', async function (t) {
t.plan(13)

t.test('should return empty array if all specified ranges are invalid', function (t) {
await t.test('should return empty array if all specified ranges are invalid', function (t) {
t.plan(3)
t.strictSame(parseBytesRange(200, 'bytes=500-20'), [])
t.strictSame(parseBytesRange(200, 'bytes=500-999'), [])
t.strictSame(parseBytesRange(200, 'bytes=500-999,1000-1499'), [])
t.assert.deepStrictEqual(parseBytesRange(200, 'bytes=500-20'), [])
t.assert.deepStrictEqual(parseBytesRange(200, 'bytes=500-999'), [])
t.assert.deepStrictEqual(parseBytesRange(200, 'bytes=500-999,1000-1499'), [])
})

t.test('should parse str', function (t) {
await t.test('should parse str', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=0-499')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 0, end: 499, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 0, end: 499, index: 0 })
})

t.test('should cap end at size', function (t) {
await t.test('should cap end at size', function (t) {
t.plan(2)
const range = parseBytesRange(200, 'bytes=0-499')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 0, end: 199, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 0, end: 199, index: 0 })
})

t.test('should parse str', function (t) {
await t.test('should parse str', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=40-80')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 40, end: 80, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 40, end: 80, index: 0 })
})

t.test('should parse str asking for last n bytes', function (t) {
await t.test('should parse str asking for last n bytes', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=-400')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 600, end: 999, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 600, end: 999, index: 0 })
})

t.test('should parse str with only start', function (t) {
await t.test('should parse str with only start', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=400-')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 400, end: 999, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 400, end: 999, index: 0 })
})

t.test('should parse "bytes=0-"', function (t) {
await t.test('should parse "bytes=0-"', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=0-')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 0, end: 999, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 0, end: 999, index: 0 })
})

t.test('should parse str with no bytes', function (t) {
await t.test('should parse str with no bytes', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=0-0')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 0, end: 0, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 0, end: 0, index: 0 })
})

t.test('should parse str asking for last byte', function (t) {
await t.test('should parse str asking for last byte', function (t) {
t.plan(2)
const range = parseBytesRange(1000, 'bytes=-1')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 999, end: 999, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 999, end: 999, index: 0 })
})

t.test('should parse str with some invalid ranges', function (t) {
await t.test('should parse str with some invalid ranges', function (t) {
t.plan(2)
const range = parseBytesRange(200, 'bytes=0-499,1000-,500-999')
t.equal(range.length, 1)
t.strictSame(range[0], { start: 0, end: 199, index: 0 })
t.assert.deepStrictEqual(range.length, 1)
t.assert.deepStrictEqual(range[0], { start: 0, end: 199, index: 0 })
})

t.test('should combine overlapping ranges', function (t) {
await t.test('should combine overlapping ranges', function (t) {
t.plan(3)
const range = parseBytesRange(150, 'bytes=0-4,90-99,5-75,100-199,101-102')
t.equal(range.length, 2)
t.strictSame(range[0], { start: 0, end: 75, index: 0 })
t.strictSame(range[1], { start: 90, end: 149, index: 1 })
t.assert.deepStrictEqual(range.length, 2)
t.assert.deepStrictEqual(range[0], { start: 0, end: 75, index: 0 })
t.assert.deepStrictEqual(range[1], { start: 90, end: 149, index: 1 })
})

t.test('should retain original order /1', function (t) {
await t.test('should retain original order /1', function (t) {
t.plan(3)
const range = parseBytesRange(150, 'bytes=90-99,5-75,100-199,101-102,0-4')
t.equal(range.length, 2)
t.strictSame(range[0], { start: 90, end: 149, index: 0 })
t.strictSame(range[1], { start: 0, end: 75, index: 1 })
t.assert.deepStrictEqual(range.length, 2)
t.assert.deepStrictEqual(range[0], { start: 90, end: 149, index: 0 })
t.assert.deepStrictEqual(range[1], { start: 0, end: 75, index: 1 })
})

t.test('should retain original order /2', function (t) {
await t.test('should retain original order /2', function (t) {
t.plan(4)
const range = parseBytesRange(150, 'bytes=-1,20-100,0-1,101-120')
t.equal(range.length, 3)
t.strictSame(range[0], { start: 149, end: 149, index: 0 })
t.strictSame(range[1], { start: 20, end: 120, index: 1 })
t.strictSame(range[2], { start: 0, end: 1, index: 2 })
t.assert.deepStrictEqual(range.length, 3)
t.assert.deepStrictEqual(range[0], { start: 149, end: 149, index: 0 })
t.assert.deepStrictEqual(range[1], { start: 20, end: 120, index: 1 })
t.assert.deepStrictEqual(range[2], { start: 0, end: 1, index: 2 })
})
})
Loading