-
Notifications
You must be signed in to change notification settings - Fork 20
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
Introduce TypeScript and an integration test #45
Conversation
0141486
to
1eb13c0
Compare
Woah! |
A README.md which gave a quick summary of the commands needed to build / test this repo would be very useful 😁 |
Along with any details about dependency/framework maintenance going forward. |
af3b343
to
6eebf2e
Compare
Thanks! I've added a CONTRIBUTING.md and, while I was at it, a workflow to automatically run tests/linting/builds on CI.
Not sure what you would like to see for this. Could you give me some more details? Thanks! |
I dunno, just whatever dependency hell we might need to know about upgrading jest, npm stuff (just npm audit --force?), etc. Just a line or two for anyone that isn't familiar with the tech(s). |
Like running |
|
Not that I'm aware of. If something comes to my mind over the next days, I'll add it, but the setup is optimized for just working, as this package most likely won't see that much love compared to others :) |
@psiinon quick bump |
Is it usual that the main code is mixed with test code? Doesn't it allow to split that per dir? |
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
This will compile with errors, but the result will be the same JavaScript files as before (apart from styling and adding strict). Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
This adds type annotations to solve all type problems that can be solved without changing the code itself Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
On one hand, this is a good idea in general. But also the code as it is written already relies on a newer interface than the version that was set before. This didn't come up as the current code isn't yet in use in the other actions, but would break the code if released like this. Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
It was done implicitly before, which TypeScript doesn't like Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]> Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]>
The jest GitHub reporter is also relying on fs to interact with the file system. If the full module is mocked, then the reporters fails. Only mock the function that needs to be mocked, and reset it back after the test is finished Signed-off-by: Daniel Bartholomae <[email protected]>
They should be ignored by the user's gitignore instead. Signed-off-by: Daniel Bartholomae <[email protected]>
Signed-off-by: Daniel Bartholomae <[email protected]>
0595949
to
5b90157
Compare
That's a stylistic preference. I have a strong preference for having test files directly next to the files under test, as it makes it easier to find them, and e.g. if a file changes directory it is easier to also relocate the file as there are no two separate folder structures to maintain. |
Signed-off-by: Daniel Bartholomae <[email protected]>
@psiinon another reminder |
@psiinon Hi Simon, do you know when you will be able to check the PR? Otherwise I would go ahead with a fork and release that for now, and we can potentially move the fork back into the zaproxy organisation some time in the future. |
I know it's not an issue, it's a matter of organization. No big deal for me. |
A test is failing for me locally:
Might be better to create a PR just adding the CI and merge it before this one, to get the checks running here. |
Huh, that's weird. I have CI already running on my fork, and it's green. Do you have any global npm packages installed that might interfere with local versions? Which version of Node are you running? |
Could be related to the way that I currently mock the file system. Not sure why it doesn't show up on CI or locally, though, as I work on Windows and CI on Linux, which already covers two file systems. |
That's basically what this PR is: it is not introducing any new functionality, but adds the functionality to run tests. We could add the workflow file only on a separate branch which would lead to a failing workflow (as there are no tests) so that it can run on this PR if we want. |
Most likely not, how should I check that? (I don't use npm often.) I followed the steps provided in the docs, if other changes are needed would be better to point that out.
I used macOS.
No, adding the CI workflow does not require doing any changes nor running the tests (once merged it would run with these changes though, hopefully). Anyway, good to see passing in CI already. |
Signed-off-by: Daniel Bartholomae <[email protected]>
Mocking the file system this way does not work on Mac. Running tests on CI will ensure that Mac users don't introduce regressions. Signed-off-by: Daniel Bartholomae <[email protected]>
The linter checks for these, and otherwise checking out on windows will create CRLF line endings Signed-off-by: Daniel Bartholomae <[email protected]>
I can confirm that mocking the file system does not seem to work on Mac by running it on Mac in CI. Unfortunately, the current way the script is written requires mocking the file system for the e2e test. This will be less of a problem for future changes, as these can be driven by unit tests instead of e2e tests. To solve it, I now skip the test on Mac only. I've also set up CI to run the repo on Linux, Mac, and Windows to detect these kinds of problems. |
Thank you! |
"outDir": "dist" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["src/**/*.test.ts"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the mocks and fixtures being excluded as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case not a blocker for me, can be tweaked after merge if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Will address in next PR to not require an additional review of this one :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And, just in case this isn't clear: This change wouldn't affect the users of the GitHub action, as the action is build via a bundler that anyways only bundles files that are used by the actual production code, so at that step all fixtures, tests, and test helpers would be ignored)
Thanks @dbartholomae and sorry this took so long to review. As you can see we need help with the actions 😁 |
Thanks! I've written #48 to plan the next steps and would love your feedback on that before I continue :) |
As discussed, I've moved the code to TypeScript, added linting and prettification as well as an integration test to make it easier for adding more tests.
Happy to also jump onto a call for a sync review if that is easier. If you review this async, I recommend going commit by commit. I've tried to group them in a way that makes it possible to review them one commit at a time.
Some things of note:
package.json
was still on an old version. The released version that is in use in the actual actions is not using what is currently in this repo in the master branch, but after the changes I did, things should work now (as confirmed by the integration test).request
, I assume because it was installed as a global dependency on the machine of the person who built and published this package.Report
,Site
,Alert
, andInstance
are based on what should be in the JSON output file, so it would be great if you could double check them and confirm the following:site
@name
, but it might not have an array ofalerts
name
,pluginid
, an array ofinstances
and (not yet in this PR but the info will be needed for the next) bothriskcode
as well asconfidence
which only can have the values given at https://www.zaproxy.org/docs/constants/