Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: another grab bag of changes from #1159 #1162

Merged
merged 9 commits into from
Jan 31, 2025

Conversation

kanadgupta
Copy link
Member

🧰 Changes

chunks out a lot of PR feedback and random changes from #1159:

  • renames all "front matter" to "frontmatter"
  • better nock and fs setup/teardown
  • cherry-picking over c871520
  • various cleanups
  • bumps deps:

before:

@readme/better-ajv-errors    2.0.0    2.1.2    2.1.2  node_modules/@readme/better-ajv-errors  rdme
eslint                      8.57.1   8.57.1   9.19.0  node_modules/eslint                     rdme
oclif                      4.17.20  4.17.21  4.17.21  node_modules/oclif                      rdme
semver                       7.6.3    7.7.0    7.7.0  node_modules/semver                     rdme
undici                      5.28.5   5.28.5    7.3.0  node_modules/undici                     rdme

after:

Package  Current  Wanted  Latest  Location             Depended by
eslint    8.57.1  8.57.1  9.19.0  node_modules/eslint  rdme
undici    5.28.5  5.28.5   7.3.0  node_modules/undici  rdme

🧬 QA & Testing

do tests still pass?

@kanadgupta kanadgupta added refactor Issues about tackling technical debt documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file labels Jan 31, 2025
@kanadgupta kanadgupta changed the title Kanad 2025 01 31/pr feedback chore: another grab bag of changes from #1159 Jan 31, 2025
@kanadgupta kanadgupta marked this pull request as ready for review January 31, 2025 23:31
@kanadgupta kanadgupta requested a review from erunion January 31, 2025 23:31
Comment on lines 25 to 27
fs.writeFileSync = vi.fn((fileName, data) => {
reducedSpec = JSON.parse(data as string);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to get this working with a test spy if you're interested.

diff --git a/__tests__/commands/openapi/convert.test.ts b/__tests__/commands/openapi/convert.test.ts
index 6fac324..2ba5928 100644
--- a/__tests__/commands/openapi/convert.test.ts
+++ b/__tests__/commands/openapi/convert.test.ts
@@ -3,7 +3,7 @@ import type { OASDocument } from 'oas/types';
 import fs from 'node:fs';
 
 import prompts from 'prompts';
-import { describe, it, expect, vi, beforeAll, beforeEach, afterEach } from 'vitest';
+import { describe, it, expect, vi, beforeAll, beforeEach, afterEach, type MockInstance } from 'vitest';
 
 import Command from '../../../src/commands/openapi/convert.js';
 import { runCommandAndReturnResult } from '../../helpers/oclif.js';
@@ -11,10 +11,10 @@ import { runCommandAndReturnResult } from '../../helpers/oclif.js';
 const successfulConversion = () => 'Your API definition has been converted and bundled and saved to output.json!';
 
 describe('rdme openapi convert', () => {
-  const fsWriteFileSync = fs.writeFileSync;
   let reducedSpec: OASDocument;
   let run: (args?: string[]) => Promise<string>;
   let testWorkingDir: string;
+  let fsWriteFileSyncSpy: MockInstance<typeof fs.writeFileSync>;
 
   beforeAll(() => {
     run = runCommandAndReturnResult(Command);
@@ -22,13 +22,13 @@ describe('rdme openapi convert', () => {
 
   beforeEach(() => {
     testWorkingDir = process.cwd();
-    fs.writeFileSync = vi.fn((fileName, data) => {
+
+    fsWriteFileSyncSpy = vi.spyOn(fs, 'writeFileSync').mockImplementationOnce((filename, data) => {
       reducedSpec = JSON.parse(data as string);
     });
   });
 
   afterEach(() => {
-    fs.writeFileSync = fsWriteFileSync;
     process.chdir(testWorkingDir);
     vi.clearAllMocks();
   });
@@ -44,7 +44,7 @@ describe('rdme openapi convert', () => {
 
       await expect(run([spec])).resolves.toBe(successfulConversion());
 
-      expect(fs.writeFileSync).toHaveBeenCalledWith('output.json', expect.any(String));
+      expect(fsWriteFileSyncSpy).toHaveBeenCalledWith('output.json', expect.any(String));
       expect(reducedSpec.tags).toHaveLength(1);
       expect(Object.keys(reducedSpec.paths)).toStrictEqual(['/pet/{petId}']);
       expect(Object.keys(reducedSpec.paths['/pet/{petId}'])).toStrictEqual(['get', 'post', 'delete']);
@@ -64,7 +64,7 @@ describe('rdme openapi convert', () => {
       ]),
     ).resolves.toBe(successfulConversion());
 
-    expect(fs.writeFileSync).toHaveBeenCalledWith('output.json', expect.any(String));
+    expect(fsWriteFileSyncSpy).toHaveBeenCalledWith('output.json', expect.any(String));
     expect(Object.keys(reducedSpec.paths)).toStrictEqual(['/pet/{petId}']);
     expect(Object.keys(reducedSpec.paths['/pet/{petId}'])).toStrictEqual(['get', 'post', 'delete']);
   });
@@ -79,7 +79,7 @@ describe('rdme openapi convert', () => {
 
       await expect(run([spec])).resolves.toBe(successfulConversion());
 
-      expect(fs.writeFileSync).toHaveBeenCalledWith('output.json', expect.any(String));
+      expect(fsWriteFileSyncSpy).toHaveBeenCalledWith('output.json', expect.any(String));
       expect(reducedSpec.tags).toHaveLength(3);
       expect(Object.keys(reducedSpec.paths)).toStrictEqual([
         '/pet',

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah tysm

@kanadgupta kanadgupta merged commit a49d6c7 into next Jan 31, 2025
7 checks passed
@kanadgupta kanadgupta deleted the kanad-2025-01-31/PR-feedback branch January 31, 2025 23:52
@kanadgupta kanadgupta mentioned this pull request Feb 1, 2025
9 tasks
@kanadgupta
Copy link
Member Author

🎉 This PR is included in version 10.1.2-next.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation refactor Issues about tackling technical debt released on @next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants