-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot tests for parseAndTypecheckPerseusItem (#1887)
The other regression tests only assert that we can successfully parse each assessmentItem in the regression dataset. However, a successful parse doesn't necessarily mean we preserved all input data or migrated it correctly to the latest format. This PR adds snapshot tests to fix that gap in our coverage. Issue: none ## Test plan: `yarn test` Author: benchristel Reviewers: jeremywiebe, anakaren-rojas, nishasy Required Reviewers: Approved By: jeremywiebe Checks: ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: #1887
- Loading branch information
1 parent
44933f8
commit 4c2db8d
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus": patch | ||
--- | ||
|
||
Internal: add snapshot tests for `parseAndTypecheckPerseusItem`. |
71 changes: 71 additions & 0 deletions
71
...arse-perseus-json/regression-tests/__snapshots__/parse-perseus-json-snapshot.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`parseAndTypecheckPerseusItem correctly parses data/radio-missing-noneOfTheAbove.json 1`] = ` | ||
{ | ||
"answer": undefined, | ||
"answerArea": { | ||
"calculator": false, | ||
"chi2Table": false, | ||
"periodicTable": false, | ||
"tTable": false, | ||
"zTable": false, | ||
}, | ||
"hints": [], | ||
"itemDataVersion": { | ||
"major": 0, | ||
"minor": 1, | ||
}, | ||
"question": { | ||
"content": "$\\begin{align} | ||
A &= \\{x: x \\text{ is a rectangle in the plane P} \\} \\\\\\\\ | ||
B &= \\{x: x \\text{ is a square in the plane P} \\} | ||
\\end{align}$ | ||
**Is $A \\subset B$ ?** | ||
[[☃ radio 1]] | ||
", | ||
"images": {}, | ||
"metadata": undefined, | ||
"widgets": { | ||
"radio 1": { | ||
"alignment": "default", | ||
"graded": true, | ||
"key": undefined, | ||
"options": { | ||
"choices": [ | ||
{ | ||
"clue": undefined, | ||
"content": "Yes", | ||
"correct": false, | ||
"isNoneOfTheAbove": undefined, | ||
"widgets": undefined, | ||
}, | ||
{ | ||
"clue": undefined, | ||
"content": "No", | ||
"correct": true, | ||
"isNoneOfTheAbove": undefined, | ||
"widgets": undefined, | ||
}, | ||
], | ||
"countChoices": false, | ||
"deselectEnabled": false, | ||
"displayCount": null, | ||
"hasNoneOfTheAbove": false, | ||
"multipleSelect": false, | ||
"noneOfTheAbove": undefined, | ||
"onePerLine": undefined, | ||
"randomize": false, | ||
}, | ||
"static": false, | ||
"type": "radio", | ||
"version": { | ||
"major": 1, | ||
"minor": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
`; |
22 changes: 22 additions & 0 deletions
22
.../perseus/src/util/parse-perseus-json/regression-tests/parse-perseus-json-snapshot.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as fs from "fs"; | ||
import {join} from "path"; | ||
|
||
import {parseAndTypecheckPerseusItem} from "../index"; | ||
import {assertSuccess} from "../result"; | ||
|
||
const dataFiles = fs.readdirSync(join(__dirname, "data")); | ||
|
||
// If you change the parsers to migrate/convert data to a new format, you may | ||
// have to regenerate these snapshots. That's expected and okay! | ||
|
||
describe("parseAndTypecheckPerseusItem", () => { | ||
it.each(dataFiles)("correctly parses data/%s", (filename) => { | ||
const json = fs.readFileSync( | ||
join(__dirname, "data", filename), | ||
"utf-8", | ||
); | ||
const result = parseAndTypecheckPerseusItem(json); | ||
assertSuccess(result); | ||
expect(result.value).toMatchSnapshot(); | ||
}); | ||
}); |