Skip to content

Commit 0d5f975

Browse files
committed
feat: Added skip option.
1 parent a30531a commit 0d5f975

24 files changed

+51
-58
lines changed

.swcrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ A test can be defined as a function containing the test to run or an object cont
5858
- `test`: The function containing the test to run. If omitted, the test will be a no-op.
5959
- `before`: A setup function to execute before starting test iteration.
6060
- `after`: A cleanup function to execute after all test iteration have been run.
61+
- `skip`: If a test should be skipped.
6162

6263
Each of the `test` functions above can be either a function, a function accepting a Node style callback or a function returning a promise (hence also async functions).
6364

package.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
"exports": "./dist/index.js",
2828
"types": "./dist/index.d.ts",
2929
"scripts": {
30-
"dev": "swc --strip-leading-paths --delete-dir-on-start -s -w -d dist src",
31-
"build": "swc --strip-leading-paths --delete-dir-on-start -d dist src",
32-
"postbuild": "concurrently npm:lint npm:typecheck",
30+
"build": "tsc -p .",
31+
"postbuild": "npm run lint",
3332
"format": "prettier -w src test",
3433
"lint": "eslint --cache",
35-
"typecheck": "tsc -p . --emitDeclarationOnly",
36-
"test": "cross-env TS_NODE_PROJECT=tsconfig.test.json c8 -c test/config/c8-local.json node --import @swc-node/register/esm-register --test test/*.test.ts",
37-
"test:ci": "cross-env TS_NODE_PROJECT=tsconfig.test.json c8 -c test/config/c8-ci.json node --import @swc-node/register/esm-register --test-reporter=tap --test test/*.test.ts",
34+
"typecheck": "tsc -p . --noEmit",
35+
"test": "c8 -c test/config/c8-local.json node --env-file=test/config/env --test test/*.test.ts",
36+
"test:ci": "c8 -c test/config/c8-ci.json node --env-file=test/config/env --test test/*.test.ts",
3837
"ci": "npm run build && npm run test:ci",
3938
"prepublishOnly": "npm run ci",
4039
"postpublish": "git push origin && git push origin -f --tags"
@@ -46,13 +45,10 @@
4645
"table": "^6.9.0"
4746
},
4847
"devDependencies": {
49-
"@cowtech/eslint-config": "10.2.0",
50-
"@swc/cli": "^0.6.0",
51-
"@swc/core": "^1.10.7",
48+
"@cowtech/eslint-config": "10.4.0",
5249
"@types/node": "^22.10.2",
5350
"c8": "^10.1.3",
54-
"chokidar": "^4.0.3",
55-
"concurrently": "^9.1.1",
51+
"cleaner-spec-reporter": "^0.3.1",
5652
"cross-env": "^7.0.3",
5753
"eslint": "^9.17.0",
5854
"prettier": "^3.4.2",

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
type Result,
1010
type Results,
1111
type Tests
12-
} from './models.js'
13-
import { printResults } from './print.js'
12+
} from './models.ts'
13+
import { printResults } from './print.ts'
1414

1515
type PromiseResolver<T> = (value: T) => void
1616
type PromiseRejecter = (err: Error) => void
1717

18-
export * from './models.js'
18+
export * from './models.ts'
1919

2020
function scheduleNextTest(context: Context): void {
2121
// We still have work to do
@@ -106,7 +106,7 @@ export function cronometro(
106106
cb?: Callback
107107
): Promise<Results> | void {
108108
if (!isMainThread) {
109-
workerData.tests = Object.entries(tests)
109+
workerData.tests = Object.entries(tests).filter(test => test[1]?.skip !== true)
110110
return
111111
}
112112

@@ -174,7 +174,7 @@ export function cronometro(
174174
iterations,
175175
errorThreshold: errorThreshold / 100,
176176
print,
177-
tests: Object.entries(tests), // Convert tests to a easier to process [name, func] list,
177+
tests: Object.entries(tests).filter(test => test[1]?.skip !== true), // Convert tests to a easier to process [name, func] list,
178178
results: {},
179179
current: 0,
180180
callback,

src/models.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Histogram } from 'hdr-histogram-js'
2-
import { resolve, dirname } from 'node:path'
32
import { fileURLToPath } from 'node:url'
43
import { type Worker } from 'node:worker_threads'
54

@@ -27,12 +26,13 @@ export interface Options {
2726
export type StaticTest = () => any
2827
export type AsyncTest = (cb: Callback) => any
2928
export type PromiseTest = () => Promise<any>
30-
export type TestFunction = StaticTest | AsyncTest | PromiseTest
29+
export type TestFunction = (StaticTest | AsyncTest | PromiseTest) & { skip?: boolean }
3130

3231
export interface Test {
3332
test?: TestFunction
3433
before?: SetupFunction
3534
after?: SetupFunction
35+
skip?: boolean
3636
}
3737

3838
export type Percentiles = Record<string, number>
@@ -100,9 +100,4 @@ export const defaultOptions = {
100100

101101
export const percentiles = [0.001, 0.01, 0.1, 1, 2.5, 10, 25, 50, 75, 90, 97.5, 99, 99.9, 99.99, 99.999]
102102

103-
export const runnerPath = resolve(
104-
dirname(fileURLToPath(import.meta.url))
105-
.replace('src', 'dist')
106-
.replace(/models.(js|ts)/, ''),
107-
'./runner.js'
108-
)
103+
export const runnerPath = fileURLToPath(new URL(`./runner.${import.meta.url.slice(-2)}`, import.meta.url))

src/print.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clean, colorize } from 'acquerello'
22
import { table } from 'table'
3-
import { type Results } from './models.js'
3+
import { type Results } from './models.ts'
44

55
const styles = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray']
66

src/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* c8 ignore start */
22
import { isMainThread, parentPort, workerData } from 'node:worker_threads'
3-
import { type WorkerContext } from './models.js'
4-
import { runWorker } from './worker.js'
3+
import { type WorkerContext } from './models.ts'
4+
import { runWorker } from './worker.ts'
55

66
if (isMainThread) {
77
throw new Error('Do not run this file as main script.')

src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
type TestContext,
77
type TestFunction,
88
type WorkerContext
9-
} from './models.js'
9+
} from './models.ts'
1010

1111
function noOp(): void {
1212
// No-op

test.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/asyncImport.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { deepStrictEqual, ifError, ok } from 'node:assert'
22
import { test } from 'node:test'
33
import { isMainThread } from 'node:worker_threads'
4-
import { cronometro, percentiles } from '../src/index.js'
4+
import { cronometro, percentiles } from '../src/index.ts'
55

66
await new Promise(resolve => setTimeout(resolve, 100))
77

0 commit comments

Comments
 (0)