// tools/generate-tests/generators/concurrency-test-generator/js-templates.ts — SPEC-034
// TypeScript/JavaScript concurrency test scaffolds
export function generateJsConcurrencyTest(title, framework, model) {
    const isVitest = framework === 'vitest';
    const runner = isVitest ? 'vitest' : 'jest';
    const lines = [
        `// Concurrency tests for: ${title}`,
        `// Concurrency model: ${model}`,
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        `import { describe, it, expect } from '${runner}'`,
        '',
        `describe('${title} — Concurrency Tests', () => {`,
        '',
        `  it('N concurrent increments produce correct final state (no lost updates)', async () => {`,
        `    const N = 100`,
        `    let sharedValue = 0`,
        '',
        `    await Promise.all(Array.from({ length: N }, async () => {`,
        `      sharedValue += 1`,
        `    }))`,
        '',
        `    expect(sharedValue).toBe(N)`,
        `  })`,
        '',
        `  it('concurrent reads observe complete states only', async () => {`,
        `    const states = ['old', 'new'] as const`,
        `    const readResult = await Promise.resolve(states[1])`,
        `    expect(states).toContain(readResult)`,
        `  })`,
    ];
    if (model === 'async-await') {
        lines.push('', `  it('event loop is not blocked by synchronous operations', async () => {`, `    let lightweightCompleted = false`, `    const lightweightPromise = Promise.resolve().then(() => { lightweightCompleted = true })`, '', `    await Promise.resolve()`, '', `    await lightweightPromise`, `    expect(lightweightCompleted).toBe(true)`, `  })`);
    }
    lines.push(`})`, '');
    return lines.join('\n');
}
export function generateJsPactTest(title, framework) {
    const isVitest = framework === 'vitest';
    const runner = isVitest ? 'vitest' : 'jest';
    return [
        `// Pact consumer contract tests for: ${title}`,
        '// Install: npm install --save-dev @pact-foundation/pact',
        '// Generated by Planu SDD MCP Server (SPEC-034)',
        '',
        `import { describe, it, expect, beforeAll, afterAll } from '${runner}'`,
        `import { PactV3, MatchersV3 } from '@pact-foundation/pact'`,
        `import path from 'node:path'`,
        '',
        `const consumerName = process.env.PACT_CONSUMER_NAME`,
        `const providerName = process.env.PACT_PROVIDER_NAME`,
        `const contractPath = process.env.PACT_CONTRACT_PATH`,
        '',
        `const provider = new PactV3({`,
        `  consumer: consumerName ?? '${title.replace(/\s+/g, '-').toLowerCase()}-consumer',`,
        `  provider: providerName ?? '${title.replace(/\s+/g, '-').toLowerCase()}-provider',`,
        `  dir: path.resolve(process.cwd(), 'pacts'),`,
        `  logLevel: 'warn',`,
        `})`,
        '',
        `describe('${title} — Pact Consumer Contract', () => {`,
        '',
        `  it.skip('loads explicit Pact interactions from contractPath', async () => {`,
        `    expect(MatchersV3).toBeDefined()`,
        `    expect(provider).toBeDefined()`,
        `    expect(contractPath).toBeTruthy()`,
        `  })`,
        `})`,
        '',
    ].join('\n');
}
//# sourceMappingURL=js-templates.js.map