Skip to content

Commit

Permalink
Replaced tap/mocha/chai with node:test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Pupix committed Jan 23, 2025
1 parent 0c43d79 commit 5ce041e
Show file tree
Hide file tree
Showing 9 changed files with 8,125 additions and 15,147 deletions.
23,069 changes: 8,019 additions & 15,050 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions packages/autocannon-compare-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
"type": "module",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "tap test/*.test.js",
"test": "node --test",
"lint": "eslint ."
},
"author": "",
"license": "ISC",
"dependencies": {
"@types/optimist": "^0.0.33",
"@types/tap": "^15.0.8",
"chalk": "^5.2.0",
"chalk-table": "^1.0.2",
"optimist": "^0.6.1"
Expand Down
54 changes: 28 additions & 26 deletions packages/autocannon-compare-cli/test/util.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'

import chalk from 'chalk'
import tap from 'tap'
import {
calculateDiffPercentage,
formatBytes,
Expand All @@ -8,38 +10,38 @@ import {
Kind
} from '../util.js'

tap.test('formatBytes', async t => {
t.equal(formatBytes(100), '100 bytes')
t.equal(formatBytes(1024), '1.0 KB')
t.equal(formatBytes(1024000), '1000 KB')
t.equal(formatBytes(1073741824), '1.0 GB')
test('formatBytes', async () => {
assert.equal(formatBytes(100), '100 bytes')
assert.equal(formatBytes(1024), '1.0 KB')
assert.equal(formatBytes(1024000), '1000 KB')
assert.equal(formatBytes(1073741824), '1.0 GB')
})

tap.test('calculateDiffPercentage', async t => {
t.equal(calculateDiffPercentage(1, 1), '=')
t.equal(calculateDiffPercentage(0, 0), '=')
t.equal(calculateDiffPercentage(0, 10), '-100%')
t.equal(calculateDiffPercentage(10, 0), '+100%')
t.equal(calculateDiffPercentage(10, 2), '+400%')
t.equal(calculateDiffPercentage(2, 10), '-80%')
t.equal(calculateDiffPercentage(6.5, 10), '-35%')
test('calculateDiffPercentage', async () => {
assert.equal(calculateDiffPercentage(1, 1), '=')
assert.equal(calculateDiffPercentage(0, 0), '=')
assert.equal(calculateDiffPercentage(0, 10), '-100%')
assert.equal(calculateDiffPercentage(10, 0), '+100%')
assert.equal(calculateDiffPercentage(10, 2), '+400%')
assert.equal(calculateDiffPercentage(2, 10), '-80%')
assert.equal(calculateDiffPercentage(6.5, 10), '-35%')
})

tap.test('getColor', async t => {
t.equal(getColor('+100%', Kind.moreIsBetter), chalk.green)
t.equal(getColor('-100%', Kind.moreIsBetter), chalk.red)
t.equal(getColor('-100%', Kind.lessIsBetter), chalk.green)
t.equal(getColor('+100%', Kind.lessIsBetter), chalk.red)
test('getColor', async () => {
assert.equal(getColor('+100%', Kind.moreIsBetter), chalk.green)
assert.equal(getColor('-100%', Kind.moreIsBetter), chalk.red)
assert.equal(getColor('-100%', Kind.lessIsBetter), chalk.green)
assert.equal(getColor('+100%', Kind.lessIsBetter), chalk.red)
})

tap.test('formatValue', async t => {
t.test('should format generic integers', async t => {
t.equal(formatValue(1300, 'requests.total'), '1,300')
test('formatValue', async t => {
await t.test('should format generic integers', async () => {
assert.equal(formatValue(1300, 'requests.total'), '1,300')
})
t.test('should format latency value with unit', async t => {
t.equal(formatValue(100, 'latency.average'), '100ms')
await t.test('should format latency value with unit', async () => {
assert.equal(formatValue(100, 'latency.average'), '100ms')
})
t.test('should format throughput value with unit', async t => {
t.equal(formatValue(100, 'throughput.total'), '100 bytes')
await t.test('should format throughput value with unit', async () => {
assert.equal(formatValue(100, 'throughput.total'), '100 bytes')
})
})
3 changes: 1 addition & 2 deletions packages/autocannon-ui-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"dev": "npm start -- -P -l info -w",
"start": "fastify start -p 3001 ./index.js",
"test": "tap",
"test": "node --test",
"_test:qa": "newman run ./test/automation/Autocannon.postman_collection.json --bail -r cli,htmlextra --reporter-htmlextra-export .test_results/qa.html --reporter-htmlextra-darkTheme --bail --timeout-request 40000",
"test:qa": "wait-on tcp:3001 && npm run _test:qa",
"lint": "eslint ."
Expand All @@ -23,7 +23,6 @@
"newman": "^6.1.0",
"newman-reporter-htmlextra": "^1.20.4",
"prettier": "^3.0.1",
"tap": "^16.0.0",
"wait-on": "^8.0.1"
}
}
66 changes: 36 additions & 30 deletions packages/autocannon-ui-backend/test/unit/routes/compare.test.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,50 @@
import fs from 'fs'
import { test } from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'

import t from 'tap'
import Fastify from 'fastify'

import index from '../../../index.js'

t.test('compare', async t => {
test('compare', async t => {
const a = JSON.parse(
fs.readFileSync('test/fixtures/fixture-a.json').toString()
)
const b = JSON.parse(
fs.readFileSync('test/fixtures/fixture-b.json').toString()
)

t.test('compare: returns 200 for comparing two valid results', async t => {
const fastify = Fastify().register(index)
const response = await fastify.inject({
url: '/api/compare',
method: 'POST',
body: {
a,
b
}
})

t.same(response.statusCode, 200)
})

t.test('compare-v2: returns 200 for comparing two valid results', async t => {
const fastify = Fastify().register(index)

const response = await fastify.inject({
url: '/api/compare-v2',
method: 'POST',
body: {
a,
b
}
})
await t.test(
'compare: returns 200 for comparing two valid results',
async () => {
const fastify = Fastify().register(index)
const response = await fastify.inject({
url: '/api/compare',
method: 'POST',
body: {
a,
b
}
})

assert.equal(response.statusCode, 200)
}
)

t.same(response.statusCode, 200)
})
await t.test(
'compare-v2: returns 200 for comparing two valid results',
async () => {
const fastify = Fastify().register(index)
const response = await fastify.inject({
url: '/api/compare-v2',
method: 'POST',
body: {
a,
b
}
})

assert.equal(response.statusCode, 200)
}
)
})
14 changes: 8 additions & 6 deletions packages/autocannon-ui-backend/test/unit/routes/execute.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import t from 'tap'
import { test } from 'node:test'
import assert from 'node:assert/strict'

import Fastify from 'fastify'

import index from '../../../index.js'

t.test('execute', async t => {
t.test('returns 400 if url is not valid', async t => {
test('execute', async t => {
await t.test('returns 400 if url is not valid', async () => {
const fastify = Fastify().register(index)

const response = await fastify.inject({
Expand All @@ -15,10 +17,10 @@ t.test('execute', async t => {
}
})

t.same(response.statusCode, 400)
assert.equal(response.statusCode, 400)
})

t.test('supports localhost urls with port', async t => {
await t.test('supports localhost urls with port', async () => {
const fastify = Fastify().register(index)

const response = await fastify.inject({
Expand All @@ -29,6 +31,6 @@ t.test('execute', async t => {
}
})

t.same(response.statusCode, 200)
assert.equal(response.statusCode, 200)
})
})
1 change: 0 additions & 1 deletion packages/autocannon-ui-frontend/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"plugin:import/recommended",
"plugin:prettier/recommended",
"plugin:react-hooks/recommended",
"plugin:mocha/recommended"
],
"plugins": ["import"],
"env": {
Expand Down
6 changes: 2 additions & 4 deletions packages/autocannon-ui-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
"name": "autocannon-ui-frontend",
"version": "2.0.0",
"private": "true",
"type": "module",
"scripts": {
"dev": "vite --port 3000",
"build": "vite build",
"serve": "vite preview",
"lint": "eslint .",
"_test:qa": "mocha --timeout=60000 test/autocannon.test.js",
"_test:qa": "node --test test/autocannon.test.js --test-timout 60000",
"test:qa": "wait-on tcp:3000 && npm run _test:qa"
},
"dependencies": {
Expand All @@ -24,11 +25,8 @@
"devDependencies": {
"@babel/preset-react": "^7.18.6",
"@vitejs/plugin-react-refresh": "^1.3.1",
"chai": "^5.0.0",
"eslint-plugin-mocha": "^10.0.1",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^5.0.0",
"mocha": "^11.0.1",
"prop-types": "^15.7.2",
"puppeteer": "^23.0.2",
"vite": "^6.0.5"
Expand Down
53 changes: 30 additions & 23 deletions packages/autocannon-ui-frontend/test/autocannon.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const puppeteer = require('puppeteer')
import { test } from 'node:test'
import puppeteer from 'puppeteer'

describe('Autocannon UI Puppeteer Test', function () {
test('Autocannon UI Puppeteer Test', async t => {
let browser
let page

before(async function () {
t.before(async () => {
browser = await puppeteer.launch({
headless: true,
slowMo: 0,
Expand All @@ -14,36 +15,42 @@ describe('Autocannon UI Puppeteer Test', function () {
page = await browser.newPage()
})

after(async function () {
t.after(async () => {
await browser.close()
})

it('should run the test and can see the progress bar', async function () {
await t.test('should run the test and can see the progress bar', async () => {
await page.goto('http://localhost:3000/')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
await page.click('[data-testid="run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar')
})

it('should run the test and can cancel the progress bar', async function () {
await page.goto('http://localhost:3000/')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
await page.click('[data-testid="run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar')
await page.click('[data-testid="cancel-run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
})

it('should run the test and can clear the run test results', async function () {
await page.goto('http://localhost:3000/')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
await page.click('[data-testid="run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar')
await page.waitForSelector('[data-testid="clear-all-button"]')
await page.click('[data-testid="clear-all-button"]')
})
await t.test(
'should run the test and can cancel the progress bar',
async () => {
await page.goto('http://localhost:3000/')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
await page.click('[data-testid="run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar')
await page.click('[data-testid="cancel-run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
}
)

await t.test(
'should run the test and can clear the run test results',
async () => {
await page.goto('http://localhost:3000/')
await page.waitForSelector('span.MuiLinearProgress-bar', { hidden: true })
await page.click('[data-testid="run-button"]')
await page.waitForSelector('span.MuiLinearProgress-bar')
await page.waitForSelector('[data-testid="clear-all-button"]')
await page.click('[data-testid="clear-all-button"]')
}
)

it('should run the two tests and can compare them', async function () {
await t.test('should run the two tests and can compare them', async () => {
const navigationPromise = page.waitForNavigation({
waitUntil: 'domcontentloaded'
})
Expand Down

0 comments on commit 5ce041e

Please sign in to comment.