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

refactor: Extract statement construction functions, use async/await, begin extracting tests. #274

Merged
merged 5 commits into from
Oct 6, 2024

Conversation

emmanuel
Copy link
Contributor

@emmanuel emmanuel commented Aug 23, 2024

Main thing here is extracting statement construction from other logic.

First goal is to support simpler and more extensive testing of statement construction (see cmi5-statements.spec.ts), but secondarily it opens up the library to additional (unforeseen) use-cases by providing CMI5-compliant xAPI statement construction ala carte from the LRS client. If you're into patterns, this PR could be described as an application of the "single responsibility principle" pattern (statement construction vs LRS communication).

Stylistically, this de-emphasizes classes and focuses on functions and data types.

@emmanuel emmanuel force-pushed the feat/use-async-await branch from 8eb2d97 to be8756c Compare August 23, 2024 19:17
@CookieCookson
Copy link
Contributor

@emmanuel This is a really helpful contribution, thank you! If you get it rebased I can give it a more thorough review next week, at first glance it is a nice refactor and test addition.

Much of the variation in testing can be handled by validating statement construction. Almost all of it, really, with the notable exceptions of `initialize()` and `moveOn()`.

Anyhow, I intend to extract the remaining statement tests from the `Cmi5` class tests (`cmi5.spec.ts`), and to extend the statement tests to cover more cases.
@emmanuel emmanuel force-pushed the feat/use-async-await branch from be8756c to 27134f8 Compare August 30, 2024 18:22
@emmanuel
Copy link
Contributor Author

@CookieCookson Great! I'm glad this looks like a useful contribution. And thanks for the encouragement!

I rebased and tests still pass locally.

@emmanuel
Copy link
Contributor Author

emmanuel commented Aug 30, 2024

Actually, regarding the tests: I dropped the mocking of time in the statement tests, which mostly works, but occasionally fails. IOW, I introduced a flaky test.

I have a thought about how to address that (my intention is to do so without returning to mocking), but it's not implemented here. Right now, if you get a test failure on the duration tests like this:

    Expected: "PT2H6M33S"
    Received: "PT2H6M33.001S"

That's the flake. Re-run the tests (maybe more than once) and it will pass. I've only seen the failure locally (not in CI), but it could happen in CI, too.

@emmanuel
Copy link
Contributor Author

Hi @CookieCookson, how's it going?

Have you had a chance to review this? Is there anything I can do to help?

@CookieCookson
Copy link
Contributor

@emmanuel I've not had any time again, sorry. I will see if I can get some time this week to investigate the flaky test(s). I can see it just being from slow execution time or a rounding error.

@emmanuel
Copy link
Contributor Author

emmanuel commented Sep 29, 2024 via email

@emmanuel
Copy link
Contributor Author

emmanuel commented Oct 4, 2024

@CookieCookson alright, I resolved the flake.

In lieu of mocking, stubbing, or adding a dependency (e.g., .toBeOneOf() from https://github.com/jest-community/jest-extended), I took a ... creative ... approach. Viz., I flipped actual and expected in order to leverage the built-in .toContain() matcher 😁.

@emmanuel
Copy link
Contributor Author

emmanuel commented Oct 4, 2024

I'd be delighted to see this land soon.

Please let me know if there's anything else you'd like to see before merging this.

@CookieCookson
Copy link
Contributor

Excellent and creative resolution - great job! I should have time this weekend to get this reviewed and released.

Did you see my comment on the other closed PR? I'm concerned about how you may actually consume the changes made as it doesn't seem that anything new is being exported.

@emmanuel
Copy link
Contributor Author

emmanuel commented Oct 5, 2024

@CookieCookson thanks for looking again.

I looked back at the last PR ("support Cmi5 from the backend"), and I think you're referring to this comment, and yet ...I'm confused 🤔.

The AbstractCmi5 class is exported as the default for the file in the original PR, and that remains the case in this PR. Also, all of the statement creation functions are exported.

So... to what were you referring?

@CookieCookson
Copy link
Contributor

I was thinking that with needing to use this on the backend, you will need to install the package and import the Abstract CMI class. When this package builds, it uses the original Cmi5 class as the entry point so you will be forced to use the class that uses the browser APIs which you may be trying to avoid. I may be confused here too, it would be good to have a code example of how you plan on consuming the Abstract CMI class in another project.

@CookieCookson CookieCookson merged commit d463878 into xapijs:develop Oct 6, 2024
5 checks passed
@CookieCookson
Copy link
Contributor

@emmanuel I finally found some time to give this the time it needs! The code change was substantial so it took a fair while to review but its lots of good stuff. All merged, this plus your previous contributions plus some security vulnerability patches have been released into @xapi/cmi5@1.4.0.

A huge thank you for your contributions on this project, and an apology that its taken months and months to get these code changes out into the wild.

Is #265 now ready to be closed up or are there additional code changes still required for this?

@emmanuel
Copy link
Contributor Author

emmanuel commented Oct 7, 2024

I went ahead and close #265; all done there!

Thanks for your encouragement and review. And again, thanks for publishing this project.

@emmanuel emmanuel deleted the feat/use-async-await branch October 7, 2024 17:31
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.

2 participants