
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
@ra-bootcamp/mocha
Advanced tools
A mocha.js and chai wrapper that delivers a promise-based API to get test results instead of only printing.
A mocha.js and chai wrapper that delivers a promise-based API to get test results instead of only printing. Created for Responde Aí's Bootcamp students use on their own Code LMS platform project. It also prevents infinite loops.
This library is UNSAFE as it uses eval
to load the code and the test code (check out Usage to understand why).
Install the package:
npm install @ra-bootcamp/mocha
# or if using yarn
yarn add @ra-bootcamp/mocha
This module exports a single function:
import { runTests } from '@ra-bootcamp/mocha';
async function main() {
const code = `
/* This function will pass the first test but not the second */
function testedFunction (param) {
return 10;
}
`;
const testCode = `
describe('testedFunction', () => {
it('should return the passed parameter (10)', () => {
const param = 10;
const result = testedFunction(param);
expect(result).to.equal(param);
});
it('should return the passed parameter (20)', () => {
const param = 20;
const result = testedFunction(param);
expect(result).to.equal(param);
});
});
`;
const callbackConsole = (value) => {
// write our function to save outputs
};
const result = await runTests(code, testCode, callbackConsole);
/*
* Will return an object with the following format:
* {
* failed: 1
* passed: 1,
* suites: [
* [
* {
* type: 'test',
* title: 'should return the passed parameter (10)',
* state: 'passed',
* },
* {
* type: 'test',
* title: 'should return the passed parameter (20)',
* state: 'failed',
* error: {
* actual: 10,
* expected: 20,
* message: 'expected 10 to equal 20',
* operator: 'strictEqual',
* stack: <Error Stack Trace>
* }
* }
* ]
* ]
* }
*
* May reject if code takes more than 1.5s to run.
*/
}
FAQs
A mocha.js and chai wrapper that delivers a promise-based API to get test results instead of only printing.
The npm package @ra-bootcamp/mocha receives a total of 0 weekly downloads. As such, @ra-bootcamp/mocha popularity was classified as not popular.
We found that @ra-bootcamp/mocha demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.