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:
@@ -9,22 +9,32 @@
|
|||||||
* - Required security schemes are referenced
|
* - Required security schemes are referenced
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const { describe, it, expect } = require('vitest');
|
import { describe, it, expect, beforeAll } from 'vitest';
|
||||||
const request = require('supertest');
|
import request from 'supertest';
|
||||||
const { createApp } = require('../../server/app');
|
import { createApp } from '../../server/app.js';
|
||||||
const YAML = require('yamljs');
|
import fs from 'fs';
|
||||||
const fs = require('fs');
|
import path from 'path';
|
||||||
const path = require('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', () => {
|
describe('Swagger Coverage', () => {
|
||||||
let app;
|
let app;
|
||||||
let openapiSpec;
|
let openapiSpec;
|
||||||
let swaggerSpec;
|
let swaggerSpec;
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(async () => {
|
||||||
// Load the base OpenAPI spec from YAML
|
// Load the base OpenAPI spec from YAML
|
||||||
const yamlPath = path.join(__dirname, '../../server/openapi.yaml');
|
const yamlPath = path.join(__dirname, '../../server/openapi.yaml');
|
||||||
const yamlContent = fs.readFileSync(yamlPath, 'utf8');
|
const yamlContent = fs.readFileSync(yamlPath, 'utf8');
|
||||||
|
const YAML = await loadYAML();
|
||||||
openapiSpec = YAML.parse(yamlContent);
|
openapiSpec = YAML.parse(yamlContent);
|
||||||
|
|
||||||
// Create app and get the merged swagger spec
|
// Create app and get the merged swagger spec
|
||||||
|
|||||||
Reference in New Issue
Block a user