GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: split test-perf-hooks-timerify · nodejs/node@22fd621

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-perf-hooks-timerify-basic.js
    • test-perf-hooks-timerify-constructor.js
    • test-perf-hooks-timerify-error.js
    • test-perf-hooks-timerify-histogram-async.mjs
    • test-perf-hooks-timerify-histogram-sync.mjs
    • test-perf-hooks-timerify-invalid-args.js
    • test-perf-hooks-timerify-multiple-wrapping.js
    • test-perf-hooks-timerify-return-value.js
    • test-perf-hooks-timerify.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-perf-hooks-timerify-basic.js‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test basic functionality of timerify and PerformanceObserver.
2+
'use strict';
3+
4+
const common = require('../common');
5+
const assert = require('assert');
6+
const { timerify, PerformanceObserver } = require('perf_hooks');
7+
8+
// Verifies that `performance.timerify` is an alias of `perf_hooks.timerify`.
9+
assert.strictEqual(performance.timerify, timerify);
10+
11+
// Intentional non-op. Do not wrap in common.mustCall();
12+
const n = timerify(function noop() {});
13+
14+
const obs = new PerformanceObserver(common.mustCall((list) => {
15+
const entries = list.getEntries();
16+
const entry = entries[0];
17+
assert(entry);
18+
assert.strictEqual(entry.name, 'noop');
19+
assert.strictEqual(entry.entryType, 'function');
20+
assert.strictEqual(typeof entry.duration, 'number');
21+
assert.strictEqual(typeof entry.startTime, 'number');
22+
obs.disconnect();
23+
}));
24+
obs.observe({ entryTypes: ['function'] });
25+
n();
Collapse file

‎test/parallel/test-perf-hooks-timerify-constructor.js‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Test that timerify works with class constructors and creates performance
2+
// entries with the correct name.
3+
4+
'use strict';
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const { timerify, PerformanceObserver } = require('perf_hooks');
9+
10+
class N {}
11+
const n = timerify(N);
12+
13+
const obs = new PerformanceObserver(common.mustCall((list) => {
14+
const entries = list.getEntries();
15+
const entry = entries[0];
16+
assert.strictEqual(entry[0], 1);
17+
assert.strictEqual(entry[1], 'abc');
18+
assert(entry);
19+
assert.strictEqual(entry.name, 'N');
20+
assert.strictEqual(entry.entryType, 'function');
21+
assert.strictEqual(typeof entry.duration, 'number');
22+
assert.strictEqual(typeof entry.startTime, 'number');
23+
obs.disconnect();
24+
}));
25+
obs.observe({ entryTypes: ['function'] });
26+
27+
new n(1, 'abc');
Collapse file

‎test/parallel/test-perf-hooks-timerify-error.js‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test that errors thrown in timerified functions bubble up without creating
2+
// performance timeline entries.
3+
4+
'use strict';
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const { timerify, PerformanceObserver } = require('perf_hooks');
9+
10+
const obs = new PerformanceObserver(common.mustNotCall());
11+
obs.observe({ entryTypes: ['function'] });
12+
const n = timerify(() => {
13+
throw new Error('test');
14+
});
15+
assert.throws(() => n(), /^Error: test$/);
16+
obs.disconnect();
Collapse file

‎test/parallel/test-perf-hooks-timerify-histogram-async.mjs‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test that timerify works with histogram option for asynchronous functions.
2+
3+
import '../common/index.mjs';
4+
import assert from 'assert';
5+
import { createHistogram, timerify } from 'perf_hooks';
6+
import { setTimeout as sleep } from 'timers/promises';
7+
8+
const histogram = createHistogram();
9+
const m = async (a, b = 1) => {
10+
await sleep(10);
11+
};
12+
const n = timerify(m, { histogram });
13+
assert.strictEqual(histogram.max, 0);
14+
for (let i = 0; i < 10; i++) {
15+
await n();
16+
}
17+
assert.notStrictEqual(histogram.max, 0);
Collapse file

‎test/parallel/test-perf-hooks-timerify-histogram-sync.mjs‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Test that timerify works with histogram option for synchronous functions.
2+
3+
import '../common/index.mjs';
4+
import assert from 'assert';
5+
import { createHistogram, timerify } from 'perf_hooks';
6+
import { setTimeout as sleep } from 'timers/promises';
7+
8+
let _deadCode;
9+
10+
const histogram = createHistogram();
11+
const m = (a, b = 1) => {
12+
for (let i = 0; i < 1e3; i++)
13+
_deadCode = i;
14+
};
15+
const n = timerify(m, { histogram });
16+
assert.strictEqual(histogram.max, 0);
17+
for (let i = 0; i < 10; i++) {
18+
n();
19+
await sleep(10);
20+
}
21+
assert(_deadCode >= 0);
22+
assert.notStrictEqual(histogram.max, 0);
Collapse file

‎test/parallel/test-perf-hooks-timerify-invalid-args.js‎

Copy file name to clipboard
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test that timerify throws appropriate errors for invalid argument types.
2+
3+
'use strict';
4+
5+
require('../common');
6+
const assert = require('assert');
7+
const { timerify } = require('perf_hooks');
8+
9+
[1, {}, [], null, undefined, Infinity].forEach((input) => {
10+
assert.throws(() => timerify(input),
11+
{
12+
code: 'ERR_INVALID_ARG_TYPE',
13+
name: 'TypeError',
14+
message: /The "fn" argument must be of type function/
15+
});
16+
});
17+
18+
const asyncFunc = async (a, b = 1) => {};
19+
const syncFunc = (a, b = 1) => {};
20+
21+
[1, '', {}, [], false].forEach((histogram) => {
22+
assert.throws(() => timerify(asyncFunc, { histogram }), {
23+
code: 'ERR_INVALID_ARG_TYPE'
24+
});
25+
assert.throws(() => timerify(syncFunc, { histogram }), {
26+
code: 'ERR_INVALID_ARG_TYPE'
27+
});
28+
});
Collapse file

‎test/parallel/test-perf-hooks-timerify-multiple-wrapping.js‎

Copy file name to clipboard
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Test that functions can be wrapped multiple times and verify length and name
2+
// properties are preserved correctly.
3+
4+
'use strict';
5+
6+
require('../common');
7+
const assert = require('assert');
8+
const { timerify } = require('perf_hooks');
9+
10+
const m = (a, b = 1) => {};
11+
const n = timerify(m);
12+
const o = timerify(m);
13+
const p = timerify(n);
14+
assert.notStrictEqual(n, o);
15+
assert.notStrictEqual(n, p);
16+
assert.notStrictEqual(o, p);
17+
assert.strictEqual(n.length, m.length);
18+
assert.strictEqual(n.name, 'timerified m');
19+
assert.strictEqual(p.name, 'timerified timerified m');
Collapse file

‎test/parallel/test-perf-hooks-timerify-return-value.js‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression tests for https://github.com/nodejs/node/issues/40623
2+
// Test that timerify preserves return values and class constructor behavior.
3+
4+
'use strict';
5+
6+
require('../common');
7+
const assert = require('assert');
8+
const { timerify } = require('perf_hooks');
9+
10+
assert.strictEqual(timerify(function func() {
11+
return 1;
12+
})(), 1);
13+
assert.strictEqual(timerify(function() {
14+
return 1;
15+
})(), 1);
16+
assert.strictEqual(timerify(() => {
17+
return 1;
18+
})(), 1);
19+
class C {}
20+
const wrap = timerify(C);
21+
assert.ok(new wrap() instanceof C);
22+
assert.throws(() => wrap(), {
23+
name: 'TypeError',
24+
});
Collapse file

‎test/parallel/test-perf-hooks-timerify.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-perf-hooks-timerify.js
-154Lines changed: 0 additions & 154 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.