Skip to content

Commit f644954

Browse files
respect-core
1 parent 09c4ea2 commit f644954

File tree

6 files changed

+99
-53
lines changed

6 files changed

+99
-53
lines changed

migrated-suites.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,7 @@
7070
"packages/core/src/decorators/__tests__/remove-x-internal.test.ts",
7171
"packages/core/src/config/__tests__/config.test.ts",
7272

73-
"packages/respect-core/src/modules/__tests__/flow-runner/runner/resolve-workflow-context.test.ts"
73+
"packages/respect-core/src/modules/__tests__/flow-runner/runner/resolve-workflow-context.test.ts",
74+
"packages/respect-core/src/modules/__tests__/flow-runner/runner/run-test-file.test.ts",
75+
"packages/respect-core/src/modules/__tests__/flow-runner/call-api-and-analyze-results.test.ts"
7476
]

packages/respect-core/src/modules/__tests__/flow-runner/call-api-and-analyze-results.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { fetch } from 'undici';
1+
import { Mock } from 'vitest';
22

3+
import { fetch } from 'undici';
34
import type { TestContext } from '../../../types';
45

56
import { callAPIAndAnalyzeResults, DEFAULT_SEVERITY_CONFIGURATION } from '../../flow-runner';
67
import { ApiFetcher } from '../../../utils/api-fetcher';
78

89
// @ts-ignore
9-
jest.mock('undici');
10+
vi.mock('undici');
1011

1112
describe('callAPIAndAnalyzeResults', () => {
1213
const apiClient = new ApiFetcher({
@@ -349,13 +350,13 @@ describe('callAPIAndAnalyzeResults', () => {
349350

350351
const mockResponse = {
351352
status: 200,
352-
json: jest.fn().mockResolvedValue({ id: 1 }),
353-
text: jest.fn().mockResolvedValue(JSON.stringify({ id: 1 })),
353+
json: vi.fn().mockResolvedValue({ id: 1 }),
354+
text: vi.fn().mockResolvedValue(JSON.stringify({ id: 1 })),
354355
headers: new Headers(),
355356
};
356357

357358
// @ts-ignore
358-
(fetch as jest.Mock).mockResolvedValue(mockResponse);
359+
(fetch as Mock).mockResolvedValue(mockResponse);
359360

360361
const result = await callAPIAndAnalyzeResults({
361362
ctx,
@@ -377,6 +378,6 @@ describe('callAPIAndAnalyzeResults', () => {
377378
});
378379

379380
// @ts-ignore
380-
(fetch as jest.Mock).mockRestore();
381+
(fetch as Mock).mockRestore();
381382
});
382383
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
// Jest Snapshot v1, https://goo.gl/fbAQLP
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`runTestFile should throw Found errors in Arazzo description error when contains lint errors 1`] = `[Error: [31mFound errors in Arazzo description[39m [1mtest.yaml[22m]`;
3+
exports[`runTestFile > should throw Found errors in Arazzo description error when contains lint errors 1`] = `[Error: Found errors in Arazzo description test.yaml]`;

packages/respect-core/src/modules/__tests__/flow-runner/runner/resolve-workflow-context.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { resolveWorkflowContext, createTestContext } from '../../../flow-runner';
22
import { ApiFetcher } from '../../../../utils/api-fetcher';
33

4-
jest.mock('../../../flow-runner/context/create-test-context');
4+
vi.mock('../../../flow-runner/context/create-test-context');
55

66
describe('resolveWorkflowContext', () => {
77
const workflowId = '$sourceDescriptions.tickets-from-museum-api.workflows.get-museum-tickets';

packages/respect-core/src/modules/__tests__/flow-runner/runner/run-test-file.test.ts

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Mock } from 'vitest';
12
import { makeDocumentFromString, lint, bundle } from '@redocly/openapi-core';
23
import * as fs from 'node:fs';
34

@@ -7,29 +8,34 @@ import { runTestFile, runStep } from '../../../flow-runner';
78
import { readYaml } from '../../../../utils/yaml';
89
import { writeFileSync } from 'node:fs';
910

10-
jest.mock('../../../../utils/yaml', () => {
11-
const originalModule = jest.requireActual('../../../../utils/yaml');
11+
vi.mock('../../../../utils/yaml', () => {
12+
const originalModule = vi.importActual('../../../../utils/yaml');
13+
1214
return {
1315
...originalModule, // In case there are other exports you want to preserve
14-
readYaml: jest.fn(),
16+
readYaml: vi.fn(),
1517
};
1618
});
1719

18-
jest.mock('@redocly/openapi-core', () => ({
19-
...jest.requireActual('@redocly/openapi-core'), // Preserve other exports
20-
formatProblems: jest.fn(), // Mock formatProblems to do nothing
21-
lint: jest.fn(),
22-
bundle: jest.fn(),
23-
}));
20+
vi.mock(import('@redocly/openapi-core'), async (importOriginal) => {
21+
const originalModule = await importOriginal();
22+
23+
return {
24+
...originalModule, // Preserve other exports
25+
formatProblems: vi.fn(), // Mock formatProblems to do nothing
26+
lint: vi.fn(),
27+
bundle: vi.fn(),
28+
};
29+
});
2430

25-
jest.mock('../../../flow-runner/run-step', () => ({
26-
runStep: jest.fn(),
31+
vi.mock('../../../flow-runner/run-step', () => ({
32+
runStep: vi.fn(),
2733
}));
2834

29-
jest.mock('node:fs', () => {
30-
const actual = jest.requireActual('node:fs');
31-
const mockExistsSync = jest.fn();
32-
const mockWriteFileSync = jest.fn();
35+
vi.mock('node:fs', () => {
36+
const actual = vi.importActual('node:fs');
37+
const mockExistsSync = vi.fn();
38+
const mockWriteFileSync = vi.fn();
3339

3440
return {
3541
__esModule: true,
@@ -41,7 +47,7 @@ jest.mock('node:fs', () => {
4147
};
4248
});
4349

44-
const mockExistsSync = fs.existsSync as jest.Mock;
50+
const mockExistsSync = fs.existsSync as Mock;
4551

4652
describe('runTestFile', () => {
4753
beforeEach(() => {
@@ -61,17 +67,17 @@ describe('runTestFile', () => {
6167
}
6268
return false;
6369
});
64-
(readYaml as jest.Mock).mockReset().mockResolvedValue({
70+
(readYaml as Mock).mockReset().mockResolvedValue({
6571
openapi: '1.0.0',
6672
info: { title: 'Cat Facts API', version: '1.0' },
6773
});
68-
(lint as jest.Mock).mockReset().mockResolvedValue([]);
69-
(bundle as jest.Mock).mockReset();
70-
(runStep as jest.Mock).mockReset();
74+
(lint as Mock).mockReset().mockResolvedValue([]);
75+
(bundle as Mock).mockReset();
76+
(runStep as Mock).mockReset();
7177
});
7278

7379
afterAll(() => {
74-
jest.resetAllMocks();
80+
vi.resetAllMocks();
7581
});
7682

7783
it(`should trow error if filename is not correct`, async () => {
@@ -87,7 +93,7 @@ describe('runTestFile', () => {
8793
'test.yml'
8894
);
8995

90-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
96+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
9197

9298
await expect(runTestFile({ file: 'test.yaml' }, {})).rejects.toThrowError(
9399
'No test files found. File test.yaml does not follows naming pattern "*.[yaml | yml | json]" or have not valid "Arazzo" description.'
@@ -113,7 +119,7 @@ describe('runTestFile', () => {
113119
'test.yml'
114120
);
115121

116-
(lint as jest.Mock).mockResolvedValueOnce([
122+
(lint as Mock).mockResolvedValueOnce([
117123
{
118124
ruleId: 'spec',
119125
severity: 'error',
@@ -132,7 +138,7 @@ describe('runTestFile', () => {
132138
},
133139
]);
134140

135-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
141+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
136142

137143
await expect(
138144
runTestFile(
@@ -198,9 +204,9 @@ describe('runTestFile', () => {
198204
'api-test-framework/test.yml'
199205
);
200206

201-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
202-
(lint as jest.Mock).mockResolvedValueOnce([]);
203-
(bundle as jest.Mock).mockResolvedValueOnce({
207+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
208+
(lint as Mock).mockResolvedValueOnce([]);
209+
(bundle as Mock).mockResolvedValueOnce({
204210
bundle: {
205211
parsed: mockDocument.parsed,
206212
},
@@ -291,9 +297,9 @@ describe('runTestFile', () => {
291297
'test.yml'
292298
);
293299

294-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
295-
(lint as jest.Mock).mockResolvedValueOnce([]);
296-
(bundle as jest.Mock).mockResolvedValueOnce({
300+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
301+
(lint as Mock).mockResolvedValueOnce([]);
302+
(bundle as Mock).mockResolvedValueOnce({
297303
bundle: {
298304
parsed: mockDocument.parsed,
299305
},
@@ -385,9 +391,9 @@ describe('runTestFile', () => {
385391
'api-test-framework/test.yml'
386392
);
387393

388-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
389-
(lint as jest.Mock).mockResolvedValueOnce([]);
390-
(bundle as jest.Mock).mockResolvedValueOnce({
394+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
395+
(lint as Mock).mockResolvedValueOnce([]);
396+
(bundle as Mock).mockResolvedValueOnce({
391397
bundle: {
392398
parsed: mockDocument.parsed,
393399
},
@@ -476,15 +482,15 @@ describe('runTestFile', () => {
476482
'api-test-framework/test.yml'
477483
);
478484

479-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
480-
(lint as jest.Mock).mockResolvedValueOnce([]);
481-
(bundle as jest.Mock).mockResolvedValueOnce({
485+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
486+
(lint as Mock).mockResolvedValueOnce([]);
487+
(bundle as Mock).mockResolvedValueOnce({
482488
bundle: {
483489
parsed: mockDocument.parsed,
484490
},
485491
});
486492

487-
(runStep as jest.Mock).mockImplementation(({ step, ctx }: { step: Step; ctx: TestContext }) => {
493+
(runStep as Mock).mockImplementation(({ step, ctx }: { step: Step; ctx: TestContext }) => {
488494
step.checks = [{ name: step.stepId, passed: false, severity: 'error' }];
489495
ctx.executedSteps.push(step);
490496
});
@@ -537,9 +543,9 @@ describe('runTestFile', () => {
537543
'api-test-framework/test.yml'
538544
);
539545

540-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
541-
(lint as jest.Mock).mockResolvedValueOnce([]);
542-
(bundle as jest.Mock).mockResolvedValueOnce({
546+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
547+
(lint as Mock).mockResolvedValueOnce([]);
548+
(bundle as Mock).mockResolvedValueOnce({
543549
bundle: {
544550
parsed: mockDocument.parsed,
545551
},
@@ -592,9 +598,9 @@ describe('runTestFile', () => {
592598
'api-test-framework/test.yml'
593599
);
594600

595-
(readYaml as jest.Mock).mockResolvedValue(mockDocument.parsed);
596-
(lint as jest.Mock).mockResolvedValueOnce([]);
597-
(bundle as jest.Mock).mockResolvedValueOnce({
601+
(readYaml as Mock).mockResolvedValue(mockDocument.parsed);
602+
(lint as Mock).mockResolvedValueOnce([]);
603+
(bundle as Mock).mockResolvedValueOnce({
598604
bundle: {
599605
parsed: mockDocument.parsed,
600606
},

packages/respect-core/src/utils/__tests__/__snapshots__/ajv-errors.test.ts.snap

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`printErrors > should display multiple Ajv errors 1`] = `
4+
"
5+
UNEVALUATEDPROPERTIES must NOT have unevaluated properties: "date".: "date".
6+
7+
1 | [
8+
> 2 | {
9+
| ^
10+
> 3 | "date": "2023-09-11",
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
12+
> 4 | "timeOpen": "09:00",
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
14+
> 5 | "timeClose": "18:00"
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
16+
> 6 | },
17+
| ^^^^ 👈🏽 unevaluatedProperties must NOT have unevaluated properties: "date".: "date".
18+
7 | {
19+
8 | "date": "2023-09-12",
20+
9 | "timeOpen": "09:00",
21+
22+
UNEVALUATEDPROPERTIES must NOT have unevaluated properties: "date".: "date".
23+
24+
5 | "timeClose": "18:00"
25+
6 | },
26+
> 7 | {
27+
| ^
28+
> 8 | "date": "2023-09-12",
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
30+
> 9 | "timeOpen": "09:00",
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
32+
> 10 | "timeClose": "18:00"
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
34+
> 11 | }
35+
| ^^^^ 👈🏽 unevaluatedProperties must NOT have unevaluated properties: "date".: "date".
36+
12 | ]
37+
"
38+
`;
39+
340
exports[`printErrors should display multiple Ajv errors 1`] = `
441
"
542
UNEVALUATEDPROPERTIES must NOT have unevaluated properties: "date".: "date".

0 commit comments

Comments
 (0)