fix(swagger): convert coverage test to ES modules

- Convert swagger-coverage.test.js to use ES module imports
- Use dynamic import for yamljs (CommonJS library)
- Fix Vitest compatibility issue
This commit is contained in:
2026-05-21 12:40:54 +01:00
parent e254873bee
commit db9b3e7a30
+17 -7
View File
@@ -9,22 +9,32 @@
* - Required security schemes are referenced
*/
const { describe, it, expect } = require('vitest');
const request = require('supertest');
const { createApp } = require('../../server/app');
const YAML = require('yamljs');
const fs = require('fs');
const path = require('path');
import { describe, it, expect, beforeAll } from 'vitest';
import request from 'supertest';
import { createApp } from '../../server/app.js';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load YAML using dynamic import for yamljs which is CommonJS
async function loadYAML() {
const YAML = await import('yamljs');
return YAML;
}
describe('Swagger Coverage', () => {
let app;
let openapiSpec;
let swaggerSpec;
beforeAll(() => {
beforeAll(async () => {
// Load the base OpenAPI spec from YAML
const yamlPath = path.join(__dirname, '../../server/openapi.yaml');
const yamlContent = fs.readFileSync(yamlPath, 'utf8');
const YAML = await loadYAML();
openapiSpec = YAML.parse(yamlContent);
// Create app and get the merged swagger spec