Skip to content

Commit

Permalink
fix(NODE-6357): strip version/branch/tag from test name (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Sep 3, 2024
1 parent 9567aa3 commit 043a590
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/bson-bench/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class Suite {
(e: Error) => e
);
if (result instanceof Error) {
console.log(`\t${task.taskName} ✗`);
console.log(`\t${task.testName} ✗`);
this._errors.push({ task, error: result });
} else {
console.log(`\t${task.taskName} ✓`);
console.log(`\t${task.testName} ✓`);
this._results.push(result);
}
}
Expand Down
5 changes: 4 additions & 1 deletion packages/bson-bench/src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Task {
result: BenchmarkResult | undefined;
benchmark: BenchmarkSpecification;
taskName: string;
testName: string;
/** @internal */
children: ChildProcess[];
/** @internal */
Expand All @@ -33,6 +34,8 @@ export class Task {
this.taskName = `${path.basename(this.benchmark.documentPath, 'json')}_${
this.benchmark.operation
}_${this.benchmark.library}`;

this.testName = this.taskName.substring(0, this.taskName.search(/#|@/));
}

/**
Expand Down Expand Up @@ -111,7 +114,7 @@ export class Task {

const perfSendResults: PerfSendResult = {
info: {
test_name: this.taskName,
test_name: this.testName,
args: {
warmup: this.benchmark.warmup,
iterations: this.benchmark.iterations,
Expand Down
18 changes: 14 additions & 4 deletions packages/bson-bench/test/unit/task.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ describe('Task', function () {
context('#run()', function () {
for (const test of testTable) {
context(`${test.operation} with library specifier: ${test.library}`, function () {
let task;

beforeEach(function () {
task = new Task(test);
});

it('completes successfully', async function () {
if (
Number(process.versions.node.split('.')[0]) >= 20 &&
Expand All @@ -50,14 +56,18 @@ describe('Task', function () {
console.log('Skipping installing bson-ext via git tag on Node 20');
this.skip();
}
const task = new Task(test);

await task.run();
for (const child of task.children) {
expect(child.exitCode).to.not.be.null;
expect(child.exitCode).to.equal(0);
}
});

it('strips the tag or commit from the test name', function () {
expect(task.testName).to.not.include(test.library);
expect(task.testName).to.match(/bson|bson-ext/);
});
});
}

Expand Down Expand Up @@ -138,7 +148,7 @@ describe('Task', function () {
});

it('returns results as an object', async function () {
expect(results.info).to.haveOwnProperty('test_name', task.taskName);
expect(results.info).to.haveOwnProperty('test_name', task.testName);
expect(results.info).to.haveOwnProperty('args');
});

Expand Down Expand Up @@ -240,12 +250,12 @@ describe('Task', function () {
options: { promoteLongs: true }
});

expectedFileName = `${task.taskName}.json`;
expectedFileName = `${task.testName}.json`;
if (await exists(expectedFileName)) await rm(expectedFileName);
});

after(async () => {
expectedFileName = `${task.taskName}.json`;
expectedFileName = `${task.testName}.json`;
if (await exists(expectedFileName)) await rm(expectedFileName);
});

Expand Down

0 comments on commit 043a590

Please sign in to comment.