Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bun/test): Allow functions as first arg to describe blocks #17218

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

reillyjodonnell
Copy link

@reillyjodonnell reillyjodonnell commented Feb 10, 2025

What does this PR do?

Allows user to pass a function as the first argument to describe. fixes #17100
Before these changes if you pass a function you:

  1. get a ts error
  2. Bun silently stops the test execution beyond the describe block and doesn't fail
  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

I wrote a passing test at test/js/bun/test/describe.test.ts

@RiskyMH
Copy link
Member

RiskyMH commented Feb 10, 2025

nice, i think you should also make a test that runs bun test as child process and ensure the function name was used correctly (and not just [object object] or smth)

@reillyjodonnell
Copy link
Author

nice, i think you should also make a test that runs bun test as child process and ensure the function name was used correctly (and not just [object object] or smth)

Great suggestion - just added additional testing against the name

@DonIsaac DonIsaac changed the title Allows function as first arg to describe block feat(bun/test): Allow functions as first arg to describe blocks Feb 21, 2025
});

test("both blocks should have run", () => {
expect(functionBlockRan).toBeTrue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use jest.fn to create a mock, then use expect(fn).toHaveBeenCalled()

@@ -1725,7 +1725,7 @@ inline fn createScope(
var function = if (args.len > 1) args[1] else .zero;
var options = if (args.len > 2) args[2] else .zero;

if (description.isEmptyOrUndefinedOrNull() or !description.isString()) {
if (description.isEmptyOrUndefinedOrNull() or (description.isFunction() and description.getName(globalThis).isEmpty())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if

describe(MyClass, function testMyClass() {
  // ...
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also interested in how far Jest goes with this too

test("describe block shows function name correctly in test output", async () => {
const test_dir = tmpdirSync();
try {
await writeFile(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll find tempDirWithFiles useful here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support functions as the description for describe
3 participants