Skip to content

Commit

Permalink
Merge branch 'main' into dropdown-tex-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielle Whyte committed Dec 12, 2024
2 parents 44b5af0 + 8ca54d0 commit eb17e85
Show file tree
Hide file tree
Showing 175 changed files with 4,976 additions and 11,633 deletions.
5 changes: 0 additions & 5 deletions .changeset/poor-numbers-reflect.md

This file was deleted.

16 changes: 14 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
const fs = require("fs");
const path = require("path");
Expand Down Expand Up @@ -139,7 +139,7 @@ module.exports = {
{
files: ["config/**", "utils/**", "testing/*"],
rules: {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-require-imports": "off",
"import/no-commonjs": "off",
"import/no-extraneous-dependencies": "off",
"import/no-relative-packages": "off",
Expand All @@ -166,6 +166,18 @@ module.exports = {
],
},
},
{
/**
* .typetest.ts files are used to do "type testing" :mindblown:
* It is common practice in these files to declare variables and
* expressions that are never used.
*/
files: ["*.typetest.ts"],
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-expressions": "off",
},
},
],
rules: {
"max-lines": "off",
Expand Down
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable @typescript-eslint/no-require-imports */
// eslint-disable-next-line import/no-commonjs
module.exports = require("./config/build/babel.config");
90 changes: 13 additions & 77 deletions config/test/custom-matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,56 +19,17 @@ declare global {
}
}

type PerseusRenderer = {
guessAndScore: () => [Array<any>, PerseusScore];
};

type Answerable = PerseusRenderer | PerseusScore;

function isRenderer(obj: Answerable): obj is PerseusRenderer {
// @ts-expect-error - TS(2339) - TS is annoying
return obj?.guessAndScore !== undefined;
}

function check(answerable: Answerable) {
let widgetState: string = "";
let score: PerseusScore;

if (isRenderer(answerable)) {
const result = answerable.guessAndScore();
widgetState = JSON.stringify(result[0]);
score = result[1];
} else {
score = answerable;
}

return {widgetState, score};
}

function maybeAddState(message: string, widgetState: string): string {
if (!widgetState) {
return message;
}

return message + `; widget state: ${widgetState}`;
}

expect.extend({
toHaveBeenAnsweredCorrectly(
answerable: Answerable,
score: PerseusScore,
options: {
shouldHavePoints: boolean;
},
) {
const shouldHavePoints = options?.shouldHavePoints ?? true;
const {widgetState, score} = check(answerable);

if (score.type === "invalid") {
const errMessage = maybeAddState(
`Invalid answer: ${score.message || "(no message)"}`,
widgetState,
);

const errMessage = `Invalid answer: ${score.message || "(no message)"}`;
return {
pass: false,
message: () => errMessage,
Expand All @@ -83,10 +44,7 @@ expect.extend({
}

if (score.earned !== score.total) {
const errMessage = maybeAddState(
"Problem was answered incorrectly",
widgetState,
);
const errMessage = "Problem was answered incorrectly";

return {
pass: false,
Expand All @@ -95,20 +53,14 @@ expect.extend({
}

if (shouldHavePoints && score.total < 1) {
const errMessage = maybeAddState(
"Score did not have any points",
widgetState,
);
const errMessage = "Score did not have any points";

return {
pass: false,
message: () => errMessage,
};
} else if (!shouldHavePoints && score.total > 0) {
const errMessage = maybeAddState(
"Score had points when it shouldn't have",
widgetState,
);
const errMessage = "Score had points when it shouldn't have";

return {
pass: false,
Expand All @@ -119,14 +71,9 @@ expect.extend({
return {pass: true, message: () => ""};
},

toHaveInvalidInput(answerable: Answerable, message: string | null) {
const {widgetState, score} = check(answerable);

toHaveInvalidInput(score: PerseusScore, message: string | null) {
if (score.type !== "invalid") {
const errMessage = maybeAddState(
`Answer state is not invalid. Score: ${JSON.stringify(score)}`,
widgetState,
);
const errMessage = `Answer state is not invalid. Score: ${JSON.stringify(score)}`;

return {
pass: false,
Expand All @@ -135,12 +82,9 @@ expect.extend({
}

if (message && (!score.message || !score.message.includes(message))) {
const errMessage = maybeAddState(
`Message shown for invalid input did not include "${message}": ${
score.message || "(no message)"
}. Score: ${JSON.stringify(score)}`,
widgetState,
);
const errMessage = `Message shown for invalid input did not include "${message}": ${
score.message || "(no message)"
}. Score: ${JSON.stringify(score)}`;

return {
pass: false,
Expand All @@ -151,14 +95,9 @@ expect.extend({
return {pass: true, message: () => ""};
},

toHaveBeenAnsweredIncorrectly(answerable: Answerable) {
const {widgetState, score} = check(answerable);

toHaveBeenAnsweredIncorrectly(score: PerseusScore) {
if (score.type === "invalid") {
const errMessage = maybeAddState(
`Invalid answer: ${score.message || "(no message)"}`,
widgetState,
);
const errMessage = `Invalid answer: ${score.message || "(no message)"}`;

return {
pass: false,
Expand All @@ -179,10 +118,7 @@ expect.extend({
if (score.earned !== 0) {
return {
pass: false,
message: () =>
`Problem was answered correctly. Widget state: ${JSON.stringify(
widgetState,
)}`,
message: () => `Problem was answered correctly.`,
};
}

Expand Down
13 changes: 13 additions & 0 deletions dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @khanacademy/perseus-dev-ui

## 4.0.4

### Patch Changes

- Updated dependencies [[`f9906728c`](https://github.com/Khan/perseus/commit/f9906728c1a8f09c91c11d824718b8a06d6a7609), [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82)]:
- @khanacademy/perseus-core@2.0.0
- @khanacademy/kas@0.4.3
- @khanacademy/kmath@0.1.17
- @khanacademy/math-input@21.1.7
- @khanacademy/perseus-linter@1.2.5
- @khanacademy/pure-markdown@0.3.14
- @khanacademy/simple-markdown@0.13.7

## 4.0.3

### Patch Changes
Expand Down
36 changes: 18 additions & 18 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus dev UI",
"author": "Khan Academy",
"license": "MIT",
"version": "4.0.3",
"version": "4.0.4",
"private": true,
"repository": {
"type": "git",
Expand All @@ -14,23 +14,23 @@
"dev": "vite"
},
"dependencies": {
"@khanacademy/kas": "^0.4.2",
"@khanacademy/kmath": "^0.1.16",
"@khanacademy/math-input": "^21.1.6",
"@khanacademy/perseus-core": "1.5.3",
"@khanacademy/perseus-linter": "^1.2.4",
"@khanacademy/pure-markdown": "^0.3.13",
"@khanacademy/simple-markdown": "^0.13.6",
"@khanacademy/wonder-blocks-banner": "3.1.14",
"@khanacademy/wonder-blocks-icon": "4.2.0",
"@khanacademy/wonder-blocks-icon-button": "5.6.2",
"@khanacademy/wonder-blocks-link": "6.1.10",
"@khanacademy/wonder-blocks-search-field": "2.3.6",
"@khanacademy/wonder-blocks-timing": "5.0.2",
"@khanacademy/wonder-blocks-tokens": "2.1.0",
"@khanacademy/wonder-blocks-toolbar": "4.0.0",
"@khanacademy/wonder-blocks-tooltip": "2.5.4",
"@khanacademy/wonder-stuff-core": "1.5.4",
"@khanacademy/kas": "^0.4.3",
"@khanacademy/kmath": "^0.1.17",
"@khanacademy/math-input": "^21.1.7",
"@khanacademy/perseus-core": "2.0.0",
"@khanacademy/perseus-linter": "^1.2.5",
"@khanacademy/pure-markdown": "^0.3.14",
"@khanacademy/simple-markdown": "^0.13.7",
"@khanacademy/wonder-blocks-banner": "3.1.7",
"@khanacademy/wonder-blocks-icon": "4.1.3",
"@khanacademy/wonder-blocks-icon-button": "5.3.4",
"@khanacademy/wonder-blocks-link": "6.1.6",
"@khanacademy/wonder-blocks-search-field": "2.2.23",
"@khanacademy/wonder-blocks-timing": "5.0.1",
"@khanacademy/wonder-blocks-tokens": "2.0.0",
"@khanacademy/wonder-blocks-toolbar": "3.0.35",
"@khanacademy/wonder-blocks-tooltip": "2.4.0",
"@khanacademy/wonder-stuff-core": "1.5.2",
"@phosphor-icons/core": "^2.0.2"
},
"devDependencies": {
Expand Down
11 changes: 0 additions & 11 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ with a short description and the main Perseus data type it accepts.
article, but the scoring is not available outside of the renderer.
</td>
</tr>
<tr>
<td><code>MultiItemRenderer</code></td>
<td> <code>{ _multi: any }</code></td>
<td>
The `MultiItemRenderer` is a more advanced renderer. It accepts an
object representing a tree of `PerseusRenderer` objects. A `Shape`
object defines the structure of the tree and you must provide a
"callback" object of the same structure which defines how and where
to render each `PerseusRenderer` that appears in the tree.
</td>
</tr>
<tr>
<td><code>Renderer</code></td>
<td><code>PerseusRenderer</code></td>
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
module.exports = require("./config/test/test.config");
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"@types/react": "~18.2.64",
"@types/react-dom": "~18.2.19",
"@types/underscore": "^1.11.4",
"@typescript-eslint/eslint-plugin": "^7.3.1",
"@typescript-eslint/parser": "^7.3.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"ancesdir": "^3.1.0",
"babel-jest": "^29.7.0",
"babel-loader": "^9.1.3",
Expand All @@ -73,15 +73,15 @@
"cypress-jest-adapter": "^0.1.1",
"cypress-real-events": "^1.12.0",
"cypress-wait-until": "^3.0.1",
"eslint": "^8.57.0",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-disable": "^2.0.3",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "27.9.0",
"eslint-plugin-jest": "28.9.0",
"eslint-plugin-jsdoc": "^48.2.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-monorepo": "^0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/kas/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
const path = require("path");

Expand Down
9 changes: 9 additions & 0 deletions packages/kas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @khanacademy/kas

## 0.4.3

### Patch Changes

- [#1971](https://github.com/Khan/perseus/pull/1971) [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Move to using optional chaining in a few places to resolve new lint rule violations.

- Updated dependencies [[`f9906728c`](https://github.com/Khan/perseus/commit/f9906728c1a8f09c91c11d824718b8a06d6a7609), [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82)]:
- @khanacademy/perseus-core@2.0.0

## 0.4.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/kas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A lightweight JavaScript CAS for comparing expressions and equations.",
"author": "Khan Academy",
"license": "MIT",
"version": "0.4.2",
"version": "0.4.3",
"publishConfig": {
"access": "public"
},
Expand All @@ -26,7 +26,7 @@
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"dependencies": {
"@khanacademy/perseus-core": "1.5.3"
"@khanacademy/perseus-core": "2.0.0"
},
"devDependencies": {
"jison": "0.4.15",
Expand Down
2 changes: 1 addition & 1 deletion packages/kas/src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ abstract class Expr {
// @ts-expect-error: TypeScript doesn't want to unify
// `Function` with the `compile`'s return type.
return new Function("vars", "return " + code + ";");
} catch (e) {
} catch {
throw new Error("Function did not compile: " + code);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kas/src/parser-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
/* eslint-disable prettier/prettier */

Expand Down
2 changes: 1 addition & 1 deletion packages/keypad-context/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/no-require-imports */
/* eslint-disable import/no-commonjs */
const path = require("path");

Expand Down
9 changes: 9 additions & 0 deletions packages/keypad-context/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @khanacademy/keypad-context

## 1.0.5

### Patch Changes

- [#1971](https://github.com/Khan/perseus/pull/1971) [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Move to using optional chaining in a few places to resolve new lint rule violations.

- Updated dependencies [[`f9906728c`](https://github.com/Khan/perseus/commit/f9906728c1a8f09c91c11d824718b8a06d6a7609), [`341d316aa`](https://github.com/Khan/perseus/commit/341d316aa8727ebb9e7fde28fc4e2d8779aa3e82)]:
- @khanacademy/perseus-core@2.0.0

## 1.0.4

### Patch Changes
Expand Down
Loading

0 comments on commit eb17e85

Please sign in to comment.