Skip to content

Commit

Permalink
Migrate some doenetml worker tests to vitest (#240)
Browse files Browse the repository at this point in the history
* upgrade dependencies
* set up test core to enable use of vitest in doenetml-worker
* upgrade math-expressions
* primitives removed from text state variables when from hidden composites
* convert tests to vitest
  • Loading branch information
dqnykamp authored Oct 10, 2024
1 parent 6386422 commit e9700dd
Show file tree
Hide file tree
Showing 52 changed files with 55,008 additions and 100,295 deletions.
4,434 changes: 2,131 additions & 2,303 deletions package-lock.json

Large diffs are not rendered by default.

64 changes: 34 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,56 @@
},
"homepage": "https://github.com/Doenet/DoenetML/README.md",
"devDependencies": {
"@ariakit/react": "^0.4.7",
"@ariakit/react": "^0.4.11",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@qualified/lsp-connection": "^0.3.0",
"@qualified/vscode-jsonrpc-ww": "^0.3.0",
"@rollup/pluginutils": "^5.1.0",
"@rollup/pluginutils": "^5.1.2",
"@types/esprima": "^4.0.6",
"@types/react": "^18.3.3",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@uiw/react-codemirror": "^4.22.2",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/web-worker": "^1.6.0",
"@vscode/test-web": "^0.0.54",
"autoprefixer": "^10.4.19",
"@vitest/web-worker": "^2.1.1",
"@vscode/test-web": "^0.0.60",
"autoprefixer": "^10.4.20",
"chalk": "^5.3.0",
"classnames": "^2.5.1",
"compress-json": "^3.0.5",
"cypress": "^12.13.0",
"cypress-parallel": "^0.13.0",
"compress-json": "^3.1.0",
"cypress": "^13.15.0",
"cypress-parallel": "^0.14.0",
"cypress-plugin-tab": "^1.0.5",
"cypress-wait-until": "^1.7.2",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.2",
"cypress-wait-until": "^3.0.2",
"eslint": "^8.57.1",
"eslint-plugin-react": "^7.37.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"eslint-plugin-react-refresh": "^0.4.12",
"esprima": "^4.0.1",
"glob": "^10.4.1",
"jsdom": "^24.1.0",
"katex": "^0.16.10",
"glob": "^10.4.5",
"jsdom": "^24.1.3",
"katex": "^0.16.11",
"micromark": "^4.0.0",
"nextra": "^3.0.0-alpha.24",
"nextra-theme-docs": "^3.0.0-alpha.24",
"node-stdlib-browser": "^1.2.0",
"postcss": "^8.4.38",
"prettier": "^3.3.2",
"nextra": "^3.0.1",
"nextra-theme-docs": "^3.0.1",
"node-stdlib-browser": "^1.2.1",
"postcss": "^8.4.47",
"prettier": "^3.3.3",
"rollup-plugin-polyfill-node": "^0.13.0",
"rollup-plugin-visualizer": "^5.12.0",
"tailwindcss": "^3.4.4",
"tailwindcss": "^3.4.13",
"ts-morph": "^22.0.0",
"typescript": "^5.4.5",
"vite": "^5.3.0",
"vite-node": "^1.6.0",
"typescript": "^5.6.2",
"vite": "^5.4.8",
"vite-node": "^2.1.1",
"vite-plugin-compile-time": "^0.2.1",
"vite-plugin-dts": "^3.9.1",
"vite-plugin-static-copy": "^1.0.5",
"vitest": "^1.6.0",
"vscode-jsonrpc": "8.2.0",
"vite-plugin-dts": "^4.2.2",
"vite-plugin-static-copy": "^1.0.6",
"vitest": "^2.1.1",
"vscode-jsonrpc": "8.2.1",
"vscode-languageserver": "^9.0.1",
"vscode-languageserver-protocol": "^3.17.5",
"wireit": "^0.14.4"
"wireit": "^0.14.9"
},
"overrides": {
"@qualified/lsp-connection": {
Expand All @@ -99,5 +99,9 @@
},
"prettier": {
"tabWidth": 4
},
"dependencies": {
"math-expressions": "^2.0.0-alpha68",
"react-router-dom": "^6.26.2"
}
}
4 changes: 2 additions & 2 deletions packages/docs-nextra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
}
},
"dependencies": {
"nextra": "^3.0.0-alpha.24",
"nextra-theme-docs": "^3.0.0-alpha.24",
"nextra": "^3.0.1",
"nextra-theme-docs": "^3.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"scripts": {
"watch": "vite build --watch",
"test": "echo \"No tests \"",
"test": "vitest",
"build": "wireit"
},
"wireit": {
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/Core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,7 @@ export default class Core {
// compositeReplacementActiveRange will be used
// - in renderers to determined if they should add commas
// - in child dependencies, where they will be translated for matched children
// and used in some components to determine if thsoe children can be formed into a list
// and used in some components to determine if those children can be formed into a list
parent.compositeReplacementActiveRange.push({
compositeName: child.componentName,
target: await child.stateValues.target,
Expand Down
53 changes: 52 additions & 1 deletion packages/doenetml-worker/src/Dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -5062,6 +5062,35 @@ class ChildDependency extends Dependency {
downstreamComponentTypes.push(child.componentType);
}

if (
this.originalDownstreamVariableNames.includes("hidden") &&
this.downstreamPrimitives.find((x) => x !== null)
) {
// We are asking for the hidden state variable and the result includes primitives.
// Since primitives don't have a hidden state variable, we instead depend on the hidden state variable
// of the composite.

for (let compositeObj of this.compositeReplacementRange) {
downstreamComponentNames.push(compositeObj.compositeName);
downstreamComponentTypes.push(
this.dependencyHandler._components[
compositeObj.compositeName
].componentType,
);

this.addedCompositeHiddenDependency = true;
}

if (
this.addedCompositeHiddenDependency &&
this.originalDownstreamVariableNames.length > 1
) {
// Added a composite hidden dependency but there are other variables that may not be on the composite.
// Make variables optional so we don't cause an unexpected error.
this.variablesOptional = true;
}
}

return {
success: true,
downstreamComponentNames,
Expand All @@ -5075,6 +5104,28 @@ class ChildDependency extends Dependency {
// TODO: do we have to adjust anything else from result
// if we add primitives to result.value?

let compositeReplacementRange = this.compositeReplacementRange;

if (this.addedCompositeHiddenDependency) {
// We added composite hidden dependencies.
// Delete them off the actual dependencies returned
// and instead add them to the compositeReplacesRange object returned.

let nDepsAdded = compositeReplacementRange.length;
let extraDependencies = result.value.splice(
result.value.length - nDepsAdded,
nDepsAdded,
);

compositeReplacementRange = JSON.parse(
JSON.stringify(compositeReplacementRange),
);

for (let [ind, range] of compositeReplacementRange.entries()) {
range.hidden = extraDependencies[ind].stateValues.hidden;
}
}

let resultValueWithPrimitives = [];
let resultInd = 0;

Expand All @@ -5088,7 +5139,7 @@ class ChildDependency extends Dependency {
}

resultValueWithPrimitives.compositeReplacementRange =
this.compositeReplacementRange;
compositeReplacementRange;

result.value = resultValueWithPrimitives;

Expand Down
12 changes: 12 additions & 0 deletions packages/doenetml-worker/src/components/Answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,13 @@ export default class Answer extends InlineComponent {
awardCredits.reduce((a, c) => a + c, 0),
);
}

// remove any trailing null's in awardsUsed
let lastNull = awardsUsed.indexOf(null);
if (lastNull !== -1) {
awardsUsed = awardsUsed.slice(0, lastNull);
}

return {
setValue: {
creditAchievedIfSubmit: creditAchieved,
Expand Down Expand Up @@ -2071,6 +2078,11 @@ export default class Answer extends InlineComponent {
return;
}

let disabled = await this.stateValues.disabled;
if (disabled) {
return;
}

let creditAchieved = await this.stateValues.creditAchievedIfSubmit;
if (await this.stateValues.handGraded) {
creditAchieved = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/components/Caption.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class Caption extends BlockComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["inlinesBlocks"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/components/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export default class Cell extends BaseComponent {
children: {
dependencyType: "child",
childGroups: ["maths", "anything"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
prefill: {
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/components/Choice.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class Choice extends InlineComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["children"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/components/Footnote.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class Footnote extends InlineComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["inlines"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
3 changes: 3 additions & 0 deletions packages/doenetml-worker/src/components/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export default class Label extends InlineComponent {
"value",
"hasLatex",
"renderAsMath",
"hidden",
],
variablesOptional: true,
},
Expand Down Expand Up @@ -241,6 +242,8 @@ export default class Label extends InlineComponent {
) {
if (typeof comp !== "object") {
return comp.toString();
} else if (comp.stateValues.hidden) {
return "";
} else if (
typeof comp.stateValues.hasLatex === "boolean" &&
typeof comp.stateValues.value === "string" &&
Expand Down
2 changes: 1 addition & 1 deletion packages/doenetml-worker/src/components/P.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class P extends BlockComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["inlinesAndLists"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//@ts-nocheck

// Note: changed this .js file to a .ts file in order to prevent an error
// from HyperFormula when loading Core directly from vitest.
// No idea why this stops the error, but found this workaround via trial-and-error.
// This file has not been converted to typescript, hence the ts-nocheck line at the beginning.

import { normalizeIndex } from "../utils/table";
import { textToAst } from "../utils/math";
import BlockComponent from "./abstract/BlockComponent";
Expand Down Expand Up @@ -1026,23 +1033,23 @@ export default class Spreadsheet extends BlockComponent {
// console.log(`array definition of evaluatedCells`)
// console.log(globalDependencyValues)

let hf = HyperFormula.buildFromArray(
globalDependencyValues.cells,
{
licenseKey: "gpl-v3",
},
);
// let hf = HyperFormula.buildFromArray(
// globalDependencyValues.cells,
// {
// licenseKey: "gpl-v3",
// },
// );

let allEvaluated = hf.getSheetValues(0);

let evaluatedCells = {};

for (let ind1 in allEvaluated) {
let row = allEvaluated[ind1];
for (let ind2 in row) {
evaluatedCells[[ind1, ind2]] = row[ind2];
}
}
// for (let ind1 in allEvaluated) {
// let row = allEvaluated[ind1];
// for (let ind2 in row) {
// evaluatedCells[[ind1, ind2]] = row[ind2];
// }
// }

return { setValue: { evaluatedCells } };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class InlineRenderInlineChildren extends InlineComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["inlines"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class TextOrInline extends InlineComponent {
inlineChildren: {
dependencyType: "child",
childGroups: ["inlines"],
variableNames: ["text"],
variableNames: ["text", "hidden"],
variablesOptional: true,
},
}),
Expand Down
Loading

0 comments on commit e9700dd

Please sign in to comment.