Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
824fd40
feat: add ciphers
boorad Jan 3, 2025
e329d7d
TS/Nitro work
boorad Jan 3, 2025
d95faf5
Nitro spec format correction
boorad Jan 7, 2025
c461fd7
C++ compiling and couple tests passing
boorad Jan 7, 2025
50c6b5f
lint & format
boorad Jan 7, 2025
8bf7c4a
bump checkbox component
boorad Jan 7, 2025
99e5563
android build
boorad Jan 7, 2025
7770dcb
ts
boorad Jan 14, 2025
eb5cc32
add getSupportedCiphers
boorad Jan 18, 2025
384777f
lint
boorad Jan 18, 2025
a41e71b
stay close to Node API
boorad Jan 18, 2025
aa01057
cipher init works, js internals closer to recent node updates
boorad Jan 18, 2025
8f7d4ee
more Node API compliance
boorad Jan 18, 2025
21f5bbe
C++ work on update/final, added tests
boorad Jan 22, 2025
a44e4df
troubleshooting
boorad Jan 22, 2025
e933da0
stack -> heap buffer for final()
boorad Jan 23, 2025
1fa6642
wip
boorad Jan 25, 2025
2fb9623
remove CipherType
boorad Jan 26, 2025
031aa21
simplify decoding, 108 pass, 23 fail
boorad Jan 27, 2025
bd63b6b
lint
boorad Jan 27, 2025
437d250
remove copy(), prep for different cipher modes
boorad Jan 28, 2025
1afed70
async not needed on tests
boorad Jan 29, 2025
5f316c4
auth mode supporting methods
boorad Feb 1, 2025
dcd7c69
wip
boorad Feb 3, 2025
eaa0ef1
don't use CipherArgs in implementation
boorad Feb 4, 2025
6e5fa42
wip - GCM & final()
boorad Feb 4, 2025
b438372
chore: rebase hash PR
boorad Feb 5, 2025
c096a36
update closer to 0.x cpp code
boorad Feb 8, 2025
706dcd3
OCB working
boorad Feb 9, 2025
a3ee7a3
owned ArrayBuffers, memory safety, and mode conditionals
boorad Feb 9, 2025
48d71fd
separate init functions for the problematic modes
boorad Feb 10, 2025
46055ff
set up HybridCipher to be a base class
boorad Feb 10, 2025
de153c3
more polymorphism
boorad Feb 11, 2025
5e0611d
AI fucking sucks
boorad Feb 11, 2025
738ce07
inheritance working, CCM still failing in update()
boorad Feb 13, 2025
3f12070
weekend work
boorad Feb 17, 2025
5c229ba
rebase
boorad Mar 2, 2025
9142240
fix: CCM mostly working
boorad Apr 14, 2025
546d583
fix: rest of algos, all tests pass, nitro upgrade
boorad Apr 15, 2025
185adf3
fix: format, lint
boorad Apr 15, 2025
808fd59
fix: someone added a shiny new clang formatter
boorad Apr 15, 2025
3f0e8e4
fix: reviewdog
boorad Apr 15, 2025
298f14f
chore: rules symlinks & more cleanup
boorad Apr 15, 2025
e282cba
fix: PR feedback, typecasting
boorad Apr 15, 2025
ace1b07
chore: ios test results
boorad Apr 15, 2025
65df448
chore: lint/format
boorad Apr 15, 2025
dd36ab9
fix: no need to override these
boorad Apr 15, 2025
4052275
fix: typo
boorad Apr 15, 2025
5303d9e
chore: more cleanup
boorad Apr 15, 2025
ecffb7e
chore: more rules
boorad Apr 15, 2025
5ad023c
chore: android test results
boorad Apr 15, 2025
fa7245c
fix: PR feedback and test fix for string args
boorad Apr 16, 2025
89a976e
chore: til bun --cwd
boorad Apr 16, 2025
225b8bb
fix: lint
boorad Apr 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cursorrules
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,3 @@ tsconfig.tsbuildinfo

# development stuffs
*scratch*

55 changes: 55 additions & 0 deletions .rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# React Native Quick Crypto

Every time you choose to apply a rule(s), explicitly state the rule(s) in the output. You can abbreviate the rule description to a single word or phrase.

## Project Context

- This is a React Native project that offers cryptographic operations in native code.
- It uses Nitro Modules to bridge JS & C++.
- Use the documentation of Nitro Modules if you have access locally to its `llms.txt` file.
- Part of the API strives to be a polyfill of the Node.js `{crypto}` module.
- The goal is to migrate 0.x of this library that uses OpenSSL 1.1.1 to now use OpenSSL 3.3 and modern C++ with Nitro Modules.

## Tech Stack

- React Native
- TypeScript
- Nitro Modules
- C++ 20 and higher, modern
- OpenSSL 3.3 and higher
- TypeScript package manager is `bun` 1.2 or higher
- Don't ask to run tests. They have to be run in an example React Native app.

## Rules

- For C++ includes, do not try to add absolute or relative paths. They have to be resolved by the build system.
- Use smart pointers in C++.
- Use modern C++ features.
- Attempt to reduce the amount of code rather than add more.
- Prefer iteration and modularization over code duplication.

## TypeScript Best Practices

- Use TypeScript for all code; prefer interfaces over types.
- Use lowercase with dashes for directories (e.g., `components/auth-wizard`).
- Favor named exports for components.
- Avoid `any` and enums; use explicit types and maps instead.
- Use functional components with TypeScript interfaces.
- Enable strict mode in TypeScript for better type safety.
- Suggest the optimal implementation considering:
- Performance impact
- Maintenance overhead
- Testing strategy
- Code examples should follow TypeScript best practices.

## React Best Practices

- Minimize the use of `useEffect`. They should be a last resort.
- Use named functions for `useEffect`s with a meaningful function name. Avoid adding unnecessary comments on effect behavior.

## Syntax & Formatting

- Use the `function` keyword for pure functions.
- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.
- Use declarative JSX.
- Use Prettier for consistent code formatting.
1 change: 1 addition & 0 deletions .windsurfrules
2 changes: 1 addition & 1 deletion CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -1 +1 @@
filter=-build/namespaces,-legal/copyright,-build/header_guard,-readability/casting,-runtime/references,-whitespace/newline,-build/c++11,-build/include_subdir,-whitespace/comments,-runtime/int,-runtime/printf
filter=-build/namespaces,-legal/copyright,-build/header_guard,-readability/casting,-runtime/references,-whitespace/newline,-build/c++11,-build/include_subdir,-whitespace/comments,-runtime/int,-runtime/printf,-whitespace/blank_line
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ QuickCrypto can be used as a drop-in replacement for your Web3/Crypto apps to sp

| Version | RN Architecture | Modules |
| ------- | ------ | ------- |
| `1.x` | new [->](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md) | Nitro Modules [->](https://github.com/margelo/react-native-nitro) |
| `1.x` | new [->](https://github.com/reactwg/react-native-new-architecture/blob/main/docs/enable-apps.md) | Nitro Modules [->](https://github.com/mrousavy/nitro) |
| `0.x` | old | Bridge & JSI |

## Benchmarks
Expand Down
21 changes: 10 additions & 11 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"example": {
"name": "react-native-quick-crypto-example",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"dependencies": {
"@craftzdog/react-native-buffer": "6.0.5",
"@noble/curves": "^1.7.0",
Expand All @@ -25,10 +25,10 @@
"events": "3.3.0",
"react": "18.3.1",
"react-native": "0.76.1",
"react-native-bouncy-checkbox": "4.0.1",
"react-native-nitro-modules": "0.21.0",
"react-native-bouncy-checkbox": "4.1.2",
"react-native-nitro-modules": "0.25.2",
"react-native-quick-base64": "2.1.2",
"react-native-quick-crypto": "1.0.0-beta.12",
"react-native-quick-crypto": "workspace:*",
"react-native-safe-area-context": "5.1.0",
"react-native-screens": "3.35.0",
"react-native-vector-icons": "^10.1.0",
Expand Down Expand Up @@ -69,13 +69,12 @@
},
"packages/react-native-quick-crypto": {
"name": "react-native-quick-crypto",
"version": "1.0.0-beta.12",
"version": "1.0.0-beta.13",
"dependencies": {
"@craftzdog/react-native-buffer": "6.0.5",
"events": "3.3.0",
"react-native-quick-base64": "2.1.2",
"readable-stream": "4.5.2",
"string_decoder": "1.3.0",
"util": "0.12.5",
},
"devDependencies": {
Expand All @@ -90,10 +89,10 @@
"eslint": "9.9.0",
"eslint-plugin-react-native": "5.0.0",
"jest": "29.7.0",
"nitro-codegen": "0.21.0",
"nitro-codegen": "0.25.2",
"prettier": "3.3.3",
"react-native-builder-bob": "0.35.2",
"react-native-nitro-modules": "0.21.0",
"react-native-nitro-modules": "0.25.2",
"release-it": "18.1.1",
"typescript": "5.1.6",
"typescript-eslint": "^8.1.0",
Expand Down Expand Up @@ -1683,7 +1682,7 @@

"new-github-release-url": ["[email protected]", "", { "dependencies": { "type-fest": "^2.5.1" } }, "sha512-NHDDGYudnvRutt/VhKFlX26IotXe1w0cmkDm6JGquh5bz/bDTw0LufSmH/GxTjEdpHEO+bVKFTwdrcGa/9XlKQ=="],

"nitro-codegen": ["nitro-codegen@0.21.0", "", { "dependencies": { "chalk": "^5.3.0", "react-native-nitro-modules": "^0.21.0", "ts-morph": "^25.0.0", "yargs": "^17.7.2", "zod": "^3.23.8" }, "bin": { "nitro-codegen": "lib/index.js" } }, "sha512-tp0hUKHN9a0IDCro9CKejQbcPDLKzYqF3U2lMPO/EVbcVlSqWLoO5dKdJ8+dzvIrbx32jIP/gK4fm4VXKIgbmg=="],
"nitro-codegen": ["nitro-codegen@0.25.2", "", { "dependencies": { "chalk": "^5.3.0", "react-native-nitro-modules": "^0.25.2", "ts-morph": "^25.0.0", "yargs": "^17.7.2", "zod": "^3.23.8" }, "bin": { "nitro-codegen": "lib/index.js" } }, "sha512-i0pGujdtmUaSmsawU6bmyFfW6MQbq+PZCWDT10QQg1EQbdPRvYAB5773R9GZtYoGNMGJ5qZVZUWnPBJRPOe61A=="],

"nocache": ["[email protected]", "", {}, "sha512-WDD0bdg9mbq6F4mRxEYcPWwfA1vxd0mrvKOyxI7Xj/atfRHVeutzuWByG//jfm4uPzp0y4Kj051EORCBSQMycw=="],

Expand Down Expand Up @@ -1871,11 +1870,11 @@

"react-native": ["[email protected]", "", { "dependencies": { "@jest/create-cache-key-function": "^29.6.3", "@react-native/assets-registry": "0.76.1", "@react-native/codegen": "0.76.1", "@react-native/community-cli-plugin": "0.76.1", "@react-native/gradle-plugin": "0.76.1", "@react-native/js-polyfills": "0.76.1", "@react-native/normalize-colors": "0.76.1", "@react-native/virtualized-lists": "0.76.1", "abort-controller": "^3.0.0", "anser": "^1.4.9", "ansi-regex": "^5.0.0", "babel-jest": "^29.7.0", "babel-plugin-syntax-hermes-parser": "^0.23.1", "base64-js": "^1.5.1", "chalk": "^4.0.0", "commander": "^12.0.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.6", "glob": "^7.1.1", "invariant": "^2.2.4", "jest-environment-node": "^29.6.3", "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", "metro-runtime": "^0.81.0", "metro-source-map": "^0.81.0", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", "pretty-format": "^29.7.0", "promise": "^8.3.0", "react-devtools-core": "^5.3.1", "react-refresh": "^0.14.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.24.0-canary-efb381bbf-20230505", "semver": "^7.1.3", "stacktrace-parser": "^0.1.10", "whatwg-fetch": "^3.0.0", "ws": "^6.2.3", "yargs": "^17.6.2" }, "peerDependencies": { "@types/react": "^18.2.6", "react": "^18.2.0" }, "optionalPeers": ["@types/react"], "bin": { "react-native": "cli.js" } }, "sha512-z4KnbrnnAvloRs9NGnah3u6/LK3IbtNMrvByxa3ifigbMlsMY4WPRYV9lvt/hH4Mzt8bfuI+utnOxFyJTTq3lg=="],

"react-native-bouncy-checkbox": ["react-native-bouncy-checkbox@4.0.1", "", { "dependencies": { "@freakycoder/react-native-bounceable": "^1.0.3" } }, "sha512-dlywsd3PWF47tkZKWFtnArtGM66Hkk1iUvlQhxSbnI56eo8BaQ4VnGFsrGxA3Jc/B7KDuzS9RCtaEflJJT5gYA=="],
"react-native-bouncy-checkbox": ["react-native-bouncy-checkbox@4.1.2", "", { "dependencies": { "@freakycoder/react-native-bounceable": "^1.0.3" } }, "sha512-hB7YwCGTNoMpTPOPiP+RWyQH35S6vxUbc7IGEW/Rqyp7GonEyhtqtthmxiphneRXnywMh8CZwND7OnvppJZscg=="],

"react-native-builder-bob": ["[email protected]", "", { "dependencies": { "@babel/core": "^7.25.2", "@babel/plugin-transform-strict-mode": "^7.24.7", "@babel/preset-env": "^7.25.2", "@babel/preset-flow": "^7.24.7", "@babel/preset-react": "^7.24.7", "@babel/preset-typescript": "^7.24.7", "babel-plugin-module-resolver": "^5.0.2", "browserslist": "^4.20.4", "cosmiconfig": "^9.0.0", "cross-spawn": "^7.0.3", "dedent": "^0.7.0", "del": "^6.1.1", "escape-string-regexp": "^4.0.0", "fs-extra": "^10.1.0", "glob": "^8.0.3", "is-git-dirty": "^2.0.1", "json5": "^2.2.1", "kleur": "^4.1.4", "metro-config": "^0.80.9", "prompts": "^2.4.2", "which": "^2.0.2", "yargs": "^17.5.1" }, "bin": { "bob": "bin/bob" } }, "sha512-/ehbjzO2GhDd8/noZiZVEGAVDkyZuWJ+zOrKcrNpqpoLOWhCO4y10FGIRkl5bfLvy7/2kXTwI6YnwiGIOODSGQ=="],

"react-native-nitro-modules": ["react-native-nitro-modules@0.21.0", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-7OQsFiApHnBmTmZj5Ge6A1FZb63v3BjI4p2Y0s6zff35Tq9LJemjB2tHdv5F/0tbjHBV4AYcZf5DMop3NdzOog=="],
"react-native-nitro-modules": ["react-native-nitro-modules@0.25.2", "", { "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-rL+X0LzB8BXvpdrUE/+oZ5v4qS/1nZIq0M8Uctbvqq2q53sVCHX4995ffT8+lGIJe/f0QcBvvrEeXtBPl86iwQ=="],

"react-native-quick-base64": ["[email protected]", "", { "dependencies": { "base64-js": "^1.5.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-xghaXpWdB0ji8OwYyo0fWezRroNxiNFCNFpGUIyE7+qc4gA/IGWnysIG5L0MbdoORv8FkTKUvfd6yCUN5R2VFA=="],

Expand Down
30 changes: 15 additions & 15 deletions docs/implementation-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
* ❌ Static method: `Certificate.exportChallenge(spkac[, encoding])`
* ❌ Static method: `Certificate.exportPublicKey(spkac[, encoding])`
* ❌ Static method: `Certificate.verifySpkac(spkac[, encoding])`
* Class: `Cipher`
* `cipher.final([outputEncoding])`
* `cipher.getAuthTag()`
* `cipher.setAAD(buffer[, options])`
* `cipher.setAutoPadding([autoPadding])`
* `cipher.update(data[, inputEncoding][, outputEncoding])`
* Class: `Decipher`
* `decipher.final([outputEncoding])`
* `decipher.setAAD(buffer[, options])`
* `decipher.setAuthTag(buffer[, encoding])`
* `decipher.setAutoPadding([autoPadding])`
* `decipher.update(data[, inputEncoding][, outputEncoding])`
* Class: `Cipher`
* `cipher.final([outputEncoding])`
* `cipher.getAuthTag()`
* `cipher.setAAD(buffer[, options])`
* `cipher.setAutoPadding([autoPadding])`
* `cipher.update(data[, inputEncoding][, outputEncoding])`
* Class: `Decipher`
* `decipher.final([outputEncoding])`
* `decipher.setAAD(buffer[, options])`
* `decipher.setAuthTag(buffer[, encoding])`
* `decipher.setAutoPadding([autoPadding])`
* `decipher.update(data[, inputEncoding][, outputEncoding])`
* ❌ Class: `DiffieHellman`
* ❌ `diffieHellman.computeSecret(otherPublicKey[, inputEncoding][, outputEncoding])`
* ❌ `diffieHellman.generateKeys([encoding])`
Expand Down Expand Up @@ -95,8 +95,8 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
* ❌ `crypto.fips`
* ❌ `crypto.checkPrime(candidate[, options], callback)`
* ❌ `crypto.checkPrimeSync(candidate[, options])`
* `crypto.createCipheriv(algorithm, key, iv[, options])`
* `crypto.createDecipheriv(algorithm, key, iv[, options])`
* `crypto.createCipheriv(algorithm, key, iv[, options])`
* `crypto.createDecipheriv(algorithm, key, iv[, options])`
* ❌ `crypto.createDiffieHellman(prime[, primeEncoding][, generator][, generatorEncoding])`
* ❌ `crypto.createDiffieHellman(primeLength[, generator])`
* ❌ `crypto.createDiffieHellmanGroup(name)`
Expand All @@ -117,7 +117,7 @@ This document attempts to describe the implementation status of Crypto APIs/Inte
* ❌ `crypto.generatePrime(size[, options[, callback]])`
* ❌ `crypto.generatePrimeSync(size[, options])`
* ❌ `crypto.getCipherInfo(nameOrNid[, options])`
* `crypto.getCiphers()`
* `crypto.getCiphers()`
* ❌ `crypto.getCurves()`
* ❌ `crypto.getDiffieHellman(groupName)`
* ❌ `crypto.getFips()`
Expand Down
Binary file removed docs/test_suite_results.png
Binary file not shown.
Binary file added docs/test_suite_results_android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/test_suite_results_ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed example/bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PODS:
- hermes-engine (0.76.1):
- hermes-engine/Pre-built (= 0.76.1)
- hermes-engine/Pre-built (0.76.1)
- NitroModules (0.21.0):
- NitroModules (0.25.2):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1940,9 +1940,9 @@ SPEC CHECKSUMS:
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
hermes-engine: 46f1ffbf0297f4298862068dd4c274d4ac17a1fd
NitroModules: 3a58d9bc70815a0d5de4476ed6a36eff05a6a0ae
NitroModules: 3a9c88afc1ca3dba01759ed410e8c2902a5d3dbb
OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4
QuickCrypto: 8b714710db7acd4299e22db704ba85ea6e38c072
QuickCrypto: d56c13c2a864ef4400d7aca6631d57989d05a0a3
RCT-Folly: 84578c8756030547307e4572ab1947de1685c599
RCTDeprecation: fde92935b3caa6cb65cbff9fbb7d3a9867ffb259
RCTRequired: 75c6cee42d21c1530a6f204ba32ff57335d19007
Expand Down
6 changes: 3 additions & 3 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"events": "3.3.0",
"react": "18.3.1",
"react-native": "0.76.1",
"react-native-bouncy-checkbox": "4.0.1",
"react-native-nitro-modules": "0.21.0",
"react-native-bouncy-checkbox": "4.1.2",
"react-native-nitro-modules": "0.25.2",
"react-native-quick-base64": "2.1.2",
"react-native-quick-crypto": "1.0.0-beta.13",
"react-native-quick-crypto": "workspace:*",
"react-native-safe-area-context": "5.1.0",
"react-native-screens": "3.35.0",
"react-native-vector-icons": "^10.1.0",
Expand Down
22 changes: 3 additions & 19 deletions example/src/hooks/useTestsList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@ import { useState, useCallback } from 'react';
import type { TestSuites } from '../types/tests';
import { TestsContext } from '../tests/util';

import '../tests/hmac/hmac_tests';
import '../tests/hash/hash_tests';
import '../tests/cipher/cipher_tests';
import '../tests/ed25519/ed25519_tests';
import '../tests/hash/hash_tests';
import '../tests/hmac/hmac_tests';
import '../tests/pbkdf2/pbkdf2_tests';
import '../tests/random/random_tests';
// import '../tests/HmacTests/HmacTests';
// import '../tests/HashTests/HashTests';
// import '../tests/CipherTests/CipherTestFirst';
// import '../tests/CipherTests/CipherTestSecond';
// import '../tests/CipherTests/PublicCipherTests';
// import '../tests/CipherTests/test398';
// import '../tests/CipherTests/generateKey';
// import '../tests/CipherTests/GenerateKeyPairTests';
// import '../tests/ConstantsTests/ConstantsTests';
// import '../tests/SignTests/SignTests';
// import '../tests/SmokeTests/bundlerTests';
// import '../tests/webcryptoTests/deriveBits';
// import '../tests/webcryptoTests/digest';
// import '../tests/webcryptoTests/generateKey';
// import '../tests/webcryptoTests/encrypt_decrypt';
// import '../tests/webcryptoTests/import_export';
// import '../tests/webcryptoTests/sign_verify';

export const useTestsList = (): [
TestSuites,
Expand Down
93 changes: 0 additions & 93 deletions example/src/hooks/useTestsRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,96 +84,3 @@ const run = (
stats.duration = stats.end.valueOf() - stats.start.valueOf();
return stats;
};

// const run = (
// addTestResult: (testResult: TestResult) => void,
// tests: Suites = {},
// ) => {
// const {
// EVENT_RUN_BEGIN,
// EVENT_RUN_END,
// EVENT_TEST_FAIL,
// EVENT_TEST_PASS,
// EVENT_TEST_PENDING,
// EVENT_TEST_END,
// EVENT_SUITE_BEGIN,
// EVENT_SUITE_END,
// } = Mocha.Runner.constants;

// const stats: Stats = { ...defaultStats };

// const runner = new Mocha.Runner(rootSuite);
// runner.stats = stats;

// // enable/disable tests based on checkbox value
// runner.suite.suites.map(s => {
// const suiteName = s.title;
// if (!tests[suiteName]?.value) {
// // console.log(`skipping '${suiteName}' suite`);
// s.tests.map(t => {
// t.skip();
// });
// } else {
// // console.log(`will run '${suiteName}' suite`);
// s.tests.map(t => {
// // @ts-expect-error - not sure why this is erroring
// t.reset();
// });
// }
// });

// let indents = -1;
// const indent = () => Array(indents).join(' ');
// runner
// .once(EVENT_RUN_BEGIN, () => {
// stats.start = new Date();
// })
// .on(EVENT_SUITE_BEGIN, (suite: MochaTypes.Suite) => {
// if (!suite.root) stats.suites++;
// indents++;
// })
// .on(EVENT_SUITE_END, () => {
// indents--;
// })
// .on(EVENT_TEST_PASS, (test: MochaTypes.Runnable) => {
// const name = test.parent?.title || '';
// stats.passes++;
// addTestResult({
// indentation: indents,
// description: test.title,
// suiteName: name,
// type: 'correct',
// });
// console.log(`${indent()}pass: ${test.title}`);
// })
// .on(EVENT_TEST_FAIL, (test: MochaTypes.Runnable, err: Error) => {
// const name = test.parent?.title || '';
// stats.failures++;
// addTestResult({
// indentation: indents,
// description: test.title,
// suiteName: name,
// type: 'incorrect',
// errorMsg: err.message,
// });
// console.log(`${indent()}fail: ${test.title} - error: ${err.message}`);
// })
// .on(EVENT_TEST_PENDING, function () {
// stats.pending++;
// })
// .on(EVENT_TEST_END, function () {
// stats.tests++;
// })
// .once(EVENT_RUN_END, () => {
// stats.end = new Date();
// stats.duration = stats.end.valueOf() - stats.start.valueOf();
// console.log(JSON.stringify(runner.stats, null, 2));
// });

// runner.run();

// return () => {
// console.log('aborting');
// runner.abort();
// };
// };
Loading
Loading