From c5bd49716fab36cb16f5faba0f161392e07e29dc Mon Sep 17 00:00:00 2001 From: solufa Date: Fri, 16 Aug 2024 11:59:20 +0900 Subject: [PATCH] chore: update test file --- src/index.ts | 2 +- tests/index.test.ts | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5968eaf..927751c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import type { PartialConfig } from './getConfig'; import { getConfig } from './getConfig'; export default (configs?: PartialConfig) => - getConfig(configs).map((config) => { + getConfig(configs).forEach((config) => { const tree = getDirentTree(config.input); const createFilePaths = (tree: DirentTree): string[] => { diff --git a/tests/index.test.ts b/tests/index.test.ts index 6ed07af..2966698 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import fs, { copyFileSync } from 'fs'; import { afterAll, beforeAll, describe, expect, test } from 'vitest'; import build from '../src'; import type { ConfigFile } from '../src/getConfig'; @@ -7,20 +7,21 @@ describe('cli test', () => { beforeAll(() => fs.mkdirSync('_samples')); afterAll(() => fs.promises.rmdir('_samples', { recursive: true })); - test('main', () => { - const configs: ConfigFile[] = require('../aspida.config.js'); + const configs: ConfigFile[] = require('../aspida.config.js'); - return Promise.all( - configs.map(async (config) => { - const originalFile = config.openapi?.outputFile ?? `${config.input}.json`; - const outputFile = `_${originalFile}`; + test.each(configs)('$input', (config) => { + const originalFile = config.openapi?.outputFile ?? `${config.input}.json`; + const outputFile = `_${originalFile}`; - await build({ ...config, openapi: { outputFile } })[0]; + if (config.input.endsWith('openapi')) { + // override doc info + copyFileSync(`${config.input}.json`, outputFile); + } - expect(fs.readFileSync(outputFile, 'utf8')).toBe( - fs.readFileSync(originalFile, 'utf8').replace(/\r/g, ''), - ); - }), + build({ ...config, openapi: { outputFile } }); + + expect(fs.readFileSync(outputFile, 'utf8')).toBe( + fs.readFileSync(originalFile, 'utf8').replace(/\r/g, ''), ); }); });