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

Show individual and total test execution time #30

Closed
wellwelwel opened this issue Feb 26, 2024 · 6 comments · Fixed by #359
Closed

Show individual and total test execution time #30

wellwelwel opened this issue Feb 26, 2024 · 6 comments · Fixed by #359

Comments

@wellwelwel
Copy link
Owner

wellwelwel commented Feb 26, 2024

Inspiration

erick

Source: https://youtu.be/iDaBo7ge604?si=x8hWjOH8ffHHOJ_6&t=2674
Credits to @ErickWendel 🇧🇷

@ErickWendel
Copy link

thanks a lot!! I also have it in English on that channel o/

@wellwelwel wellwelwel pinned this issue Mar 1, 2024
@1NxT
Copy link

1NxT commented Apr 17, 2024

Something like that?
image

@wellwelwel
Copy link
Owner Author

Thanks, @1NxT 🚀

I think (0.000000ms) should be good.

The idea would be:

  • If the user use test, it will show the execution time for each test performed
  • At the end of each file (using test method or not), it will show the total for each file
  • On exit, it will show the final total of the tests

It's important to note that Poku's assert simplify the test process by turning test, describe and it in a simple assert(true, "Describing it"), so it's not necessary to include an execution time for each assertion 🙋🏻‍♂️

For example:

A) Shows only the file and total execution time:

import { assert } from 'poku';

assert.strictEqual(1, 1, 'Describing it');

B) Shows both the test, file and total execution times:

import { test, assert } from 'poku';

// This should show the execution time
test(() => {
  // This is just an assertion
  assert.strictEqual(1, 1, 'Describing it too');
});

Feel free to discuss it 🤝

@1NxT
Copy link

1NxT commented Apr 17, 2024

I was reading the code trying console log the time, I used the file parseAsssetion.ts to try to measure the time of each assert.

  var startTime = performance.now();
  const isPoku =
    typeof process.env?.FILE === 'string' && process.env?.FILE.length > 0;
  const FILE = process.env.FILE;

  try {
    ...

    if (typeof options.message === 'string') {
      var endTime = performance.now();
      const message = isPoku
        ? `${format.bold(format.success(`✔ ${options.message}`))} ${format.dim(format.success(`› ${FILE}`))} ${format.dim(`(${(endTime - startTime).toFixed(6)}ms)`)}`
        : format.bold(format.success(`✔ ${options.message}`)) + ` ${format.dim(`(${(endTime - startTime).toFixed(6)}ms)`)}`;

      console.log(message);
    }

But I don't know if it's a good approach.

@wellwelwel
Copy link
Owner Author

wellwelwel commented Apr 17, 2024

I was reading the code trying console log the time

@1NxT, I believe that perf_hooks would be a good approach (I didn't get to try it):

import { performance } from 'node:perf_hooks';

const start = performance.now();
const end = performance.now();
const total = (end - start).toFixed(6);

We could begin with the total time per file:

Start:

if (!(await beforeEach(fileRelative, configs))) return false;

End:

if (!(await afterEach(fileRelative, configs))) return false;


Note to self

It would be interesting not to affect the execution time of the test itself with the Poku process, but we could think about this later.

@wellwelwel wellwelwel changed the title Show idividual and total test execution time Show individual and total test execution time May 17, 2024
@wellwelwel
Copy link
Owner Author

wellwelwel commented Jun 10, 2024

Happy to close one of the project's first issues 🎉


Sequential Example

Screenshot 2024-06-10 at 06 06 14

Parallel Example

Screenshot 2024-06-10 at 06 07 56

@wellwelwel wellwelwel unpinned this issue Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants