From b13ca8c64b534ba14e3de6a0db61b5e67964814b Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Tue, 27 Feb 2024 07:30:40 +0200 Subject: [PATCH] More testing of action system, now with test coverage --- .DS_Store | Bin 0 -> 6148 bytes .vscode/settings.json | 2 + app/.github/pull_request_template.md | 16 -- app/.gitignore | 3 + app/.meteor/packages | 2 + app/.meteor/versions | 2 + .../applyActionProperty.test.ts | 174 +++++++++++++++++- .../applyProperties/applyActionProperty.ts | 19 +- .../action/tasks/applyDamagePropTask.ts | 14 +- .../action/tasks/applyItemAsAmmoTask.ts | 12 +- .../api/engine/action/tasks/applyTask.ts | 2 +- app/imports/parser/parseTree/call.ts | 1 - app/package-lock.json | 9 + app/package.json | 3 + app/tsconfig.json | 18 +- node_modules/@types/nearley/LICENSE | 21 --- node_modules/@types/nearley/README.md | 15 -- node_modules/@types/nearley/index.d.ts | 108 ----------- node_modules/@types/nearley/package.json | 58 ------ package-lock.json | 6 + 20 files changed, 236 insertions(+), 249 deletions(-) create mode 100644 .DS_Store delete mode 100644 app/.github/pull_request_template.md delete mode 100644 node_modules/@types/nearley/LICENSE delete mode 100644 node_modules/@types/nearley/README.md delete mode 100644 node_modules/@types/nearley/index.d.ts delete mode 100644 node_modules/@types/nearley/package.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6af03ce39db35d2e59c65354115417e398b80c97 GIT binary patch literal 6148 zcmeHK%SyvQ6rHivrW7Fyg)Rr&7VJZc#Z8Fy2aM=Kr6#0kFlIuNnnfvOtv}?K_&we` zGXaZPi`aW%=G^B@=0N7b7~}3T957}x#w=)v9F-bDcWr3LBqMShBTIu=24H;zsfqn{ zz;ACbpQS7fitpbaM_JzQfAXD1b9b+0wXBYH?>))F%l&+rx&Go7tt% z!Rl-`4YYbZ6&FH`%--z*`E z7$64z83VjI^` { + const prop = task.prop; if (task.targetIds.length > 1) { @@ -22,7 +24,7 @@ export default async function applyDamagePropTask( // Set the scope properties result.pushScope = {}; - if (prop.operation === 'increment') { + if (operation === 'increment') { if (value >= 0) { result.pushScope['~damage'] = { value }; } else { @@ -67,7 +69,7 @@ export default async function applyDamagePropTask( value: `${statName}${operation === 'set' ? ' set to' : ''}` + ` ${value}`, inline: true, - silenced: prop.silent, + ...prop.silent && { silenced: true }, }, task.targetIds); } @@ -98,7 +100,7 @@ export default async function applyDamagePropTask( name: title, value: `${getPropertyTitle(targetProp)} set to ${value}`, inline: true, - silenced: prop.silent, + ...prop.silent && { silenced: true }, }] }); } else if (operation === 'increment') { @@ -120,10 +122,10 @@ export default async function applyDamagePropTask( type: targetProp.type, }], contents: [{ - name: 'Attribute damage', - value: `${getPropertyTitle(targetProp)} ${value}`, + name: 'Attribute damaged', + value: `${numberToSignedString(-value)} ${getPropertyTitle(targetProp)}`, inline: true, - silenced: prop.silent, + ...prop.silent && { silenced: true }, }] }); } diff --git a/app/imports/api/engine/action/tasks/applyItemAsAmmoTask.ts b/app/imports/api/engine/action/tasks/applyItemAsAmmoTask.ts index 4097991f..6a178f65 100644 --- a/app/imports/api/engine/action/tasks/applyItemAsAmmoTask.ts +++ b/app/imports/api/engine/action/tasks/applyItemAsAmmoTask.ts @@ -43,11 +43,13 @@ export default async function applyItemAsAmmoTask(task: ItemAsAmmoTask, action: type: 'item', }], // Log the item name as a heading if it has child properties to apply - contents: itemChildren.length ? [{ - name: getPropertyTitle(item) || 'Ammo', - inline: false, - silenced: prop.silent, - }] : undefined, + ...itemChildren.length && { + contents: [{ + name: getPropertyTitle(item) || 'Ammo', + inline: false, + silenced: prop.silent, + }] + }, }); await applyTriggers(action, item, [action.creatureId], 'ammo.after', userInput); diff --git a/app/imports/api/engine/action/tasks/applyTask.ts b/app/imports/api/engine/action/tasks/applyTask.ts index a33f9e76..91a0b23b 100644 --- a/app/imports/api/engine/action/tasks/applyTask.ts +++ b/app/imports/api/engine/action/tasks/applyTask.ts @@ -53,7 +53,7 @@ export default async function applyTask( // Create a result an push it to the action results, pass it to the apply function to modify const result = new TaskResult(task.prop._id, task.targetIds); - result.scope[`#${prop.type}`] = prop; + result.scope[`#${prop.type}`] = { _propId: prop._id }; action.results.push(result); // Apply the property diff --git a/app/imports/parser/parseTree/call.ts b/app/imports/parser/parseTree/call.ts index 17fbe058..3f90d9b5 100644 --- a/app/imports/parser/parseTree/call.ts +++ b/app/imports/parser/parseTree/call.ts @@ -1,4 +1,3 @@ -console.log('call.ts imports') import error from '/imports/parser/parseTree/error'; import constant from '/imports/parser/parseTree/constant'; import functions, { ParserFunction } from '/imports/parser/functions'; diff --git a/app/package-lock.json b/app/package-lock.json index ee57feb2..17a46a80 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1512,6 +1512,15 @@ "integrity": "sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==", "dev": true }, + "@types/simpl-schema": { + "version": "1.12.7", + "resolved": "https://registry.npmjs.org/@types/simpl-schema/-/simpl-schema-1.12.7.tgz", + "integrity": "sha512-GhXOCJqKcDeawYoIe4Jly7C5ePR3Uh3jaswb1U+Ruh1x7EtZqOJMMyxnoVvJUIl5b+v7yoFs4RVny/ZowyXBDw==", + "dev": true, + "requires": { + "@types/meteor": "*" + } + }, "@types/sizzle": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/@types/sizzle/-/sizzle-2.3.8.tgz", diff --git a/app/package.json b/app/package.json index f264c12a..504e3eb6 100644 --- a/app/package.json +++ b/app/package.json @@ -13,6 +13,8 @@ "debug": "meteor --inspect", "bundle-viz": "meteor --extra-packages bundle-visualizer --production", "test": "meteor test --driver-package meteortesting:mocha --port 3001", + "test:coverage": "COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_OUT_REMAP=1 COVERAGE_APP_FOLDER=$PWD/ meteor test --once --driver-package meteortesting:mocha", + "test:watch:coverage": "COVERAGE=1 COVERAGE_OUT_LCOVONLY=1 COVERAGE_OUT_REMAP=1 COVERAGE_APP_FOLDER=$PWD/ TEST_WATCH=1 meteor test --driver-package meteortesting:mocha", "build": "meteor build ../build --architecture os.linux.x86_64" }, "engines": { @@ -68,6 +70,7 @@ "devDependencies": { "@types/chai": "^4.3.11", "@types/mocha": "^10.0.6", + "@types/simpl-schema": "^1.12.7", "@typescript-eslint/eslint-plugin": "^5.62.0", "@typescript-eslint/parser": "^5.62.0", "@vue/compiler-dom": "^3.4.19", diff --git a/app/tsconfig.json b/app/tsconfig.json index e6cc6b2b..93b1feab 100644 --- a/app/tsconfig.json +++ b/app/tsconfig.json @@ -1,9 +1,11 @@ { "compilerOptions": { - "module": "ESNext", + "module": "esNext", "moduleResolution": "Node", - "target": "ES2020", - "jsx": "react", + "target": "es2018", + "lib": ["esnext", "dom"], + "jsx": "preserve", + "strict": true, "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": ".", @@ -22,15 +24,19 @@ "meteor/aldeed:collection2": [ "packages/collection2/collection2.js" ] - } + }, + "resolveJsonModule": true, + "types": ["node", "mocha"], + "esModuleInterop": true, }, "vueCompilerOptions": { - "target": 2 // For Vue version <= 2.6.14 + "target": 2 }, "exclude": [ "node_modules", "**/node_modules/*", - ".meteor" + ".meteor", + "./packages/**" ], "typeAcquisition": { "include": [ diff --git a/node_modules/@types/nearley/LICENSE b/node_modules/@types/nearley/LICENSE deleted file mode 100644 index 9e841e7a..00000000 --- a/node_modules/@types/nearley/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ - MIT License - - Copyright (c) Microsoft Corporation. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE diff --git a/node_modules/@types/nearley/README.md b/node_modules/@types/nearley/README.md deleted file mode 100644 index 9a5f1a3c..00000000 --- a/node_modules/@types/nearley/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Installation -> `npm install --save @types/nearley` - -# Summary -This package contains type definitions for nearley (https://github.com/Hardmath123/nearley#readme). - -# Details -Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/nearley. - -### Additional Details - * Last updated: Tue, 07 Nov 2023 09:09:39 GMT - * Dependencies: none - -# Credits -These definitions were written by [Nikita Litvin](https://github.com/deltaidea), and [BendingBender](https://github.com/BendingBender). diff --git a/node_modules/@types/nearley/index.d.ts b/node_modules/@types/nearley/index.d.ts deleted file mode 100644 index 5cca1013..00000000 --- a/node_modules/@types/nearley/index.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -export as namespace nearley; - -export class Parser { - /** - * Reserved token for indicating a parse fail. - */ - static fail: {}; - - grammar: Grammar; - options: ParserOptions; - lexer: Lexer; - lexerState?: LexerState | undefined; - current: number; - /** - * An array of possible parsings. Each element is the thing returned by your grammar. - * - * Note that this is undefined before the first feed() call. - * It isn't typed as `any[] | undefined` to spare you the null checks when it's definitely an array. - */ - results: any[]; - - constructor(grammar: Grammar, options?: ParserOptions); - - /** - * The Parser object can be fed data in parts with .feed(data). - * You can then find an array of parsings with the .results property. - * If results is empty, then there are no parsings. - * If results contains multiple values, then that combination is ambiguous. - * - * @throws If there are no possible parsings, nearley will throw an error - * whose offset property is the index of the offending token. - */ - feed(chunk: string): this; - finish(): any[]; - restore(column: { [key: string]: any; lexerState: LexerState }): void; - save(): { [key: string]: any; lexerState: LexerState }; -} - -export interface ParserOptions { - keepHistory?: boolean | undefined; - lexer?: Lexer | undefined; -} - -export class Rule { - static highestId: number; - - id: number; - name: string; - symbols: any[]; - postprocess?: Postprocessor | undefined; - - constructor(name: string, symbols: any[], postprocess?: Postprocessor); - - toString(withCursorAt?: number): string; -} - -export class Grammar { - static fromCompiled(rules: CompiledRules): Grammar; - - rules: Rule[]; - start: string; - byName: { [ruleName: string]: Rule[] }; - lexer?: Lexer | undefined; - - constructor(rules: Rule[]); -} - -export interface CompiledRules { - Lexer?: Lexer | undefined; - ParserStart: string; - ParserRules: ParserRule[]; -} - -export interface ParserRule { - name: string; - symbols: any[]; - postprocess?: Postprocessor | undefined; -} - -export type Postprocessor = (data: any[], reference?: number, wantedBy?: {}) => void; - -export interface Lexer { - /** - * Sets the internal buffer to data, and restores line/col/state info taken from save(). - */ - reset(data: string, state?: LexerState): void; - /** - * Returns e.g. {type, value, line, col, …}. Only the value attribute is required. - */ - next(): Token | undefined; - /** - * Returns an object describing the current line/col etc. This allows us - * to preserve this information between feed() calls, and also to support Parser#rewind(). - * The exact structure is lexer-specific; nearley doesn't care what's in it. - */ - save(): LexerState; - /** - * Returns a string with an error message describing the line/col of the offending token. - * You might like to include a preview of the line in question. - */ - formatError(token: Token, message: string): string; -} - -export type Token = string | { value: string }; - -export interface LexerState { - [x: string]: any; -} diff --git a/node_modules/@types/nearley/package.json b/node_modules/@types/nearley/package.json deleted file mode 100644 index 72c1d0bd..00000000 --- a/node_modules/@types/nearley/package.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "_from": "@types/nearley", - "_id": "@types/nearley@2.11.5", - "_inBundle": false, - "_integrity": "sha512-dM7TrN0bVxGGXTYGx4YhGear8ysLO5SOuouAWM9oltjQ3m9oYa13qi8Z1DJp5zxVMPukvQdsrnZmgzpeuTSEQA==", - "_location": "/@types/nearley", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "@types/nearley", - "name": "@types/nearley", - "escapedName": "@types%2fnearley", - "scope": "@types", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/@types/nearley/-/nearley-2.11.5.tgz", - "_shasum": "9087e1634e1c90efb25d661390702381789685cb", - "_spec": "@types/nearley", - "_where": "/Users/stef/github/DiceCloud", - "bugs": { - "url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues" - }, - "bundleDependencies": false, - "contributors": [ - { - "name": "Nikita Litvin", - "url": "https://github.com/deltaidea" - }, - { - "name": "BendingBender", - "url": "https://github.com/BendingBender" - } - ], - "dependencies": {}, - "deprecated": false, - "description": "TypeScript definitions for nearley", - "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/nearley", - "license": "MIT", - "main": "", - "name": "@types/nearley", - "repository": { - "type": "git", - "url": "git+https://github.com/DefinitelyTyped/DefinitelyTyped.git", - "directory": "types/nearley" - }, - "scripts": {}, - "typeScriptVersion": "4.5", - "types": "index.d.ts", - "typesPublisherContentHash": "2b82830a1a87ef19e588c4f6dcd1c00fde50afd7c9dc5bd8233b054f436578d4", - "version": "2.11.5" -} diff --git a/package-lock.json b/package-lock.json index 4cd093cc..0dd68c16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,6 +2,12 @@ "requires": true, "lockfileVersion": 1, "dependencies": { + "@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, "@types/nearley": { "version": "2.11.5", "resolved": "https://registry.npmjs.org/@types/nearley/-/nearley-2.11.5.tgz",