
Research
/Security News
OpenAPI React Query Codegen Compromised in Mini Shai-Hulud npm Supply Chain Attack
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.
@specsafe/test-gen
Advanced tools
Test generation library for the SpecSafe spec-driven development framework. Parses specifications and generates TypeScript test files.
npm install @specsafe/test-gen
Parses specification files and extracts requirements.
import { ScenarioParser } from '@specsafe/test-gen';
const parser = new ScenarioParser();
parseRequirements(specContent: string): Requirement[]Parse requirements from spec content.
const specContent = `
## Requirements
### REQ-001: User Login
**Given** a registered user with email "user@example.com"
**When** they enter the correct password
**Then** they should be redirected to the dashboard
### REQ-002: Invalid Password
**Given** a registered user
**When** they enter an incorrect password
**Then** an error message should be displayed
`;
const requirements = parser.parseRequirements(specContent);
console.log(requirements);
// [
// {
// id: 'REQ-001',
// title: 'User Login',
// given: 'a registered user with email "user@example.com"',
// when: 'they enter the correct password',
// then: 'they should be redirected to the dashboard'
// },
// ...
// ]
Generates TypeScript test files from requirements.
import { TypeScriptTestGenerator } from '@specsafe/test-gen';
const generator = new TypeScriptTestGenerator({
framework: 'vitest', // or 'jest'
specId: 'user-authentication'
});
generate(requirements: Requirement[]): stringGenerate test file content.
const requirements = [
{
id: 'REQ-001',
title: 'User Login',
given: 'a registered user',
when: 'they enter valid credentials',
then: 'they should be logged in'
}
];
const testCode = generator.generate(requirements);
console.log(testCode);
// Output:
// import { describe, it, expect } from 'vitest';
//
// describe('User Authentication', () => {
// it('REQ-001: User Login', () => {
// // Given: a registered user
// // When: they enter valid credentials
// // Then: they should be logged in
// expect(true).toBe(true);
// });
// });
const generator = new TypeScriptTestGenerator({
framework: 'vitest',
specId: 'my-feature'
});
Generates tests using Vitest's describe, it, and expect:
import { describe, it, expect } from 'vitest';
describe('My Feature', () => {
it('REQ-001: Requirement Title', () => {
// Test implementation
});
});
const generator = new TypeScriptTestGenerator({
framework: 'jest',
specId: 'my-feature'
});
Generates tests using Jest's globals:
describe('My Feature', () => {
it('REQ-001: Requirement Title', () => {
// Test implementation
});
});
import { ScenarioParser, TypeScriptTestGenerator } from '@specsafe/test-gen';
import { readFileSync, writeFileSync } from 'fs';
// Read spec file
const specContent = readFileSync('./specs/active/login.spec.md', 'utf-8');
// Parse requirements
const parser = new ScenarioParser();
const requirements = parser.parseRequirements(specContent);
// Generate tests
const generator = new TypeScriptTestGenerator({
framework: 'vitest',
specId: 'login'
});
const testCode = generator.generate(requirements);
// Write to file
writeFileSync('./src/specs/login.spec.ts', testCode);
The generated tests include comments based on the Gherkin-style requirements:
// Given: a registered user with valid credentials
// When: they submit the login form
// Then: they should be authenticated
You fill in the actual test implementation:
it('REQ-001: User Login', () => {
// Given: a registered user with valid credentials
const user = createUser({ email: 'test@example.com', password: 'secret' });
// When: they submit the login form
const result = login(user.email, user.password);
// Then: they should be authenticated
expect(result.authenticated).toBe(true);
});
import { ScenarioParser, TypeScriptTestGenerator } from '@specsafe/test-gen';
import { readdirSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
const parser = new ScenarioParser();
const specsDir = './specs/active';
const outputDir = './src/specs';
const specFiles = readdirSync(specsDir).filter(f => f.endsWith('.spec.md'));
for (const file of specFiles) {
const specId = file.replace('.spec.md', '');
const content = readFileSync(join(specsDir, file), 'utf-8');
const requirements = parser.parseRequirements(content);
const generator = new TypeScriptTestGenerator({
framework: 'vitest',
specId
});
const testCode = generator.generate(requirements);
writeFileSync(join(outputDir, `${specId}.spec.ts`), testCode);
console.log(`Generated tests for ${specId}`);
}
Requirements should follow this format in your spec files:
## Requirements
### REQ-XXX: Requirement Title
**Given** [context]
**When** [action]
**Then** [expected result]
Where:
REQ-XXX is a unique requirement ID (e.g., REQ-001, REQ-002)MIT © Agentic Engineering
FAQs
Test generators for SpecSafe
The npm package @specsafe/test-gen receives a total of 4 weekly downloads. As such, @specsafe/test-gen popularity was classified as not popular.
We found that @specsafe/test-gen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Research
/Security News
Ten malicious OpenAPI React Query Codegen versions were published to npm in the Mini Shai-Hulud attack, all with valid provenance.

Security News
Socket joins more than 100 technology, cybersecurity, and financial organizations calling for a global surge in cyber defense.

Product
Enterprise security teams can now detect malware, credential theft, suspicious network activity, and risky updates across Microsoft Edge extensions.