cyberchef/tests/lib/VitestAdapter.mjs
consigcody94 1ac3190dae Modernize CyberChef build system, dependencies, UI, and testing
Build System:
- Replace Grunt with npm scripts and Node.js helper scripts
- Remove worker-loader, use native Webpack 5 worker syntax
- Add Rspack config as faster alternative bundler (5-23x faster)
- Replace platform-specific sed postinstall hacks with cross-platform Node.js script
- Update browser targets from Chrome 50/Firefox 38 to Chrome 80/Firefox 78/Safari 14
- Fix import assertions (assert -> with) for Node 24 compatibility

Dependencies:
- Replace deprecated crypto-js with native RC4 implementation and @noble/hashes EVP KDF
- Replace blakejs with @noble/hashes/blake2b and blake2s
- Add @noble/hashes for MD5, SHA1/2/3, RIPEMD160, HMAC, HKDF (crypto-api fallback for legacy algos)
- Replace lodash with native CaseConvert.mjs utility
- Replace moment.js in web layer with date-fns
- Add date-fns and date-fns-tz dependencies
- Remove jquery, snackbarjs, arrive, bootstrap-colorpicker, bootstrap-material-design, popper.js v1, lodash, blakejs, crypto-js

UI Modernization:
- Upgrade Bootstrap 4.6.2 to Bootstrap 5.3 (87 data attribute renames)
- Remove bootstrap-material-design (unmaintained)
- Remove jQuery dependency entirely (38 calls replaced with native DOM + BS5 JS API)
- Add custom Snackbar.mjs notification utility (replaces snackbarjs)
- Replace bootstrap-colorpicker with native HTML color input

Testing:
- Add Vitest config and adapter for running existing TestRegister tests
- Add Playwright config and E2E test replacing Nightwatch
- Update CI workflows to use npm scripts and Playwright
2026-03-23 13:59:24 -04:00

77 lines
2.6 KiB
JavaScript

/**
* Vitest adapter for CyberChef's TestRegister format.
* Allows existing test files using TestRegister.addTests() to work with Vitest
* without modifying every test file.
*
* Usage in test files:
* import TestRegister from "../../lib/TestRegister.mjs";
* TestRegister.addTests([{ name, input, expectedOutput, recipeConfig }]);
*
* Then in a .test.mjs file:
* import { runRegisteredTests } from "../../lib/VitestAdapter.mjs";
* import "./tests/Base64.mjs"; // registers tests
* runRegisteredTests();
*
* @author CyberChef Modernization
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import { describe, it, expect } from "vitest";
import Chef from "../../src/core/Chef.mjs";
import TestRegister from "./TestRegister.mjs";
/**
* Run all tests registered via TestRegister.addTests() as Vitest tests.
*
* @param {string} [suiteName="CyberChef Operations"] - Name for the test suite
*/
export function runRegisteredTests(suiteName = "CyberChef Operations") {
describe(suiteName, () => {
const tests = TestRegister.tests;
for (const test of tests) {
it(test.name, async () => {
const chef = new Chef();
const result = await chef.bake(
test.input,
test.recipeConfig,
{ returnType: "string" }
);
if (test.expectedError) {
expect(result.error).toBeTruthy();
if (test.expectedOutput) {
expect(result.error.displayStr).toBe(test.expectedOutput);
}
} else if (result.error) {
throw new Error(`Unexpected error: ${result.error.displayStr}`);
} else if ("expectedMatch" in test) {
expect(result.result).toMatch(test.expectedMatch);
} else if ("unexpectedMatch" in test) {
expect(result.result).not.toMatch(test.unexpectedMatch);
} else {
expect(result.result).toBe(test.expectedOutput);
}
});
}
});
}
/**
* Run all API tests registered via TestRegister.addApiTests() as Vitest tests.
*
* @param {string} [suiteName="CyberChef Node API"] - Name for the test suite
*/
export function runRegisteredApiTests(suiteName = "CyberChef Node API") {
describe(suiteName, () => {
const tests = TestRegister.apiTests;
for (const test of tests) {
it(test.name, async () => {
await test.run();
});
}
});
}