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

Remove guessAndScore #1974

Merged
merged 4 commits into from
Dec 11, 2024
Merged

Remove guessAndScore #1974

merged 4 commits into from
Dec 11, 2024

Conversation

handeyeco
Copy link
Contributor

@handeyeco handeyeco commented Dec 10, 2024

Summary:

Remove guessAndScore from Renderer. This hasn't been used in learner-facing logic for a little bit now. The bulk of this PR is updating internal usage - tools for testing exercise correctness were using this (specifically in Cypress and our custom matchers for Jest); so most of the work was porting tests to use scorePerseusItem instead.

Test plan:

From a learner's perspective, this is dead code. So while this is a major API change, it's mostly removing dead code and updating tests. Tests should continue to run successfully.

@handeyeco handeyeco self-assigned this Dec 10, 2024
@handeyeco handeyeco changed the title don't use renderer scoring for tests WIP: remove guessAndScore Dec 10, 2024
Copy link
Contributor

github-actions bot commented Dec 10, 2024

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (2fbfbf4) and published it to npm. You
can install it using the tag PR1974.

Example:

yarn add @khanacademy/perseus@PR1974

If you are working in Khan Academy's webapp, you can run:

./dev/tools/bump_perseus_version.sh -t PR1974

Copy link
Contributor

github-actions bot commented Dec 10, 2024

Size Change: -51 B (0%)

Total Size: 1.27 MB

Filename Size Change
packages/perseus/dist/es/index.js 414 kB -51 B (-0.01%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 39 kB
packages/keypad-context/dist/es/index.js 760 B
packages/kmath/dist/es/index.js 4.27 kB
packages/math-input/dist/es/index.js 77.9 kB
packages/math-input/dist/es/strings.js 1.79 kB
packages/perseus-core/dist/es/index.js 1.48 kB
packages/perseus-editor/dist/es/index.js 688 kB
packages/perseus-linter/dist/es/index.js 22.2 kB
packages/perseus/dist/es/strings.js 3.7 kB
packages/pure-markdown/dist/es/index.js 3.66 kB
packages/simple-markdown/dist/es/index.js 12.5 kB

compressed-size-action

@handeyeco handeyeco changed the title WIP: remove guessAndScore Remove guessAndScore Dec 10, 2024
@handeyeco handeyeco requested review from a team December 10, 2024 21:40
return {widgetState, score};
}

function maybeAddState(message: string, widgetState: string): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed widgetState from the tests and they didn't seem to care. So I'm thinking this is a feature we didn't think was particularly useful. Also since the Renderer isn't scoring now, the correct/incorrect helper isn't the place to get that.

/**
* @deprecated use scorePerseusItem
*/
guessAndScore: () => [UserInputArray, PerseusScore] = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy about this, but I wanted to go further and delete score. Unfortunately I'm not sure we're ready for that until we have a path for client-side validation.

perseusRenderData: PerseusRenderer,
userInputMap: UserInputMap,
): PerseusScore {
return scorePerseusItem(perseusRenderData, userInputMap, mockStrings, "en");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just didn't want to bother with importing mockStrings everywhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: I love this technique! Trying to get it into my memory banks so I can use it sometime too. Very cool.

absoluteValueQuestion,
userInput,
);
expect(score).toStrictEqual({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cypress doesn't have access to toHaveBeenAnsweredCorrectly AFAIK

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: Good to know! Haven't written Cypress tests in a while.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's correct, because toHaveBeenAnsweredCorrectly is a Jest custom matcher. Although our Cypress tests look kinda like Jest tests, they aren't, and they just happen to have similar assertion APIs. We didn't replicate the custom matchers for the Renderer in Cypress.

// Assert
expect(renderer).toHaveBeenAnsweredCorrectly();
expect(score).toHaveBeenAnsweredCorrectly();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

90% of the changes are just updating tests to score outside of Renderer and then using that score for the assertion.

Copy link
Contributor

@Myranae Myranae left a comment

Choose a reason for hiding this comment

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

Thanks! Looks great! Went through and tested most of the widgets in SB and they all seem good too.

perseusRenderData: PerseusRenderer,
userInputMap: UserInputMap,
): PerseusScore {
return scorePerseusItem(perseusRenderData, userInputMap, mockStrings, "en");
Copy link
Contributor

Choose a reason for hiding this comment

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

Praise: I love this technique! Trying to get it into my memory banks so I can use it sometime too. Very cool.

Comment on lines -17 to -19
// NOTE(jeremy): The graded-group widget does not participate in
// Renderer grading. So we can't call `renderer.score()` and see that
// the widget is answered correctly. The only route to check the answer
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Did you change this because no widgets will participate in renderer grading after this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, since renderer.score is going away soon I didn't see the need to make that distinction here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I filed a ticket to look into this more: https://khanacademy.atlassian.net/browse/LEMS-2719

absoluteValueQuestion,
userInput,
);
expect(score).toStrictEqual({
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment: Good to know! Haven't written Cypress tests in a while.

@handeyeco handeyeco merged commit fcbde58 into remove-scoreinput2 Dec 11, 2024
13 of 18 checks passed
handeyeco added a commit that referenced this pull request Dec 12, 2024
* bulk of it removed, tests passing

* odds and ends

* changeset

* remove i18n

* respond to Jeremys feedback

* remove scoring things again

* changeset

* Remove `guessAndScore` (#1974)

## Summary:
Remove `guessAndScore` from Renderer. This hasn't been used in learner-facing logic for a little bit now. The bulk of this PR is updating internal usage - tools for testing exercise correctness were using this (specifically in Cypress and our custom matchers for Jest); so most of the work was porting tests to use `scorePerseusItem` instead.

## Test plan:
From a learner's perspective, this is dead code. So while this is a major API change, it's mostly removing dead code and updating tests. Tests should continue to run successfully.

Author: handeyeco

Reviewers: handeyeco, Myranae, jeremywiebe

Required Reviewers:

Approved By: Myranae, jeremywiebe

Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ⏹️  [cancelled] Publish npm snapshot (ubuntu-latest, 20.x), ⏹️  [cancelled] Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ⏹️  [cancelled] Check builds for changes in size (ubuntu-latest, 20.x), ⏹️  [cancelled] Cypress (ubuntu-latest, 20.x), ⏹️  [cancelled] Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x)

Pull Request URL: #1974
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.

3 participants