diff --git a/.vscode/launch.json b/.vscode/launch.json index 327da8570e18..d518ced211a3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -66,6 +66,23 @@ "smartStep": true, "console": "integratedTerminal", }, + { + "name": "Quantity Tests", + "presentation": { + "group": "0_CoreTests", + "order": 1 + }, + "cwd": "${workspaceFolder}/core/quantity/", + "type": "node", + "request": "launch", + "runtimeExecutable": "pnpm", + "runtimeArgs": [ + "test" + ], + "autoAttachChildProcesses": true, + "smartStep": true, + "console": "integratedTerminal", + }, { "name": "OrbitGT Tests", "presentation": { diff --git a/common/changes/@itwin/core-quantity/as-vitest-core-quantity_2024-10-19-14-49.json b/common/changes/@itwin/core-quantity/as-vitest-core-quantity_2024-10-19-14-49.json new file mode 100644 index 000000000000..2bb40169d9fe --- /dev/null +++ b/common/changes/@itwin/core-quantity/as-vitest-core-quantity_2024-10-19-14-49.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@itwin/core-quantity", + "comment": "", + "type": "none" + } + ], + "packageName": "@itwin/core-quantity" +} \ No newline at end of file diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index cb9795810c1a..6df8e3370e40 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -124,7 +124,7 @@ importers: '@itwin/eslint-plugin': 5.0.0-dev.1_aji6oyyaiulsuzmkdveqwiygte '@opentelemetry/api': 1.0.4 '@types/node': 18.16.20 - '@vitest/coverage-v8': 2.1.1_vitest@2.1.0 + '@vitest/coverage-v8': 2.1.0_vitest@2.1.0 eslint: 9.13.0 rimraf: 3.0.2 typescript: 5.6.2 @@ -160,7 +160,7 @@ importers: '@types/chai': 4.3.1 '@types/flatbuffers': 1.10.0 '@types/node': 18.16.20 - '@vitest/coverage-v8': 2.1.1_vitest@2.1.0 + '@vitest/coverage-v8': 2.1.0_vitest@2.1.0 eslint: 9.13.0 nyc: 15.1.0 rimraf: 3.0.2 @@ -600,8 +600,8 @@ importers: '@itwin/core-quantity': link:../quantity '@itwin/eslint-plugin': 5.0.0-dev.1_aji6oyyaiulsuzmkdveqwiygte '@types/chai-as-promised': 7.1.0 - '@vitest/browser': 2.1.1_bbcqthgmodi4rrojsqljgj3bpm - '@vitest/coverage-v8': 2.1.1_vvzb4akewk7qhprv5gsu3bguym + '@vitest/browser': 2.1.0_bbcqthgmodi4rrojsqljgj3bpm + '@vitest/coverage-v8': 2.1.0_qvp2nat4f5x6c53yn4p7pzv3mu babel-loader: 8.2.5_webpack@5.76.0 babel-plugin-istanbul: 6.1.1 cpx2: 3.0.0 @@ -614,7 +614,7 @@ importers: typescript: 5.6.2 vite-multiple-assets: 1.3.1 vite-plugin-static-copy: 1.0.6 - vitest: 2.1.0_@vitest+browser@2.1.1 + vitest: 2.1.0_@vitest+browser@2.1.0 webpack: 5.76.0 ../../core/frontend-devtools: @@ -667,7 +667,7 @@ importers: '@itwin/eslint-plugin': 5.0.0-dev.1_aji6oyyaiulsuzmkdveqwiygte '@types/flatbuffers': 1.10.0 '@types/node': 18.16.20 - '@vitest/coverage-v8': 2.1.1_vitest@2.1.0 + '@vitest/coverage-v8': 2.1.0_vitest@2.1.0 eslint: 9.13.0 rimraf: 3.0.2 typescript: 5.6.2 @@ -912,36 +912,22 @@ importers: '@itwin/build-tools': workspace:* '@itwin/core-bentley': workspace:* '@itwin/eslint-plugin': 5.0.0-dev.1 - '@types/chai': 4.3.1 - '@types/chai-as-promised': ^7 '@types/glob': ^5.0.35 - '@types/mocha': ^10.0.6 - '@types/sinon': ^17.0.2 - chai: ^4.3.10 - chai-as-promised: ^7.1.1 + '@vitest/coverage-v8': ^2.1.0 eslint: ^9.13.0 - mocha: ^10.2.0 - nyc: ^15.1.0 rimraf: ^3.0.2 - sinon: ^17.0.2 typescript: ~5.6.2 + vitest: ^2.1.0 devDependencies: '@itwin/build-tools': link:../../tools/build '@itwin/core-bentley': link:../bentley '@itwin/eslint-plugin': 5.0.0-dev.1_aji6oyyaiulsuzmkdveqwiygte - '@types/chai': 4.3.1 - '@types/chai-as-promised': 7.1.0 '@types/glob': 5.0.35 - '@types/mocha': 10.0.6 - '@types/sinon': 17.0.2 - chai: 4.3.10 - chai-as-promised: 7.1.1_chai@4.3.10 + '@vitest/coverage-v8': 2.1.0_vitest@2.1.0 eslint: 9.13.0 - mocha: 10.2.0 - nyc: 15.1.0 rimraf: 3.0.2 - sinon: 17.0.2 typescript: 5.6.2 + vitest: 2.1.0 ../../core/telemetry: specifiers: @@ -4103,10 +4089,10 @@ packages: resolution: {integrity: sha512-F2VBt7W/mwqEU4bL0RnHNZmC/OxzNx9cOYxHqnXX3MP6ruYvZUZAW9imgN9+h/uBT/oP8Gh888J2OZSbjSeWcg==} engines: {node: '>=18'} dependencies: - '@inquirer/figures': 1.0.6 + '@inquirer/figures': 1.0.7 '@inquirer/type': 2.0.0 '@types/mute-stream': 0.0.4 - '@types/node': 22.7.4 + '@types/node': 22.7.7 '@types/wrap-ansi': 3.0.0 ansi-escapes: 4.3.2 cli-width: 4.1.0 @@ -4117,8 +4103,8 @@ packages: yoctocolors-cjs: 2.1.2 dev: true - /@inquirer/figures/1.0.6: - resolution: {integrity: sha512-yfZzps3Cso2UbM7WlxKwZQh2Hs6plrbjs1QnzQDZhK2DgyCo6D8AaHps9olkNcUFlcYERMqU3uJSp1gmy3s/qQ==} + /@inquirer/figures/1.0.7: + resolution: {integrity: sha512-m+Trk77mp54Zma6xLkLuY+mvanPxlE4A7yNKs2HBiyZ4UkVs28Mv5c/pgWrHeInx+USHeX/WEPzjrWrcJiQgjw==} engines: {node: '>=18'} dev: true @@ -4204,8 +4190,8 @@ packages: reflect-metadata: 0.1.13 dev: false - /@itwin/core-bentley/4.9.5: - resolution: {integrity: sha512-2cFqJnWKdGyNgZziqYHg4KkYVXD3+f4WQ5xhVPkEYffcOpXXz4yFh8nDOZmhgOLAmJo6KDH2x+uNJembcX6wjQ==} + /@itwin/core-bentley/4.9.7: + resolution: {integrity: sha512-c/A0UT+slQTIFMsLon4haYmey/vpdP+MJrly4SaEgC0WHTo06t3qYf0342F3F15DmsnqC2n2DDNx6/n6pUPqOg==} dev: false /@itwin/core-common/4.8.1_67wltvhdskk2oee2c3z2o4tfly: @@ -4436,7 +4422,7 @@ packages: /@itwin/presentation-shared/1.1.0: resolution: {integrity: sha512-H0NiWIYpxPSg4bJdQdSo4epdFUqoza/4UEbRj6nin906Mr2oKWu7Jep9OLbFXTmarMtP+q+5iSlp/eTRhTc/Cg==} dependencies: - '@itwin/core-bentley': 4.9.5 + '@itwin/core-bentley': 4.9.7 dev: false /@itwin/reality-data-client/1.2.1_mdtbcqczpmeuv6yjzfaigjndwi: @@ -4484,7 +4470,7 @@ packages: /@itwin/unified-selection/1.1.1: resolution: {integrity: sha512-myygzispTehbgeZBFbOipyt3AvTr9Lx+QvP5hPG3YKyEvGimAtO3Mh6unwmdCxrM9Ue9w5El63Jbr0N+f+ZdVg==} dependencies: - '@itwin/core-bentley': 4.9.5 + '@itwin/core-bentley': 4.9.7 '@itwin/presentation-shared': 1.1.0 rxjs: 7.8.1 rxjs-for-await: 1.0.0_rxjs@7.8.1 @@ -4615,8 +4601,8 @@ packages: resolution: {integrity: sha512-HZpPoABogPvjeJOdzCOSJsXeL/SMCBgBZMVC3X3d7YYp2gf31MfxhUoYUNwf1ERPJOnQc0wkFn9trqI6ZEdZuA==} dev: false - /@mswjs/interceptors/0.35.9: - resolution: {integrity: sha512-SSnyl/4ni/2ViHKkiZb8eajA/eN1DNFaHjhGiLUdZvDz6PKF4COSf/17xqSz64nOo2Ia29SA6B2KNCsyCbVmaQ==} + /@mswjs/interceptors/0.36.5: + resolution: {integrity: sha512-aQ8WF5zQwOdcxLsxSEk9Jd01GgGb80xxqCaiDDlewhtwqpSm8MOvUHslwPydVirasdW09++NxDNNftm1vLY8yA==} engines: {node: '>=18'} dependencies: '@open-draft/deferred-promise': 2.2.0 @@ -4744,7 +4730,7 @@ packages: rollup: optional: true dependencies: - '@types/estree': 1.0.6 + '@types/estree': 1.0.5 estree-walker: 2.0.2 picomatch: 2.3.1 dev: true @@ -5126,12 +5112,12 @@ packages: resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==} dependencies: '@types/eslint': 9.6.0 - '@types/estree': 1.0.6 + '@types/estree': 1.0.5 /@types/eslint/9.6.0: resolution: {integrity: sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==} dependencies: - '@types/estree': 1.0.6 + '@types/estree': 1.0.5 '@types/json-schema': 7.0.15 /@types/estree/0.0.51: @@ -5139,7 +5125,6 @@ packages: /@types/estree/1.0.5: resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} - dev: true /@types/estree/1.0.6: resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==} @@ -5304,8 +5289,8 @@ packages: dependencies: undici-types: 5.26.5 - /@types/node/22.7.4: - resolution: {integrity: sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==} + /@types/node/22.7.7: + resolution: {integrity: sha512-SRxCrrg9CL/y54aiMCG3edPKdprgMVGDXjA3gB8UmmBW5TcXzRUYAh8EWzTnSJFAd1rgImPELza+A3bJ+qxz8Q==} dependencies: undici-types: 6.19.8 dev: true @@ -5572,12 +5557,12 @@ packages: '@typescript-eslint/types': 8.11.0 eslint-visitor-keys: 3.4.3 - /@vitest/browser/2.1.1_bbcqthgmodi4rrojsqljgj3bpm: - resolution: {integrity: sha512-wLKqohwlZI24xMIEZAPwv9SVliv1avaIBeE0ou471D++BRPhiw2mubKBczFFIDHXuSL7UXb8/JQK9Ui6ttW9bQ==} + /@vitest/browser/2.1.0_bbcqthgmodi4rrojsqljgj3bpm: + resolution: {integrity: sha512-A75cB40Uv8Q0dSo1vHsCkiMUZwjFyd/BkqfgiaHvNltjAbZ0XGX+VvMtWd/zne+1lfwg32pv+JVYZP8Oagb+ng==} peerDependencies: playwright: '*' safaridriver: '*' - vitest: 2.1.1 + vitest: 2.1.0 webdriverio: '*' peerDependenciesMeta: playwright: @@ -5589,14 +5574,14 @@ packages: dependencies: '@testing-library/dom': 10.4.0 '@testing-library/user-event': 14.5.2_eboxt5b3qr45gcxzx7wxppt6li - '@vitest/mocker': 2.1.1_msw@2.4.9 - '@vitest/utils': 2.1.1 + '@vitest/mocker': 2.1.0_msw@2.4.12 + '@vitest/utils': 2.1.0 magic-string: 0.30.11 - msw: 2.4.9_typescript@5.6.2 + msw: 2.4.12_typescript@5.6.2 playwright: 1.47.1 sirv: 2.0.4 tinyrainbow: 1.2.0 - vitest: 2.1.0_@vitest+browser@2.1.1 + vitest: 2.1.0_@vitest+browser@2.1.0 ws: 8.18.0 transitivePeerDependencies: - bufferutil @@ -5605,17 +5590,18 @@ packages: - vite dev: true - /@vitest/coverage-v8/2.1.1_vitest@2.1.0: - resolution: {integrity: sha512-md/A7A3c42oTT8JUHSqjP5uKTWJejzUW4jalpvs+rZ27gsURsMU8DEb+8Jf8C6Kj2gwfSHJqobDNBuoqlm0cFw==} + /@vitest/coverage-v8/2.1.0_qvp2nat4f5x6c53yn4p7pzv3mu: + resolution: {integrity: sha512-yqCkr2nrV4o58VcVMxTVkS6Ggxzy7pmSD8JbTbhbH5PsQfUIES1QT716VUzo33wf2lX9EcWYdT3Vl2MMmjR59g==} peerDependencies: - '@vitest/browser': 2.1.1 - vitest: 2.1.1 + '@vitest/browser': 2.1.0 + vitest: 2.1.0 peerDependenciesMeta: '@vitest/browser': optional: true dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 + '@vitest/browser': 2.1.0_bbcqthgmodi4rrojsqljgj3bpm debug: 4.3.6 istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 @@ -5626,23 +5612,22 @@ packages: std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 - vitest: 2.1.0_@types+node@18.16.20 + vitest: 2.1.0_@vitest+browser@2.1.0 transitivePeerDependencies: - supports-color dev: true - /@vitest/coverage-v8/2.1.1_vvzb4akewk7qhprv5gsu3bguym: - resolution: {integrity: sha512-md/A7A3c42oTT8JUHSqjP5uKTWJejzUW4jalpvs+rZ27gsURsMU8DEb+8Jf8C6Kj2gwfSHJqobDNBuoqlm0cFw==} + /@vitest/coverage-v8/2.1.0_vitest@2.1.0: + resolution: {integrity: sha512-yqCkr2nrV4o58VcVMxTVkS6Ggxzy7pmSD8JbTbhbH5PsQfUIES1QT716VUzo33wf2lX9EcWYdT3Vl2MMmjR59g==} peerDependencies: - '@vitest/browser': 2.1.1 - vitest: 2.1.1 + '@vitest/browser': 2.1.0 + vitest: 2.1.0 peerDependenciesMeta: '@vitest/browser': optional: true dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 0.2.3 - '@vitest/browser': 2.1.1_bbcqthgmodi4rrojsqljgj3bpm debug: 4.3.6 istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 @@ -5653,7 +5638,7 @@ packages: std-env: 3.7.0 test-exclude: 7.0.1 tinyrainbow: 1.2.0 - vitest: 2.1.0_@vitest+browser@2.1.1 + vitest: 2.1.0_@types+node@18.16.20 transitivePeerDependencies: - supports-color dev: true @@ -5667,7 +5652,7 @@ packages: tinyrainbow: 1.2.0 dev: true - /@vitest/mocker/2.1.0_vite@5.4.6: + /@vitest/mocker/2.1.0_msw@2.4.12: resolution: {integrity: sha512-ZxENovUqhzl+QiOFpagiHUNUuZ1qPd5yYTCYHomGIZOFArzn4mgX2oxZmiAItJWAaXHG6bbpb/DpSPhlk5DgtA==} peerDependencies: msw: ^2.3.5 @@ -5681,11 +5666,11 @@ packages: '@vitest/spy': 2.1.0 estree-walker: 3.0.3 magic-string: 0.30.11 - vite: 5.4.6_@types+node@18.16.20 + msw: 2.4.12_typescript@5.6.2 dev: true - /@vitest/mocker/2.1.1_msw@2.4.9: - resolution: {integrity: sha512-LNN5VwOEdJqCmJ/2XJBywB11DLlkbY0ooDJW3uRX5cZyYCrc4PI/ePX0iQhE3BiEGiQmK4GE7Q/PqCkkaiPnrA==} + /@vitest/mocker/2.1.0_vite@5.4.6: + resolution: {integrity: sha512-ZxENovUqhzl+QiOFpagiHUNUuZ1qPd5yYTCYHomGIZOFArzn4mgX2oxZmiAItJWAaXHG6bbpb/DpSPhlk5DgtA==} peerDependencies: msw: ^2.3.5 vite: ^5.0.0 @@ -5698,7 +5683,7 @@ packages: '@vitest/spy': 2.1.0 estree-walker: 3.0.3 magic-string: 0.30.11 - msw: 2.4.9_typescript@5.6.2 + vite: 5.4.6_@types+node@18.16.20 dev: true /@vitest/pretty-format/2.1.0: @@ -5742,14 +5727,6 @@ packages: tinyrainbow: 1.2.0 dev: true - /@vitest/utils/2.1.1: - resolution: {integrity: sha512-Y6Q9TsI+qJ2CC0ZKj6VBb+T8UPz593N113nnUykqwANqhgf3QkZeHFlusgKLTqrnVHbj/XDKZcDHol+dxVT+rQ==} - dependencies: - '@vitest/pretty-format': 2.1.1 - loupe: 3.1.1 - tinyrainbow: 1.2.0 - dev: true - /@webassemblyjs/ast/1.11.1: resolution: {integrity: sha512-ukBh14qFLjxTQNTXocdyksN5QdM28S1CxHt2rdskFyL+xFV7VremuBLVbmCePj+URalXBENx/9Lm7lnhihtCSw==} dependencies: @@ -7263,7 +7240,6 @@ packages: path-key: 3.1.1 shebang-command: 2.0.0 which: 2.0.2 - dev: false /cross-spawn/7.0.3: resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} @@ -8382,7 +8358,7 @@ packages: /estree-walker/3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} dependencies: - '@types/estree': 1.0.6 + '@types/estree': 1.0.5 dev: true /esutils/2.0.3: @@ -8693,7 +8669,7 @@ packages: resolution: {integrity: sha512-dCIq9FpEcyQyXKCkyzmlPTFNgrCzPudOe+mhvJU5zAtlBnGVy2yKxtfsxK2tQBThwq225jcvBjpw1Gr40uzZCA==} engines: {node: '>=8.0.0'} dependencies: - cross-spawn: 7.0.3 + cross-spawn: 7.0.1 signal-exit: 3.0.7 /foreground-child/3.3.0: @@ -9643,7 +9619,7 @@ packages: /is-reference/3.0.2: resolution: {integrity: sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==} dependencies: - '@types/estree': 1.0.6 + '@types/estree': 1.0.5 dev: true /is-regex/1.1.4: @@ -10709,8 +10685,8 @@ packages: /ms/2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} - /msw/2.4.9_typescript@5.6.2: - resolution: {integrity: sha512-1m8xccT6ipN4PTqLinPwmzhxQREuxaEJYdx4nIbggxP8aM7r1e71vE7RtOUSQoAm1LydjGfZKy7370XD/tsuYg==} + /msw/2.4.12_typescript@5.6.2: + resolution: {integrity: sha512-upQMKZt0fYIB0Gj6gKc5i/PK4JrICTu3ItfXiju3FTdgQLaqARv7+jugPCsOkrWpTzzjo5iLW+4F6L/mGNukbA==} engines: {node: '>=18'} hasBin: true requiresBuild: true @@ -10724,7 +10700,7 @@ packages: '@bundled-es-modules/statuses': 1.0.1 '@bundled-es-modules/tough-cookie': 0.1.6 '@inquirer/confirm': 3.2.0 - '@mswjs/interceptors': 0.35.9 + '@mswjs/interceptors': 0.36.5 '@open-draft/until': 2.1.0 '@types/cookie': 0.6.0 '@types/statuses': 2.0.5 @@ -10819,7 +10795,7 @@ packages: '@sinonjs/fake-timers': 11.2.2 '@sinonjs/text-encoding': 0.7.2 just-extend: 6.2.0 - path-to-regexp: 6.3.0 + path-to-regexp: 6.2.2 /nock/12.0.3: resolution: {integrity: sha512-QNb/j8kbFnKCiyqi9C5DD0jH/FubFGj5rt9NQFONXwQm3IPB0CULECg/eS3AU1KgZb/6SwUa4/DTRKhVxkGABw==} @@ -11389,8 +11365,12 @@ packages: /path-to-regexp/0.1.10: resolution: {integrity: sha512-7lf7qcQidTku0Gu3YDPc8DJ1q7OOucfa/BSsIwjuh56VU7katFvuM8hULfkwB3Fns/rsVF7PwPKVw1sl5KQS9w==} + /path-to-regexp/6.2.2: + resolution: {integrity: sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw==} + /path-to-regexp/6.3.0: resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==} + dev: true /path-type/3.0.0: resolution: {integrity: sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==} @@ -13643,6 +13623,62 @@ packages: fsevents: 2.3.3 dev: true + /vitest/2.1.0: + resolution: {integrity: sha512-XuuEeyNkqbfr0FtAvd9vFbInSSNY1ykCQTYQ0sj9wPy4hx+1gR7gqVNdW0AX2wrrM1wWlN5fnJDjF9xG6mYRSQ==} + engines: {node: ^18.0.0 || >=20.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@types/node': ^18.0.0 || >=20.0.0 + '@vitest/browser': 2.1.0 + '@vitest/ui': 2.1.0 + happy-dom: '*' + jsdom: '*' + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@types/node': + optional: true + '@vitest/browser': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + dependencies: + '@vitest/expect': 2.1.0 + '@vitest/mocker': 2.1.0_vite@5.4.6 + '@vitest/pretty-format': 2.1.1 + '@vitest/runner': 2.1.0 + '@vitest/snapshot': 2.1.0 + '@vitest/spy': 2.1.0 + '@vitest/utils': 2.1.0 + chai: 5.1.1 + debug: 4.3.6 + magic-string: 0.30.11 + pathe: 1.1.2 + std-env: 3.7.0 + tinybench: 2.9.0 + tinyexec: 0.3.0 + tinypool: 1.0.1 + tinyrainbow: 1.2.0 + vite: 5.4.6 + vite-node: 2.1.0 + why-is-node-running: 2.3.0 + transitivePeerDependencies: + - less + - lightningcss + - msw + - sass + - sass-embedded + - stylus + - sugarss + - supports-color + - terser + dev: true + /vitest/2.1.0_@types+node@18.16.20: resolution: {integrity: sha512-XuuEeyNkqbfr0FtAvd9vFbInSSNY1ykCQTYQ0sj9wPy4hx+1gR7gqVNdW0AX2wrrM1wWlN5fnJDjF9xG6mYRSQ==} engines: {node: ^18.0.0 || >=20.0.0} @@ -13700,7 +13736,7 @@ packages: - terser dev: true - /vitest/2.1.0_@vitest+browser@2.1.1: + /vitest/2.1.0_@vitest+browser@2.1.0: resolution: {integrity: sha512-XuuEeyNkqbfr0FtAvd9vFbInSSNY1ykCQTYQ0sj9wPy4hx+1gR7gqVNdW0AX2wrrM1wWlN5fnJDjF9xG6mYRSQ==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true @@ -13725,7 +13761,7 @@ packages: jsdom: optional: true dependencies: - '@vitest/browser': 2.1.1_bbcqthgmodi4rrojsqljgj3bpm + '@vitest/browser': 2.1.0_bbcqthgmodi4rrojsqljgj3bpm '@vitest/expect': 2.1.0 '@vitest/mocker': 2.1.0_vite@5.4.6 '@vitest/pretty-format': 2.1.1 diff --git a/core/quantity/package.json b/core/quantity/package.json index dd2b81d8c6f6..5ecf613594d1 100644 --- a/core/quantity/package.json +++ b/core/quantity/package.json @@ -18,9 +18,9 @@ "clean": "rimraf lib .rush/temp/package-deps*.json .nyc_output", "extract-api": "betools extract-api --entry=core-quantity", "lint": "eslint \"./src/**/*.ts\" 1>&2", - "test": "mocha", + "test": "vitest --run", "docs": "betools docs --includes=../../generated-docs/extract --json=../../generated-docs/core/core-quantity/file.json --tsIndexFile=./core-quantity.ts --onlyJson", - "cover": "nyc npm -s test", + "cover": "vitest --run --coverage", "start": "npm run -s lint && npm run -s clean && npm run -s build && npm run -s test & npm run -s cover & npm run -s docs" }, "keywords": [ @@ -36,24 +36,14 @@ "@itwin/build-tools": "workspace:*", "@itwin/core-bentley": "workspace:*", "@itwin/eslint-plugin": "5.0.0-dev.1", - "@types/chai": "4.3.1", - "@types/chai-as-promised": "^7", "@types/glob": "^5.0.35", - "@types/mocha": "^10.0.6", - "@types/sinon": "^17.0.2", - "chai": "^4.3.10", - "chai-as-promised": "^7.1.1", + "@vitest/coverage-v8": "^2.1.0", "eslint": "^9.13.0", - "mocha": "^10.2.0", - "nyc": "^15.1.0", "rimraf": "^3.0.2", - "sinon": "^17.0.2", - "typescript": "~5.6.2" + "typescript": "~5.6.2", + "vitest": "^2.1.0" }, "peerDependencies": { "@itwin/core-bentley": "workspace:^5.0.0-dev.3" - }, - "nyc": { - "extends": "./node_modules/@itwin/build-tools/.nycrc" } -} +} \ No newline at end of file diff --git a/core/quantity/src/Formatter/Formatter.ts b/core/quantity/src/Formatter/Formatter.ts index 9868ce62e307..f58c99b4526e 100644 --- a/core/quantity/src/Formatter/Formatter.ts +++ b/core/quantity/src/Formatter/Formatter.ts @@ -208,9 +208,9 @@ export class Formatter { const unitConversion = spec.unitConversions[i].conversion; if (i > 0 && unitConversion.factor < 1.0) - throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`); + throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`); if (i > 0 && unitConversion.offset !== 0) // offset should only ever be defined for major unit - throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`); + throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`); let unitValue = 0.0; if (spec.format.type === FormatType.Ratio){ diff --git a/core/quantity/src/test/BearingAzimuth.test.ts b/core/quantity/src/test/BearingAzimuth.test.ts index 486e30f0893f..f47186e17403 100644 --- a/core/quantity/src/test/BearingAzimuth.test.ts +++ b/core/quantity/src/test/BearingAzimuth.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { assert, expect } from "chai"; +import { describe, expect, it } from "vitest"; import { Format } from "../Formatter/Format"; import { FormatterSpec } from "../Formatter/FormatterSpec"; import { Formatter } from "../Formatter/Formatter"; @@ -65,18 +65,18 @@ describe("Bearing format tests:", () => { const bearingDMS = new Format("BearingDMS"); await bearingDMS.fromJSON(unitsProvider, bearingDMSJson).catch(() => { }); - assert.isTrue(bearingDMS.hasUnits); + expect(bearingDMS.hasUnits).to.be.true; const bearingDMSWithLabel = new Format("BearingDMSWithLabel"); await bearingDMSWithLabel.fromJSON(unitsProvider, bearingDMSWithLabelJson).catch(() => { }); - assert.isTrue(bearingDMSWithLabel.hasUnits); + expect(bearingDMSWithLabel.hasUnits).to.be.true; const bearingDecimal = new Format("BearingDecimal"); await bearingDecimal.fromJSON(unitsProvider, bearingDecimalJson).catch(() => { }); - assert.isTrue(bearingDecimal.hasUnits); + expect(bearingDecimal.hasUnits).to.be.true; const rad: UnitProps = await unitsProvider.findUnitByName("Units.RAD"); - assert.isTrue(rad.isValid); + expect(rad.isValid).to.be.true; const bearingDMSFormatter = await FormatterSpec.create("RadToBearingDMS", bearingDMS, unitsProvider, rad); const bearingDMSWithLabelFormatter = await FormatterSpec.create("RadToBearingDMSWithLabel", bearingDMSWithLabel, unitsProvider, rad); const bearingDecimalFormatter = await FormatterSpec.create("RadToBearingDecimal", bearingDecimal, unitsProvider, rad); @@ -121,7 +121,7 @@ describe("Bearing format tests:", () => { expect(resultBearingDMS).to.be.eql(entry.dms); const parseBearingDMSResult = Parser.parseQuantityString(resultBearingDMS, bearingDMSParser); if (!Parser.isParsedQuantity(parseBearingDMSResult)) { - assert.fail(`Expected a parsed from bearing DMS input string ${resultBearingDMS}`); + expect.fail(`Expected a parsed from bearing DMS input string ${resultBearingDMS}`); } expect(parseBearingDMSResult.value, `Parsed result for ${entry.input} from formatted ${resultBearingDMS}`).closeTo(normalizedAngle, 0.0001); @@ -129,7 +129,7 @@ describe("Bearing format tests:", () => { expect(resultBearingDMSWithLabel).to.be.eql(entry.dmsWithLabel); const parseBearingDMSWithLabelResult = Parser.parseQuantityString(resultBearingDMSWithLabel, bearingDMSWithLabelParser); if (!Parser.isParsedQuantity(parseBearingDMSWithLabelResult)) { - assert.fail(`Expected a parsed from bearing DMS with label input string ${resultBearingDMSWithLabel}`); + expect.fail(`Expected a parsed from bearing DMS with label input string ${resultBearingDMSWithLabel}`); } expect(parseBearingDMSWithLabelResult.value, `Parsed result for ${normalizedAngle} from formatted ${resultBearingDMSWithLabel}`).closeTo(normalizedAngle, 0.0001); @@ -137,7 +137,7 @@ describe("Bearing format tests:", () => { expect(resultBearingDecimal).to.be.eql(entry.decimal); const parseBearingDecimalResult = Parser.parseQuantityString(resultBearingDecimal, bearingDecimalParser); if (!Parser.isParsedQuantity(parseBearingDecimalResult)) { - assert.fail(`Expected a parsed from bearing decimal input string ${resultBearingDecimal}`); + expect.fail(`Expected a parsed from bearing decimal input string ${resultBearingDecimal}`); } expect(parseBearingDecimalResult.value, `Parsed result for ${normalizedAngle} from formatted ${resultBearingDecimal}`).closeTo(normalizedAngle, 0.0001); } @@ -217,14 +217,14 @@ describe("Azimuth format tests:", () => { const azimuthDMS = new Format("azimuthDMS"); await azimuthDMS.fromJSON(unitsProvider, azimuthDMSJson).catch(() => { }); - assert.isTrue(azimuthDMS.hasUnits); + expect(azimuthDMS.hasUnits).to.be.true; const azimuthDecimal = new Format("azimuthDecimal"); await azimuthDecimal.fromJSON(unitsProvider, azimuthDecimalJson).catch(() => { }); - assert.isTrue(azimuthDecimal.hasUnits); + expect(azimuthDecimal.hasUnits).to.be.true; const rad: UnitProps = await unitsProvider.findUnitByName("Units.RAD"); - assert.isTrue(rad.isValid); + expect(rad.isValid).to.be.true; const azimuthDMSFormatter = await FormatterSpec.create("RadToAzimuthDMS", azimuthDMS, unitsProvider, rad); const azimuthDecimalFormatter = await FormatterSpec.create("RadToAzimuthDecimal", azimuthDecimal, unitsProvider, rad); @@ -295,9 +295,9 @@ describe("Azimuth format tests:", () => { const format = new Format(`azimuthWith${baseInDegrees}Base`); await format.fromJSON(unitsProvider, props); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const deg: UnitProps = await unitsProvider.findUnitByName("Units.ARC_DEG"); - assert.isTrue(deg.isValid); + expect(deg.isValid).to.be.true; return FormatterSpec.create(`DegreeToAzimuthWith${baseInDegrees}Base`, format, unitsProvider, deg); }; @@ -310,9 +310,9 @@ describe("Azimuth format tests:", () => { const format = new Format(`azimuthWith${baseInDegrees}Base`); await format.fromJSON(unitsProvider, props); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const deg: UnitProps = await unitsProvider.findUnitByName("Units.ARC_DEG"); - assert.isTrue(deg.isValid); + expect(deg.isValid).to.be.true; return ParserSpec.create(format, unitsProvider, deg); }; @@ -352,7 +352,7 @@ describe("Azimuth format tests:", () => { const parser = await createParser(entry.base, entry.counterClockwise); const parseResult = Parser.parseQuantityString(result, parser); if (!Parser.isParsedQuantity(parseResult)) { - assert.fail("Expected a parsed quantity"); + expect.fail("Expected a parsed quantity"); } expect(parseResult.value, `Parsed result for ${entry.input} with base ${entry.base} ccw: ${entry.counterClockwise}`).closeTo(entry.input, 0.0001); } @@ -382,9 +382,9 @@ describe("Azimuth format tests:", () => { const format = new Format(`azimuth`); await format.fromJSON(unitsProvider, formatJson); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const minutes: UnitProps = await unitsProvider.findUnitByName("Units.ARC_MINUTE"); - assert.isTrue(minutes.isValid); + expect(minutes.isValid).to.be.true; const formatter = await FormatterSpec.create("Formatter", format, unitsProvider, minutes); const result = Formatter.formatQuantity(5100, formatter); // 85 degrees, angle with a South base expect(result).to.be.eql("265.0°"); @@ -414,14 +414,14 @@ describe("Azimuth format tests:", () => { const format = new Format(`azimuth`); await format.fromJSON(unitsProvider, formatJson); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const rad: UnitProps = await unitsProvider.findUnitByName("Units.RAD"); - assert.isTrue(rad.isValid); + expect(rad.isValid).to.be.true; const formatter = await FormatterSpec.create("Formatter", format, unitsProvider, rad); const parser = await ParserSpec.create(format, unitsProvider, rad, unitsProvider); const parseResult = Parser.parseQuantityString("265.0°", parser); if (!Parser.isParsedQuantity(parseResult)) { - assert.fail("Expected a parsed quantity"); + expect.fail("Expected a parsed quantity"); } expect(parseResult.value).closeTo(1.4835, 0.0001); const formattedValue = Formatter.formatQuantity(parseResult.value, formatter); @@ -451,8 +451,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, jsonObj); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "The Format testAzimuthFormat has an invalid 'azimuthBaseUnit' attribute. It should be of type 'string'."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("The Format testAzimuthFormat has an invalid 'azimuthBaseUnit' attribute. It should be of type 'string'."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -466,8 +466,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, jsonObj); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "Invalid unit name 'invalidUnit' for azimuthBaseUnit in Format 'testAzimuthFormat'."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("Invalid unit name 'invalidUnit' for azimuthBaseUnit in Format 'testAzimuthFormat'."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -481,8 +481,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, jsonObj); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "The Format testAzimuthFormat has an invalid 'revolutionUnit' attribute. It should be of type 'string'."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("The Format testAzimuthFormat has an invalid 'revolutionUnit' attribute. It should be of type 'string'."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -496,8 +496,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, jsonObj); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "Invalid unit name 'invalidUnit' for revolutionUnit in Format 'testAzimuthFormat'."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("Invalid unit name 'invalidUnit' for revolutionUnit in Format 'testAzimuthFormat'."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -510,8 +510,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, jsonObj); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "The Format testAzimuthFormat is 'Azimuth' or 'Bearing' type therefore the attribute 'revolutionUnit' is required."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("The Format testAzimuthFormat is 'Azimuth' or 'Bearing' type therefore the attribute 'revolutionUnit' is required."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -523,8 +523,8 @@ describe("Azimuth and Revolution formatting that throws error:", () => { await testFormatWithAzimuthType.fromJSON(unitsProvider, { type: "azimuth" }); expect.fail("Expected error was not thrown"); } catch (e: any) { - assert.strictEqual(e.message, "The Format testAzimuthFormat has an 'azimuthBase' attribute therefore the attribute 'azimuthBaseUnit' is required."); - assert.instanceOf(e, QuantityError); + expect(e.message).toEqual("The Format testAzimuthFormat has an 'azimuthBase' attribute therefore the attribute 'azimuthBaseUnit' is required."); + expect(e).toBeInstanceOf(QuantityError); } }); }); diff --git a/core/quantity/src/test/CompositeFormats.test.ts b/core/quantity/src/test/CompositeFormats.test.ts index 1267be431b76..291e09877db4 100644 --- a/core/quantity/src/test/CompositeFormats.test.ts +++ b/core/quantity/src/test/CompositeFormats.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { assert, expect } from "chai"; +import { describe, expect, it } from "vitest"; import { Format } from "../Formatter/Format"; import { FormatterSpec } from "../Formatter/FormatterSpec"; import { Formatter } from "../Formatter/Formatter"; @@ -35,21 +35,16 @@ describe("Composite Formats tests:", () => { uomSeparator: "", }; - try { - const format = new Format("test"); - await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + const format = new Format("test"); + await format.fromJSON(unitsProvider, formatData).catch(() => { }); + expect(format.hasUnits).to.be.true; - const testEntry = { magnitude: 12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "12:6 1/2" }; + const testEntry = { magnitude: 12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "12:6 1/2" }; - const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); - const spec = await FormatterSpec.create("test", format, unitsProvider, unit); + const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); + const spec = await FormatterSpec.create("test", format, unitsProvider, unit); - Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(false); - } catch (err: any) { - assert.strictEqual(err.message, "The Format test has a invalid unit specification.."); - } + expect(() => Formatter.formatQuantity(testEntry.magnitude, spec)).to.throw("The Format test has a invalid unit specification."); }); it("Bad Composite unit with offset", async () => { @@ -76,24 +71,18 @@ describe("Composite Formats tests:", () => { uomSeparator: "", }; - try { - const format = new Format("test"); - await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + const format = new Format("test"); + await format.fromJSON(unitsProvider, formatData).catch(() => { }); + expect(format.hasUnits).to.be.true; - const testEntry = { - magnitude: 12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "12:6 1/2", - }; + const testEntry = { + magnitude: 12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "12:6 1/2", + }; - const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); - const spec = await FormatterSpec.create("test", format, unitsProvider, unit); + const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); + const spec = await FormatterSpec.create("test", format, unitsProvider, unit); - Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(false); - } catch (err: any) { - assert.strictEqual(err.message, "The Format test has a invalid unit specification.."); - // console.log(err.message); - } + expect(() => Formatter.formatQuantity(testEntry.magnitude, spec)).toThrow("The Format test has a invalid unit specification."); }); it("Single Composite with label override", async () => { @@ -118,7 +107,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.5417'" }, @@ -133,9 +122,8 @@ describe("Composite Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.strictEqual(formattedValue, testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -203,15 +191,15 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits, `Test case number ${testEntry.testCaseNum} failed`); - assert.equal(format.hasFormatTraitSet(FormatTraits.KeepSingleZero), testEntry.keepSingleZero, `Test case number ${testEntry.testCaseNum} failed`); - assert.equal(format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint), testEntry.keepDecimalPoint, `Test case number ${testEntry.testCaseNum} failed`); - assert.equal(format.hasFormatTraitSet(FormatTraits.TrailZeroes), testEntry.trailZeroes, `Test case number ${testEntry.testCaseNum} failed`); + expect(format.hasUnits).to.be.true; + expect(format.hasFormatTraitSet(FormatTraits.KeepSingleZero)).toEqual(testEntry.keepSingleZero); + expect(format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint)).toEqual(testEntry.keepDecimalPoint); + expect(format.hasFormatTraitSet(FormatTraits.TrailZeroes)).toEqual(testEntry.trailZeroes); const spec = await FormatterSpec.create("test", format, unitsProvider, new BasicUnit(unit.name, unit.label, unit.contextId)); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.equal(formattedValue, testEntry.result, `Test case number ${testEntry.testCaseNum} failed`); - assert.isTrue(formattedValue.length > 0, `Test case number ${testEntry.testCaseNum} failed`); + expect(formattedValue).toEqual(testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); } }); @@ -241,7 +229,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12'-6 1/2\"" }, @@ -257,9 +245,8 @@ describe("Composite Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.strictEqual(formattedValue, testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -289,7 +276,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12:6 1/2" }, @@ -305,9 +292,8 @@ describe("Composite Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.strictEqual(formattedValue, testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -333,7 +319,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-150 1/2\"" }, @@ -349,8 +335,9 @@ describe("Composite Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); + // eslint-disable-next-line no-console // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -376,7 +363,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-150 1/2 in" }, @@ -391,9 +378,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.strictEqual(formattedValue, testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -419,7 +405,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-150.5\"" }, @@ -434,8 +420,7 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -465,7 +450,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -1.0, unit: { name: "Units.M", label: "m", contextId: "Units.LENGTH" }, result: "-3'-3 3/8\"" }, @@ -479,9 +464,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue.length > 0); - assert.isTrue(formattedValue === testEntry.result); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -511,7 +495,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: -1.0, unit: { name: "Units.M", label: "m", contextId: "Units.LENGTH" }, result: "-3'-3.37\"" }, @@ -525,9 +509,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue === testEntry.result); - assert.isTrue(formattedValue.length > 0); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue).toEqual(testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); } }); @@ -553,7 +536,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: 0.5283367223037165, unit: { name: "Units.RAD", label: "rad", contextId: "Units.ANGLE" }, result: "30.27146435�" }, @@ -564,9 +547,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue === testEntry.result); - assert.isTrue(formattedValue.length > 0); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue).toEqual(testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); } }); @@ -592,7 +574,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: 0.5283367223037165, unit: { name: "Units.RAD", label: "rad", contextId: "Units.ANGLE" }, result: "30.0�" }, @@ -603,9 +585,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue === testEntry.result); - assert.isTrue(formattedValue.length > 0); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue).toEqual(testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); } }); @@ -639,7 +620,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: 0.5283367223037165, unit: { name: "Units.RAD", label: "rad", contextId: "Units.ANGLE" }, result: "30�16'17.27166\"" }, @@ -650,9 +631,8 @@ describe("Composite Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.isTrue(formattedValue === testEntry.result); - assert.isTrue(formattedValue.length > 0); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue).toEqual(testEntry.result); + expect(formattedValue.length).toBeGreaterThan(0); } }); it("Rad to DMS (precision 3)", async () => { @@ -685,7 +665,7 @@ describe("Composite Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const testQuantityData = [ { magnitude: 0.5283367223037165, unit: { name: "Units.RAD", label: "rad", contextId: "Units.ANGLE" }, result: "30�16'17.272\"" }, @@ -702,8 +682,7 @@ describe("Composite Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); expect(formattedValue).to.be.eql(testEntry.result); - assert.isTrue(formattedValue.length > 0); - // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); + expect(formattedValue.length).toBeGreaterThan(0); } }); @@ -714,7 +693,7 @@ describe("Composite Formats tests:", () => { composite: { includeZero: true, spacer: "", - units: [{name: "Units.KM"},{name: "Units.M", label: ""},{name: "Units.CM", label: "CM"},{name: "Units.MM", label: "'"}], + units: [{ name: "Units.KM" }, { name: "Units.M", label: "" }, { name: "Units.CM", label: "CM" }, { name: "Units.MM", label: "'" }], }, formatTraits: ["keepSingleZero", "applyRounding"], precision: 4, @@ -722,7 +701,7 @@ describe("Composite Formats tests:", () => { uomSeparator: "", }; const format = new Format("test"); - assert.isDefined(format); + expect(format).toBeDefined(); await format.fromJSON(unitsProvider, compositeFormat).catch(() => { }); expect(JSON.stringify(format.toJSON().composite)).to.eql(`{"spacer":"","includeZero":true,"units":[{"name":"Units.KM"},{"name":"Units.M","label":""},{"name":"Units.CM","label":"CM"},{"name":"Units.MM","label":"'"}]}`); diff --git a/core/quantity/src/test/Formatting.test.ts b/core/quantity/src/test/Formatting.test.ts index 215d28361061..10d96a683456 100644 --- a/core/quantity/src/test/Formatting.test.ts +++ b/core/quantity/src/test/Formatting.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { assert, expect } from "chai"; +import { describe, expect, it } from "vitest"; import { QuantityError } from "../Exception"; import { Format } from "../Formatter/Format"; import { DecimalPrecision, FormatTraits, parseFormatTrait } from "../Formatter/FormatEnums"; @@ -22,7 +22,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'type' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'type' attribute.`); }); }); @@ -37,7 +38,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test does not have the required 'precision' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test does not have the required 'precision' attribute.`); }); }); @@ -53,7 +55,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'precision' attribute. It should be an integer.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'precision' attribute. It should be an integer.`); }); }); @@ -69,7 +72,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'precision' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'precision' attribute.`); }); }); @@ -86,7 +90,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'showSignOption' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'showSignOption' attribute.`); }); }); @@ -102,7 +107,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'precision' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'precision' attribute.`); }); }); @@ -118,7 +124,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'formatTraits' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'formatTraits' attribute.`); }); }); @@ -165,7 +172,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'minWidth' attribute. It should be a positive integer.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'minWidth' attribute. It should be a positive integer.`); }); }); @@ -181,9 +189,7 @@ describe("Formatting tests:", () => { }; const testFormat = new Format("test"); - await testFormat.fromJSON(unitsProvider, json).catch(() => { - assert.isTrue(false); - }); + await expect(testFormat.fromJSON(unitsProvider, json)).resolves.not.toThrow(); }); it("Bad decimal separator value", async () => { @@ -198,7 +204,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'decimalSeparator' attribute. It should be an empty or one character string.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'decimalSeparator' attribute. It should be an empty or one character string.`); }); }); @@ -213,9 +220,7 @@ describe("Formatting tests:", () => { }; const testFormat = new Format("test"); - await testFormat.fromJSON(unitsProvider, json).catch(() => { - assert.isTrue(false); - }); + await expect(testFormat.fromJSON(unitsProvider, json)).resolves.not.toThrow(); }); it("Bad thousand separator value", async () => { @@ -230,7 +235,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'thousandSeparator' attribute. It should be an empty or one character string.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'thousandSeparator' attribute. It should be an empty or one character string.`); }); }); @@ -245,9 +251,7 @@ describe("Formatting tests:", () => { }; const testFormat = new Format("test"); - await testFormat.fromJSON(unitsProvider, json).catch(() => { - assert.isTrue(false); - }); + await expect(testFormat.fromJSON(unitsProvider, json)).resolves.not.toThrow(); }); it("Bad uom separator value", async () => { @@ -261,7 +265,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'uomSeparator' attribute. It should be an empty or one character string.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'uomSeparator' attribute. It should be an empty or one character string.`); }); }); @@ -275,9 +280,7 @@ describe("Formatting tests:", () => { }; const testFormat = new Format("test"); - await testFormat.fromJSON(unitsProvider, json).catch(() => { - assert.isTrue(false); - }); + await expect(testFormat.fromJSON(unitsProvider, json)).resolves.not.toThrow(); }); it("Bad station separator value", async () => { @@ -293,7 +296,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'stationSeparator' attribute. It should be an empty or one character string.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'stationSeparator' attribute. It should be an empty or one character string.`); }); }); @@ -309,9 +313,7 @@ describe("Formatting tests:", () => { }; const testFormat = new Format("test"); - await testFormat.fromJSON(unitsProvider, json).catch(() => { - assert.isTrue(false); - }); + await expect(testFormat.fromJSON(unitsProvider, json)).resolves.not.toThrow(); }); it("Scientific type is required", async () => { @@ -326,7 +328,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test is 'Scientific' type therefore the attribute 'scientificType' is required.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test is 'Scientific' type therefore the attribute 'scientificType' is required.`); }); }); @@ -343,7 +346,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'scientificType' attribute.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'scientificType' attribute.`); }); }); @@ -364,7 +368,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has a Composite with no valid 'units'`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has a Composite with no valid 'units'`); }); }); @@ -389,7 +394,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `Invalid unit name 'Units.F'.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`Invalid unit name 'Units.F'.`); }); }); @@ -419,7 +425,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The unit Units.FT has a duplicate name.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The unit Units.FT has a duplicate name.`); }); }); @@ -435,7 +442,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test is 'Station' type therefore the attribute 'stationOffsetSize' is required.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test is 'Station' type therefore the attribute 'stationOffsetSize' is required.`); }); }); @@ -452,7 +460,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has an invalid 'stationOffsetSize' attribute. It should be a positive integer.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has an invalid 'stationOffsetSize' attribute. It should be a positive integer.`); }); }); @@ -482,7 +491,8 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json).catch((err) => { - assert.isTrue(err instanceof QuantityError && err.message === `The Format test has a Composite with an invalid 'spacer' attribute. It should be an empty or one character string.`); + expect(err).toBeInstanceOf(QuantityError); + expect(err.message).toEqual(`The Format test has a Composite with an invalid 'spacer' attribute. It should be an empty or one character string.`); }); }); @@ -498,27 +508,27 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.ApplyRounding)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.ExponentOnlyNegative)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.FractionDash)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.KeepDecimalPoint)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.PrependUnitLabel)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.TrailZeroes)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.Use1000Separator)); - assert.isTrue(testFormat.hasFormatTraitSet(FormatTraits.ZeroEmpty)); + expect(testFormat.hasFormatTraitSet(FormatTraits.ApplyRounding)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.ExponentOnlyNegative)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.FractionDash)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.KeepDecimalPoint)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.PrependUnitLabel)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.TrailZeroes)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.Use1000Separator)).to.be.true; + expect(testFormat.hasFormatTraitSet(FormatTraits.ZeroEmpty)).to.be.true; const outJson = testFormat.toJSON(); - assert.isTrue(outJson.formatTraits!.length === 10); + expect(outJson.formatTraits!.length).toEqual(10); // ensure we can modify const modifiedFormatProps = { ...outJson, formatTraits: ["keepSingleZero"], precision: 3 }; const modifiedFormat = new Format("modified"); await modifiedFormat.fromJSON(unitsProvider, modifiedFormatProps); - assert.isTrue(modifiedFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)); - assert.isFalse(modifiedFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)); - assert.isTrue(modifiedFormat.precision === DecimalPrecision.Three); + expect(modifiedFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)).to.be.true; + expect(modifiedFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)).to.be.false; + expect(modifiedFormat.precision).toEqual(DecimalPrecision.Three); }); it("Read/Write Empty Format Traits", async () => { @@ -533,19 +543,19 @@ describe("Formatting tests:", () => { const testFormat = new Format("test"); await testFormat.fromJSON(unitsProvider, json); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.ApplyRounding)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.ExponentOnlyNegative)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.FractionDash)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.KeepDecimalPoint)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.PrependUnitLabel)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.TrailZeroes)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.Use1000Separator)); - assert.isFalse(testFormat.hasFormatTraitSet(FormatTraits.ZeroEmpty)); + expect(testFormat.hasFormatTraitSet(FormatTraits.ApplyRounding)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.ExponentOnlyNegative)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.FractionDash)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.KeepDecimalPoint)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.KeepSingleZero)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.PrependUnitLabel)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.ShowUnitLabel)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.TrailZeroes)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.Use1000Separator)).to.be.false; + expect(testFormat.hasFormatTraitSet(FormatTraits.ZeroEmpty)).to.be.false; const outJson = testFormat.toJSON(); - assert.isTrue(outJson.formatTraits!.length === 0); + expect(outJson.formatTraits!.length).toEqual(0); }); it("Load Formats from Json", async () => { @@ -726,25 +736,25 @@ describe("Formatting tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); if (formatData.hasOwnProperty("precision")) - assert.isTrue(format.precision === formatData.precision); - assert.isTrue(format.type.toUpperCase() === formatData.type.toUpperCase()); + expect(format.precision).toEqual(formatData.precision); + expect(format.type.toUpperCase()).toEqual(formatData.type.toUpperCase()); if (formatData.hasOwnProperty("uomSeparator")) - assert.isTrue(format.uomSeparator === formatData.uomSeparator); + expect(format.uomSeparator).toEqual(formatData.uomSeparator); for (const traitStr of formatData.formatTraits) { const traitToValidate = parseFormatTrait(traitStr, "format.test"); if (traitToValidate !== undefined) - assert.isTrue(format.hasFormatTraitSet(traitToValidate)); + expect(format.hasFormatTraitSet(traitToValidate)).to.be.true; } if (formatData.hasOwnProperty("composite")) { - assert.isTrue(format.hasUnits === true); - assert.isTrue(format.units!.length === formatData.composite!.units.length); + expect(format.hasUnits).to.be.true; + expect(format.units!.length).toEqual(formatData.composite!.units.length); } const jsonData = format.toJSON(); - assert.isTrue(jsonData.type.toUpperCase() === format.type.toUpperCase()); + expect(jsonData.type.toUpperCase()).toEqual(format.type.toUpperCase()); if (formatData.hasOwnProperty("showSignOption")) { - assert.isTrue(formatData.showSignOption!.toUpperCase() === jsonData.showSignOption!.toUpperCase()); + expect(formatData.showSignOption!.toUpperCase()).toEqual(jsonData.showSignOption!.toUpperCase()); } } }); @@ -765,16 +775,16 @@ describe("Formatting tests:", () => { ], }; - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes) === false); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)); + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)).to.be.true; }); it("isFormatTraitSetInProps works properly", () => { @@ -785,16 +795,16 @@ describe("Formatting tests:", () => { ], }; - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)); - assert.isFalse(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes)); + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)).to.be.false; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes)).to.be.true; }); it("show old/optional trait format works properly", () => { @@ -803,16 +813,16 @@ describe("Formatting tests:", () => { formatTraits: "trailZeroes,keepSingleZero,zeroEmpty,keepDecimalPoint,applyRounding,fractionDash,showUnitLabel,prependUnitLabel,use1000Separator,exponentOnlyNegative", }; - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)); - assert.isTrue(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)); + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ApplyRounding)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ExponentOnlyNegative)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.FractionDash)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepDecimalPoint)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.KeepSingleZero)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.PrependUnitLabel)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ShowUnitLabel)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.TrailZeroes)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.Use1000Separator)).to.be.true; + expect(Format.isFormatTraitSetInProps(formatProps, FormatTraits.ZeroEmpty)).to.be.true; }); it("deserialization of custom Formats is consistent", async () => { @@ -834,11 +844,11 @@ describe("Formatting tests:", () => { // Assertions // eslint-disable-next-line guard-for-in for (const key in formatProps) { - assert(jsonObj.hasOwnProperty(key), `jsonObj is missing property ${key}`); + expect(jsonObj.hasOwnProperty(key)).to.be.true; const formatPropValue = formatProps[key as keyof FormatProps]; const jsonObjValue = jsonObj[key as keyof FormatProps]; - assert(typeof formatPropValue === typeof jsonObjValue, `Property ${key} types do not match`); + expect(typeof formatPropValue).toEqual(typeof jsonObjValue); if (Array.isArray(formatPropValue) && Array.isArray(jsonObjValue)) { expect(formatPropValue).to.have.members(jsonObjValue, `Property ${key} does not match`); } else { @@ -932,11 +942,11 @@ describe("Formatting tests:", () => { // Assertions // eslint-disable-next-line guard-for-in for (const key in formatProps) { - assert(jsonObj.hasOwnProperty(key), `jsonObj is missing property ${key}`); + expect(jsonObj.hasOwnProperty(key)).to.be.true; const formatPropValue = formatProps[key as keyof FormatProps]; const jsonObjValue = jsonObj[key as keyof FormatProps]; - assert(typeof formatPropValue === typeof jsonObjValue, `Property ${key} types do not match`); + expect(typeof formatPropValue).toEqual(typeof jsonObjValue); if (Array.isArray(formatPropValue) && Array.isArray(jsonObjValue)) { expect(formatPropValue).to.have.members(jsonObjValue, `Property ${key} does not match`); } else { diff --git a/core/quantity/src/test/NumericFormat.test.ts b/core/quantity/src/test/NumericFormat.test.ts index 0860e8be3ba8..0711775faa6d 100644 --- a/core/quantity/src/test/NumericFormat.test.ts +++ b/core/quantity/src/test/NumericFormat.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { assert } from "chai"; +import { describe, expect, it } from "vitest"; import { Format } from "../Formatter/Format"; import { FormatterSpec } from "../Formatter/FormatterSpec"; import { Formatter } from "../Formatter/Formatter"; @@ -27,7 +27,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.5417 ft" }, @@ -45,7 +45,7 @@ describe("Numeric Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -64,7 +64,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.5417 ft" }, @@ -82,7 +82,7 @@ describe("Numeric Formats tests:", () => { const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -101,7 +101,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const clonedFormat = format.clone({ showOnlyPrimaryUnit: true, @@ -124,7 +124,7 @@ describe("Numeric Formats tests:", () => { const spec = await FormatterSpec.create("test", clonedFormat, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -141,7 +141,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-ft 13" }, @@ -156,7 +156,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -174,7 +174,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "(ft 13)" }, @@ -188,7 +188,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -206,7 +206,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.542 ft" }, @@ -222,7 +222,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -240,7 +240,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "12.542 ft" }, @@ -254,7 +254,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -271,7 +271,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-13.0 ft" }, @@ -286,7 +286,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -303,7 +303,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.54 ft" }, @@ -318,7 +318,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -335,7 +335,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.54 ft" }, @@ -350,7 +350,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -366,7 +366,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.5416666666667, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12.54 ft" }, @@ -381,7 +381,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -399,7 +399,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.541e5, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-0.1254e7 ft" }, @@ -413,7 +413,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -431,7 +431,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.541e5, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-1.2541e6 ft" }, @@ -445,7 +445,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -462,7 +462,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -1.01e12, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-1.01e12 ft" }, @@ -473,7 +473,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); } }); @@ -489,7 +489,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: 123.456, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "1+23.46" }, @@ -503,7 +503,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -521,7 +521,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: 123.456, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "0+123.46" }, @@ -535,7 +535,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -553,7 +553,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: 123.456, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "0+123.46" }, @@ -567,7 +567,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -584,7 +584,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const testQuantityData = [ { magnitude: -12.125, unit: { name: "Units.FT", label: "ft", contextId: "Units.LENGTH" }, result: "-12-1/8 ft" }, @@ -602,7 +602,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", format, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(testEntry.magnitude.toString() + " " + testEntry.unit.label + " => " + formattedValue); } }); @@ -619,7 +619,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const clonedFormat = format.clone({ showOnlyPrimaryUnit: true, @@ -643,7 +643,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", clonedFormat, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(`${testEntry.magnitude.toString()} ${testEntry.unit.label} => ${formattedValue}`); } }); @@ -660,7 +660,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const clonedFormat = format.clone({ showOnlyPrimaryUnit: true, @@ -684,7 +684,7 @@ describe("Numeric Formats tests:", () => { const unit = new BasicUnit(testEntry.unit.name, testEntry.unit.label, testEntry.unit.contextId); const spec = await FormatterSpec.create("test", clonedFormat, unitsProvider, unit); const formattedValue = Formatter.formatQuantity(testEntry.magnitude, spec); - assert.strictEqual(formattedValue, testEntry.result); + expect(formattedValue).toEqual(testEntry.result); // console.log(`${testEntry.magnitude.toString()} ${testEntry.unit.label} => ${formattedValue}`); } }); @@ -701,7 +701,7 @@ describe("Numeric Formats tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; const primaryUnit: UnitProps = { name: "Units.FT", @@ -722,7 +722,7 @@ describe("Numeric Formats tests:", () => { }, }); - assert.strictEqual(clonedFormat.units?.length, 1); - assert.strictEqual(clonedFormat.units![0][1], "foot"); + expect(clonedFormat.units?.length).toEqual(1); + expect(clonedFormat.units![0][1]).toEqual("foot"); }); }); diff --git a/core/quantity/src/test/Parsing.test.ts b/core/quantity/src/test/Parsing.test.ts index c0f048363559..b50a5aae54c6 100644 --- a/core/quantity/src/test/Parsing.test.ts +++ b/core/quantity/src/test/Parsing.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { assert, expect } from "chai"; +import { describe, expect, it} from "vitest"; import { Format } from "../Formatter/Format"; import { FormatterSpec } from "../Formatter/FormatterSpec"; import { Formatter } from "../Formatter/Formatter"; @@ -18,16 +18,16 @@ const logTestOutput = false; describe("Parsing tests:", () => { it("Bad unit", async () => { const testUnit: UnitProps = new BadUnit(); - assert.isTrue(testUnit.name.length === 0); - assert.isTrue(testUnit.label.length === 0); - assert.isTrue(testUnit.phenomenon.length === 0); - assert.isTrue(testUnit.isValid === false); + expect(testUnit.name.length).toEqual(0); + expect(testUnit.label.length).toEqual(0); + expect(testUnit.phenomenon.length).toEqual(0); + expect(testUnit.isValid).to.be.false; }); it("Quantity constructor", async () => { const noUnitQty = new Quantity(); - assert.isTrue(noUnitQty.magnitude === 0); - assert.isTrue(noUnitQty.isValid === false); + expect(noUnitQty.magnitude).toEqual(0); + expect(noUnitQty.isValid).to.be.false; }); it("Quantity convert Meters to inches", async () => { @@ -38,8 +38,8 @@ describe("Parsing tests:", () => { const conversion = await unitsProvider.getConversion(meterUnit, inchUnit); const inchesQty = meterQty.convertTo(inchUnit, conversion); - assert.isTrue(meterQty.magnitude === 1.0); - assert.isTrue(inchesQty!.magnitude === meterQty.magnitude * conversion.factor); + expect(meterQty.magnitude).toEqual(1.0); + expect(inchesQty!.magnitude).toEqual(meterQty.magnitude * conversion.factor); }); it("Convert units", async () => { @@ -60,7 +60,7 @@ describe("Parsing tests:", () => { for (const toVal of tstVal.cvtTo) { const toUnit = await unitsProvider.findUnit(toVal.label, fromUnit.phenomenon); const conversionData = await unitsProvider.getConversion(fromUnit, toUnit); - assert.isTrue(Math.fround(conversionData.factor) === toVal.factor); + expect(Math.fround(conversionData.factor)).toEqual(toVal.factor); } } }); @@ -94,10 +94,10 @@ describe("Parsing tests:", () => { let i = 0; for (const test of tests) { const tokens = Parser.parseQuantitySpecification(test.input, format); - assert.isTrue(tokens.length === test.expectedTokens.length); + expect(tokens.length).toEqual(test.expectedTokens.length); for (let j = 0; j < tokens.length; j++) { - assert.isTrue(tokens[j].value === test.expectedTokens[j].value); + expect(tokens[j].value).toEqual(test.expectedTokens[j].value); } i = i + 1; @@ -128,10 +128,10 @@ describe("Parsing tests:", () => { let i = 0; for (const test of tests) { const tokens = Parser.parseQuantitySpecification(test.input, format); - assert.isTrue(tokens.length === test.expectedTokens.length); + expect(tokens.length).toEqual(test.expectedTokens.length); for (let j = 0; j < tokens.length; j++) { - assert.isTrue(tokens[j].value === test.expectedTokens[j].value); + expect(tokens[j].value).toEqual(test.expectedTokens[j].value); } i = i + 1; @@ -155,7 +155,7 @@ describe("Parsing tests:", () => { for (const lookupEntry of expectedLookupResults) { const unit = await unitProvider.findUnit(lookupEntry.label, (lookupEntry.unitContext.length > 0) ? lookupEntry.unitContext : undefined); - assert.isTrue(unit.name === lookupEntry.name); + expect(unit.name).toEqual(lookupEntry.name); } }); @@ -177,7 +177,7 @@ describe("Parsing tests:", () => { for (const toVal of tstVal.cvtTo) { const toUnit = await unitsProvider.findUnit(toVal.label, fromUnit.phenomenon); const conversionData = await unitsProvider.getConversion(fromUnit, toUnit); - assert.isTrue(Math.fround(conversionData.factor) === toVal.factor); + expect(Math.fround(conversionData.factor)).toEqual(toVal.factor); } } }); @@ -219,13 +219,13 @@ describe("Parsing tests:", () => { const unitsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); // console.log (`quantityProps=${JSON.stringify(quantityProps)}`); - expect(Math.fround(quantityProps.magnitude)).to.eql(Math.fround(testEntry.quantity.magnitude)); - expect(quantityProps.unit.name).to.eql(testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -257,8 +257,8 @@ describe("Parsing tests:", () => { for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); // console.log (`quantityProps=${JSON.stringify(quantityProps)}`); - expect(Math.fround(quantityProps.magnitude)).to.eql(Math.fround(testEntry.quantity.magnitude)); - expect(quantityProps.unit.name).to.eql(testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -295,12 +295,12 @@ describe("Parsing tests:", () => { const unitsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); - assert.isTrue(Math.fround(quantityProps.magnitude) === Math.fround(testEntry.quantity.magnitude)); - assert.isTrue(quantityProps.unit.name === testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -336,12 +336,12 @@ describe("Parsing tests:", () => { const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); - assert.isTrue(Math.fround(quantityProps.magnitude) === Math.fround(testEntry.quantity.magnitude)); - assert.isTrue(quantityProps.unit.name === testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -382,12 +382,12 @@ describe("Parsing tests:", () => { const unitsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); - assert.isTrue(Math.fround(quantityProps.magnitude) === Math.fround(testEntry.quantity.magnitude)); - assert.isTrue(quantityProps.unit.name === testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -413,12 +413,12 @@ describe("Parsing tests:", () => { const unitsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(!format.hasUnits); + expect(format.hasUnits).to.be.false; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); - assert.isTrue(Math.fround(quantityProps.magnitude) === Math.fround(testEntry.quantity.magnitude)); - assert.isTrue(quantityProps.unit.name === testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -451,7 +451,7 @@ describe("Parsing tests:", () => { const unitsAndAltLabelsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsAndAltLabelsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; const persistenceUnit = await unitsAndAltLabelsProvider.findUnitByName("Units.M"); @@ -493,7 +493,7 @@ describe("Parsing tests:", () => { const unitsProvider = new TestUnitsProvider(); const format = new Format("test"); await format.fromJSON(unitsProvider, formatData).catch(() => { }); - assert.isTrue(format.hasUnits); + expect(format.hasUnits).to.be.true; for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); @@ -545,8 +545,8 @@ describe("Parsing tests:", () => { for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry.value, format, unitsProvider); // console.log (`quantityProps=${JSON.stringify(quantityProps)}`); - expect(Math.fround(quantityProps.magnitude)).to.eql(Math.fround(testEntry.quantity.magnitude)); - expect(quantityProps.unit.name).to.eql(testEntry.quantity.unitName); + expect(Math.fround(quantityProps.magnitude)).toEqual(Math.fround(testEntry.quantity.magnitude)); + expect(quantityProps.unit.name).toEqual(testEntry.quantity.unitName); } }); @@ -590,8 +590,8 @@ describe("Parsing tests:", () => { for (const testEntry of testData) { const quantityProps = await Parser.parseIntoQuantity(testEntry, format, unitsProvider); - expect(quantityProps.isValid).to.eql(false); - expect(quantityProps.magnitude).to.eql(0); + expect(quantityProps.isValid).to.be.false; + expect(quantityProps.magnitude).toEqual(0); } }); @@ -694,7 +694,7 @@ describe("Synchronous Parsing tests:", async () => { else if (Parser.isParseError(parseResult)) console.log(`input=${testEntry.value} error=${parseResult.error}`); // eslint-disable-line no-console } - assert.isTrue(Parser.isParsedQuantity(parseResult)); + expect(Parser.isParsedQuantity(parseResult)).to.be.true; if (Parser.isParsedQuantity(parseResult)) expect(parseResult.value).closeTo(testEntry.magnitude, 0.0001); } @@ -744,9 +744,9 @@ describe("Synchronous Parsing tests:", async () => { else if (Parser.isParseError(parseResult)) console.log(`input=${testEntry} error=${parseResult.error}`); // eslint-disable-line no-console } - assert.isTrue(Parser.isParseError(parseResult)); + expect(Parser.isParseError(parseResult)).to.be.true; if (Parser.isParseError(parseResult)) - expect(parseResult.error).to.eql(ParseError.MathematicOperationFoundButIsNotAllowed); + expect(parseResult.error).toEqual(ParseError.MathematicOperationFoundButIsNotAllowed); } }); @@ -784,7 +784,7 @@ describe("Synchronous Parsing tests:", async () => { else if (Parser.isParseError(parseResult)) console.log(`input=${testEntry.value} error=${parseResult.error}`); // eslint-disable-line no-console } - assert.isTrue(Parser.isParsedQuantity(parseResult)); + expect(Parser.isParsedQuantity(parseResult)).to.be.true; if (Parser.isParsedQuantity(parseResult)) expect(parseResult.value).closeTo(testEntry.magnitude, 0.0001); } @@ -835,7 +835,7 @@ describe("Synchronous Parsing tests:", async () => { else if (Parser.isParseError(parseResult)) console.log(`input=${testEntry.value} error=${parseResult.error}`); // eslint-disable-line no-console } - assert.isTrue(Parser.isParsedQuantity(parseResult)); + expect(Parser.isParsedQuantity(parseResult)).to.be.true; if (Parser.isParsedQuantity(parseResult)) expect(parseResult.value).closeTo(testEntry.magnitude, 0.0001); } @@ -876,7 +876,7 @@ describe("Synchronous Parsing tests:", async () => { for (const testEntry of testData) { const parseResult = Parser.parseQuantityString(testEntry.value, parserSpec); - assert.isTrue(Parser.isParsedQuantity(parseResult)); + expect(Parser.isParsedQuantity(parseResult)).to.be.true; if (Parser.isParsedQuantity(parseResult)) { if (logTestOutput) { // eslint-disable-next-line no-console @@ -910,7 +910,7 @@ describe("Synchronous Parsing tests:", async () => { for (const testEntry of testData) { const parseResult = Parser.parseQuantityString(testEntry.value, angleParserSpec); - assert.isTrue(Parser.isParsedQuantity(parseResult)); + expect(Parser.isParsedQuantity(parseResult)).to.be.true; if (Parser.isParsedQuantity(parseResult)) { if (logTestOutput) { // eslint-disable-next-line no-console diff --git a/core/quantity/src/test/Quantity.test.ts b/core/quantity/src/test/Quantity.test.ts index a631e508d64b..30c8d7a43332 100644 --- a/core/quantity/src/test/Quantity.test.ts +++ b/core/quantity/src/test/Quantity.test.ts @@ -2,7 +2,7 @@ * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ -import { expect } from "chai"; +import { describe, expect, it } from "vitest"; import { almostEqual } from "../Quantity"; describe("Quantity", () => { diff --git a/core/quantity/src/test/Ratio.test.ts b/core/quantity/src/test/Ratio.test.ts index 70617d4d2796..26d9e1df3f08 100644 --- a/core/quantity/src/test/Ratio.test.ts +++ b/core/quantity/src/test/Ratio.test.ts @@ -1,4 +1,4 @@ -import { assert, expect } from "chai"; +import { assert, describe, expect, it } from "vitest"; import { Format } from "../Formatter/Format"; import { Formatter } from "../Formatter/Formatter"; @@ -34,11 +34,11 @@ describe("Ratio format tests", () => { const unitsProvider = new TestUnitsProvider(); const ratioFormat = new Format("Ratio"); - await ratioFormat.fromJSON(unitsProvider, ratioJson).catch(() => {}); - assert.isTrue(ratioFormat.hasUnits); + await ratioFormat.fromJSON(unitsProvider, ratioJson).catch(() => { }); + expect(ratioFormat.hasUnits).to.be.true; const persistenceUnit: UnitProps = await unitsProvider.findUnitByName(persistenceUnitStr); - assert.isTrue(persistenceUnit.isValid); + expect(persistenceUnit.isValid).to.be.true; const ratioFormatterSpec = await FormatterSpec.create(`${ratioType}`, ratioFormat, unitsProvider, persistenceUnit); // persisted unit const ratioParser = await ParserSpec.create(ratioFormat, unitsProvider, persistenceUnit); // persistence unit @@ -132,11 +132,11 @@ describe("Ratio format tests", () => { { magnitude: 3, ratio: "1:0.333", precision: 3 }, { magnitude: 3, ratio: "1:0.3333", precision: 4 }, - { magnitude: 0.667, ratio: "1:1.49925", precision: 5}, - { magnitude: 0.667, ratio: "1:1.4993", precision: 4}, - { magnitude: 0.667, ratio: "1:1.499", precision: 3}, - { magnitude: 0.667, ratio: "1:1.5", precision: 2}, - { magnitude: 0.667, ratio: "1:1.5", precision: 1}, + { magnitude: 0.667, ratio: "1:1.49925", precision: 5 }, + { magnitude: 0.667, ratio: "1:1.4993", precision: 4 }, + { magnitude: 0.667, ratio: "1:1.499", precision: 3 }, + { magnitude: 0.667, ratio: "1:1.5", precision: 2 }, + { magnitude: 0.667, ratio: "1:1.5", precision: 1 }, ]; await testRatioType("OneToN", testData); }); @@ -180,9 +180,9 @@ describe("Ratio format tests", () => { try { await ratioFormat.fromJSON(unitsProvider, ratioJson); expect.fail("Expected error was not thrown"); - } catch (e: any){ - assert.strictEqual(e.message, "The Format Ratio is 'Ratio' type therefore the attribute 'ratioType' is required."); - assert.instanceOf(e, QuantityError); + } catch (e: any) { + expect(e.message).toEqual("The Format Ratio is 'Ratio' type therefore the attribute 'ratioType' is required."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -203,9 +203,9 @@ describe("Ratio format tests", () => { try { await ratioFormat.fromJSON(unitsProvider, ratioJson); expect.fail("Expected error was not thrown"); - } catch (e: any){ - assert.strictEqual(e.message, "The Format Ratio has an invalid 'ratioType' attribute."); - assert.instanceOf(e, QuantityError); + } catch (e: any) { + expect(e.message).toEqual("The Format Ratio has an invalid 'ratioType' attribute."); + expect(e).toBeInstanceOf(QuantityError); } }); @@ -250,8 +250,8 @@ describe("Ratio format tests", () => { const testData: TestData[] = [ { magnitude: 1.0 / 7, ratio: "143:1000" }, { magnitude: 2.0 / 7, ratio: "143:500" }, // comes down from 286:1000 - { magnitude: 1.0 / 7, ratio: "1429:10000", precision: 4}, - { magnitude: 2.0 / 7, ratio: "2857:10000", precision: 4}, + { magnitude: 1.0 / 7, ratio: "1429:10000", precision: 4 }, + { magnitude: 2.0 / 7, ratio: "2857:10000", precision: 4 }, ]; await testRatioType("useGreatestCommonDivisor", testData); }); @@ -280,17 +280,17 @@ describe("Ratio format tests", () => { assert.fail("Failed to create ratio format from JSON"); } - assert.isTrue(ratioFormat.hasUnits, "Ratio format should have units"); + expect(ratioFormat.hasUnits).to.be.true; const persistenceUnit: UnitProps = await unitsProvider.findUnitByName(persistenceUnitStr); - assert.isTrue(persistenceUnit.isValid, "Persistence unit should be valid"); + expect(persistenceUnit.isValid).to.be.true; const ratioParser = await ParserSpec.create(ratioFormat, unitsProvider, persistenceUnit); for (const entry of testData) { const parserRatioResult = Parser.parseQuantityString(entry.ratio, ratioParser); if (entry.parseError) { // if it is expecting an error - assert.isTrue(Parser.isParseError(parserRatioResult)); + expect(Parser.isParseError(parserRatioResult)).to.be.true; // Check if parserRatioResult has the err property, which signifies a ParseQuantityError if ("error" in parserRatioResult) expect(parserRatioResult.error).to.equal(entry.parseError); @@ -330,10 +330,10 @@ describe("Ratio format tests", () => { { magnitude: 1.0, ratio: "10:0", parseError: ParseError.MathematicOperationFoundButIsNotAllowed }, { magnitude: 1.0, ratio: "", parseError: ParseError.NoValueOrUnitFoundInString }, - { magnitude: 1.0, ratio: "1:", parseError: ParseError.NoValueOrUnitFoundInString}, - { magnitude: 1.0, ratio: "1:A", parseError: ParseError.NoValueOrUnitFoundInString}, + { magnitude: 1.0, ratio: "1:", parseError: ParseError.NoValueOrUnitFoundInString }, + { magnitude: 1.0, ratio: "1:A", parseError: ParseError.NoValueOrUnitFoundInString }, - { magnitude: 1.0, ratio: "1:2:3", parseError: ParseError.UnableToConvertParseTokensToQuantity}, + { magnitude: 1.0, ratio: "1:2:3", parseError: ParseError.UnableToConvertParseTokensToQuantity }, ]; await testRatioParser(testData); }); @@ -392,21 +392,21 @@ describe("Ratio format tests", () => { const unitsProvider = new TestUnitsProvider(); const vphRatioFormat = new Format("VpH"); await vphRatioFormat.fromJSON(unitsProvider, vphRatioFormatJson); - assert.isTrue(vphRatioFormat.hasUnits); + expect(vphRatioFormat.hasUnits).to.be.true; const hvpRatioFormat = new Format("HpV"); await hvpRatioFormat.fromJSON(unitsProvider, hpvRatioFormatJson); - assert.isTrue(hvpRatioFormat.hasUnits); + expect(hvpRatioFormat.hasUnits).to.be.true; const vH: UnitProps = await unitsProvider.findUnitByName("Units.VERTICAL_PER_HORIZONTAL"); - assert.isTrue(vH.isValid); + expect(vH.isValid).to.be.true; const hV: UnitProps = await unitsProvider.findUnitByName("Units.HORIZONTAL_PER_VERTICAL"); - assert.isTrue(hV.isValid); + expect(hV.isValid).to.be.true; - const vphToVphFormatter = await FormatterSpec.create("vph_to_vph_formatter", vphRatioFormat, unitsProvider,vH); - const hpvToVphFormatter = await FormatterSpec.create("hvp_to_vph_formatter", vphRatioFormat, unitsProvider,hV); - const vphToHpvFormatter = await FormatterSpec.create("vph_to_hpv_formatter", hvpRatioFormat, unitsProvider,vH); - const hpvToHpvFormatter = await FormatterSpec.create("hpv_to_hpv_formatter", hvpRatioFormat, unitsProvider,hV); + const vphToVphFormatter = await FormatterSpec.create("vph_to_vph_formatter", vphRatioFormat, unitsProvider, vH); + const hpvToVphFormatter = await FormatterSpec.create("hvp_to_vph_formatter", vphRatioFormat, unitsProvider, hV); + const vphToHpvFormatter = await FormatterSpec.create("vph_to_hpv_formatter", hvpRatioFormat, unitsProvider, vH); + const hpvToHpvFormatter = await FormatterSpec.create("hpv_to_hpv_formatter", hvpRatioFormat, unitsProvider, hV); const vphToVphParser = await ParserSpec.create(vphRatioFormat, unitsProvider, vH); const hpvToVphParser = await ParserSpec.create(vphRatioFormat, unitsProvider, hV); diff --git a/core/quantity/vitest.config.mts b/core/quantity/vitest.config.mts new file mode 100644 index 000000000000..7ab32697945d --- /dev/null +++ b/core/quantity/vitest.config.mts @@ -0,0 +1,24 @@ +import { coverageConfigDefaults, defineConfig } from 'vitest/config'; +export default defineConfig({ + test: { + dir: "src", + coverage: { + provider: "v8", + include: [ + "src/**/*" + ], + exclude: [ + ...coverageConfigDefaults.exclude, + "src/test/**/*", + "**/*.d.ts", + "**/*.d.tsx" + ], + reporter: [ + "text-summary", + "lcov", + "cobertura" + ], + reportsDirectory: "./lib/cjs/test/coverage", + } + } +})