-
Notifications
You must be signed in to change notification settings - Fork 44
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
Conversation
fs.writeFileSync = vi.fn((fileName, data) => { | ||
reducedSpec = JSON.parse(data as string); | ||
}); |
There was a problem hiding this comment.
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',
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah tysm
Co-Authored-By: Jon Ursenbach <[email protected]>
🎉 This PR is included in version 10.1.2-next.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
🧰 Changes
chunks out a lot of PR feedback and random changes from #1159:
nock
andfs
setup/teardownbefore:
after:
🧬 QA & Testing
do tests still pass?