
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Simple testing framework inspired by Jest.
This is not a fully functional testing framework, it's just a simple example of how you can create your own testing framework. Why would you do that? Because it's fun, duh!
Well, it's very similar to Jest, you have the same describe, it and expect functions, just with (much) less features:
import { describe, it, expect } from 'sweetest';
describe('My test suite', () => {
it('should pass', () => {
expect(1 + 1).toBe(2);
});
it('should fail', () => {
expect(1 + 1).toBe(3);
});
describe('Nested suite', () => {
it('should pass', () => {
expect(null).toBeNull();
});
});
});
The output will be something like this:
❌ My test suite
✅ should pass
❌ should fail
✅ Nested suite
✅ should pass
Currently, there is a limited list of built in matchers:
toBe(value): Strict equality with valuetoBeNull(): Strict equality with nullBut, you can still create your own matchers, just like in Jest.
A "matcher" is a function that receives the value to be tested along with the expected value, and throws an AssertionError if the value is not as expected:
import { addMatcher, AssertionError, type Matcher } from 'sweetest';
const toBeGreaterThan: Matcher = (value: number, expected: number) => {
if (value <= expected) {
throw new AssertionError(`Expected ${value} to be greater than ${expected}`);
}
};
addMatcher('toBeGreaterThan', toBeGreaterThan);
If you're using TypeScript, you'll also need to extend the Matchers interface using "Module Augmentation":
declare module 'sweetest' {
interface Matchers {
toBeGreaterThan(value: number, expected: number): void;
}
}
Same as in Jest, you can use hooks to run code before and after each test, or before and after each suite:
import { describe, it, beforeEach, afterEach, beforeAll, afterAll } from 'sweetest';
describe('My test suite', () => {
beforeAll(() => {
console.log('Before all tests');
});
beforeEach(() => {
console.log('Before each test');
});
afterEach(() => {
console.log('After each test');
});
afterAll(() => {
console.log('After all tests');
});
it('should pass', () => {
expect(1 + 1).toBe(2);
});
});
You can also create mock functions using the sw.fn function, and assert if they were called using the toHaveBeenCalled, toHaveBeenCalledTimes
and toHaveBeenCalledWith matchers:
import { describe, it, expect, sw } from 'sweetest';
describe('My test suite', () => {
it('should call the mock function', () => {
const mock = sw.fn((count: number) => {
return count * 2;
});
mock(1);
mock(2);
mock(3);
expect(mock).toHaveBeenCalled();
expect(mock).toHaveBeenCalledTimes(3);
expect(mock).toHaveBeenCalledWith(1);
});
});
FAQs
Simple testing framework inspired by Jest
The npm package sweetest receives a total of 3 weekly downloads. As such, sweetest popularity was classified as not popular.
We found that sweetest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.