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

Simplify testApi.mjs #1135

Merged
merged 10 commits into from
Jan 23, 2025
Merged

Simplify testApi.mjs #1135

merged 10 commits into from
Jan 23, 2025

Conversation

pavpanchekha
Copy link
Contributor

This PR significantly simplifies testApi.mjs (which it also renames) using a nice testAPI abstraction. Not every part of the code is ported over yet, but the bulk of it is; I may merge before porting everything or I might wait and keep going until everything looks pretty. As a minor extra improvement, the test-api.js script now also starts the server for you and has nicer command-line output with basic performance data.

This PR, I think, obsoletes #1055. It's possible there are improvements in that PR that are worth porting over, I may or may not check, but I think this PR is better.

Funny enough, I was considering rewriting test-api.js into Racket so we don't depend on node, but the code is now pretty enough that I think it's not worth it.

Comment on lines 118 to 194
const exactsBody = {
method: 'POST', body: JSON.stringify({
formula: FPCoreFormula2, sample: eval_sample
})
}
const exacts = await (await fetch(makeEndpoint("/api/exacts"), exactsBody)).json()
assertIdAndPath(exacts)
assert.deepEqual(exacts.points, [[[1], -1.4142135623730951]])
const exactsAsyncResult = await callAsyncAndWaitJSONResult("/api/start/exacts", exactsBody)
assertIdAndPath(exactsAsyncResult)
assert.deepEqual(exactsAsyncResult.points, [[[1], -1.4142135623730951]])
await testAPI("/api/exacts", {
formula: FPCoreFormula2,
sample: eval_sample
}, (body) => {
assert.deepEqual(body.points, [[[1], -1.4142135623730951]]);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good example of the before/after.

@pavpanchekha pavpanchekha merged commit 896f1ee into main Jan 23, 2025
6 checks passed
@pavpanchekha pavpanchekha deleted the simplify-testApi branch January 24, 2025 00:47
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.

1 participant