Files
node/test/parallel/test-trace-events-get-category-enabled-buffer.js
2026-09-24 17:30:20 +00:00

47 lines
1.3 KiB
JavaScript

'use strict';
// Flags: --expose-internals
const common = require('../common');
const { it } = require('node:test');
try {
require('trace_events');
} catch {
common.skip('missing trace events');
}
// Perfetto aborts on a category that is not in its static registry, and its
// enabled flag does not follow createTracing().enable().
common.skipIfPerfettoEnabled();
const { createTracing, getEnabledCategories } = require('trace_events');
const assert = require('assert');
const { categoryEnabledChecker } = require('internal/trace_events');
it('should track enabled/disabled categories', () => {
const random = Math.random().toString().slice(2);
const category = `node.${random}`;
const isEnabled = categoryEnabledChecker(category);
const tracing = createTracing({
categories: [category],
});
assert.strictEqual(isEnabled(), false);
tracing.enable();
let currentCategories = getEnabledCategories();
assert.ok(currentCategories.includes(category), `the getEnabledCategories should include ${category}, got: ${currentCategories}`);
assert.strictEqual(isEnabled(), true);
tracing.disable();
currentCategories = getEnabledCategories();
assert.ok(currentCategories === undefined, `the getEnabledCategories should return undefined, got: ${currentCategories}`);
assert.strictEqual(isEnabled(), false);
});