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

Add JS summary handlers and some tests #20

Merged
merged 7 commits into from
Jan 20, 2021
Merged

Add JS summary handlers and some tests #20

merged 7 commits into from
Jan 20, 2021

Conversation

na--
Copy link
Member

@na-- na-- commented Jan 19, 2021

Sorry the code is kind of 🤮 I was restricted by the need to support k6's base compatibility mode, and I closely followed the Go code in k6 and Go's stdlib in the manual transpilation, so that the results of the first version maximally resemble the current k6 text summary... 😞 We can change these things in the future, and we should definitely add more tests and probably refactor the code to be less of a pile of functions, but this should do for an alpha version, I think.

This closes grafana/k6#1120, since it contains a very basic version of a JUnit-generating function.

@na--
Copy link
Member Author

na-- commented Jan 19, 2021

Erm despite the green checkmark, the tests seem to have been failing with a script error for a long time... See https://app.circleci.com/pipelines/github/loadimpact/jslib.k6.io/101/workflows/83419271-12e2-474f-a49b-aa395a8f5a62/jobs/224:

ERRO[0008] TypeError: Value is not an object: undefined
	at file:///home/circleci/jslib.k6.io/tests/testSuite.js:25:22(4)  executor=shared-iterations scenario=default source=stacktrace

running (00m00.1s), 0/1 VUs, 1 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs  00m00.0s/10m0s  1/1 shared iters

    data_received........: 0 B 0 B/s
    data_sent............: 0 B 0 B/s
    iteration_duration...: avg=42.55µs min=42.55µs med=42.55µs max=42.55µs p(90)=42.55µs p(95)=42.55µs
    iterations...........: 1   15.751111/s

No checks whatsoever, but 0 exit code... grafana/k6#1769 will make this easier, but for now I'll add a try / catch block to fail the tests on script errors. And then fix the issue...

@na--
Copy link
Member Author

na-- commented Jan 20, 2021

Here is a test script I use to compare the new JS summary and the old Go-based summary: https://gist.github.com/na--/d68652c21a83821d0542bd52850eae28

I basically compare stdout-old.txt and stdout-new.txt - there are some differences in the color positioning due to newlines, but they shouldn't matter. Instead of fancy tests for textSummary, I can make one that uses a snapshot of raw-data.json from that file and generates the summary from it, comparing it to the stdout-new.txt contents? After carefully verifying the summary by eye, that should be good enough, or at least better than nothing?

@legander
Copy link
Collaborator

Holy moly lots of GO code! Do you want me to review the code or just verifying the output?
Do you wanna release it as 0.0.1-alpha or is 0.0.1 enough?
Thanks for fixing the test case running! 🙏
The formatting gotta stay prettier though, so it is going to get formatted to 2 spaces, sorry about that.

@na--
Copy link
Member Author

na-- commented Jan 20, 2021

Holy moly lots of GO code! Do you want me to review the code or just verifying the output?

Yeah... Sorry for the Go-style of code, but as I said, I decided to almost literally translate what currently exists in k6 as the first step. Once we have that and some more tests, we can refactor it and remove superfluous things (strWidth probably needs to go or be significantly changed). So, basically, if you ignore the unidiomatic JS, can you take a quick look and see if anything seems wrong. I am especially concerned about the functions that work with numbers, since numbers are a bit finicky in JS, so basically humanizeValue() and all of its sub-functions. I've added tests for them, but I am pretty sure I have missed a few corner cases.

Do you wanna release it as 0.0.1-alpha or is 0.0.1 enough?

0.0.1 is enough, I think, the code is at least usable...

The formatting gotta stay prettier though, so it is going to get formatted to 2 spaces, sorry about that.

Ah, sorry, I missed that, will fix it after lunch

Copy link
Contributor

@mstoykov mstoykov left a comment

Choose a reason for hiding this comment

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

LGTM

@na--
Copy link
Member Author

na-- commented Jan 20, 2021

@legander, I fixed the formatter back to Prettier. I didn't have that VSCode module installed, so I think I just clicked Yes when it complained and suggested to change it to something else... And I don't really care about the indentation, though the lack of semicolons is giving me anxiety 😅

Copy link
Contributor

@imiric imiric left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just some nitpicks. Agree that having tests with the actual rendered summary would be good, as well as refactoring it to use "classes", etc., but we can address that later.

I'll give it a test later today.

lib/k6-summary/0.0.1/index.js Outdated Show resolved Hide resolved
lib/k6-summary/0.0.1/index.js Outdated Show resolved Hide resolved
lib/k6-summary/0.0.1/index.js Outdated Show resolved Hide resolved
@na--
Copy link
Member Author

na-- commented Jan 20, 2021

@imiric I am currently adding a few simple tests that use raw-data.json from a real test and compare, will hopefully post them in the next hour. Not ideal, but better than nothing and would make the refactoring easier.

@legander
Copy link
Collaborator

Didn't get a chance yet to review, will hopefully be able to later today.

@na--
Copy link
Member Author

na-- commented Jan 20, 2021

@legander, thanks! I'm going to merge this in a bit, since we link to it in the v0.30.0 release notes, but if you find any major bugs in your review we can just update the 0.0.1 version, since we're not changing the API. Or release v0.0.2 and update the release notes.

@legander
Copy link
Collaborator

Aight! Don't forget to add it to supported.json and run yarn run generate-homepage to update the index page if you want it to show up under "Available libs" @na--

@na--
Copy link
Member Author

na-- commented Jan 20, 2021

Didn't know I had to do that 😅 Thanks! 🙇

I probably should have read https://github.com/loadimpact/jslib.k6.io#how-to-add-a-new-js-package 🤦‍♂️ 🙄

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.

Output check/threshold results in a machine-readable unit test format to publish test results in CI
4 participants