Skip to content

Commit 8b5f152

Browse files
authored
refactor: run compatibility suite tests across OpenAPI version pairs (3.0/3.1) (#58)
1 parent d70118f commit 8b5f152

File tree

16 files changed

+2921
-1860
lines changed

16 files changed

+2921
-1860
lines changed

jest.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ module.exports = {
2525
// "^@netcracker/qubership-apihub-graphapi$":'<rootDir>/../qubership-apihub-graphapi/src',
2626
// "^@netcracker/qubership-apihub-compatibility-suites$":'<rootDir>/../apihub-compatibility-suites/generation/suite-service',
2727
// },
28-
setupFilesAfterEnv: ['jest-extended/all'],
28+
setupFilesAfterEnv: [
29+
'jest-extended/all',
30+
'<rootDir>/test/setup/jest-wrappers.ts',
31+
],
2932
}

package-lock.json

Lines changed: 2518 additions & 1617 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
],
1010
"exports": {
1111
".": {
12+
"types": "./dist/index.d.ts",
1213
"import": "./dist/index.es.js",
13-
"require": "./dist/index.cjs.js",
14-
"types": "./dist/index.d.ts"
14+
"require": "./dist/index.cjs.js"
1515
}
1616
},
1717
"scripts": {
@@ -22,41 +22,41 @@
2222
"development:link": "npm link && npm link @netcracker/qubership-apihub-json-crawl && npm link @netcracker/qubership-apihub-graphapi && npm link @netcracker/qubership-apihub-api-unifier && npm link @netcracker/qubership-apihub-compatibility-suites",
2323
"development:unlink": "npm unlink && npm unlink @netcracker/qubership-apihub-json-crawl && npm unlink @netcracker/qubership-apihub-graphapi && npm unlink @netcracker/qubership-apihub-api-unifier && npm unlink @netcracker/qubership-apihub-compatibility-suites",
2424
"test": "jest --maxWorkers 3 --verbose",
25-
"test:compatibility-suites": "jest --findRelatedTests --detectOpenHandles test/compatibility-suites/*",
26-
"test:human-readble": "jest --findRelatedTests --detectOpenHandles test/human-readable/*",
25+
"test:compatibility-suites": "jest --detectOpenHandles test/compatibility-suites",
26+
"test:human-readable": "jest --detectOpenHandles test/human-readable",
2727
"update-lock-file": "update-lock-file @netcracker"
2828
},
2929
"dependencies": {
3030
"@netcracker/qubership-apihub-api-unifier": "dev",
3131
"@netcracker/qubership-apihub-json-crawl": "dev",
32-
"fast-equals": "4.0.3"
32+
"fast-equals": "6.0.0"
3333
},
3434
"devDependencies": {
3535
"@netcracker/qubership-apihub-compatibility-suites": "dev",
3636
"@netcracker/qubership-apihub-graphapi": "dev",
3737
"@netcracker/qubership-apihub-npm-gitflow": "3.1.0",
38-
"@types/jest": "29.5.11",
39-
"@types/node": "20.11.6",
40-
"@typescript-eslint/eslint-plugin": "6.13.2",
41-
"@typescript-eslint/parser": "6.13.2",
42-
"eslint": "8.55.0",
43-
"eslint-plugin-sort-exports": "0.8.0",
44-
"jest": "29.7.0",
45-
"jest-extended": "^4.0.2",
38+
"@types/jest": "30.0.0",
39+
"@types/js-yaml": "4.0.9",
40+
"@types/node": "25.0.3",
41+
"@typescript-eslint/eslint-plugin": "7.18.0",
42+
"@typescript-eslint/parser": "7.18.0",
43+
"eslint": "8.57.1",
44+
"eslint-plugin-sort-exports": "0.9.1",
45+
"fast-json-patch": "3.1.1",
46+
"graphql": "16.12.0",
47+
"jest": "30.2.0",
48+
"jest-extended": "7.0.0",
49+
"js-yaml": "4.1.1",
4650
"openapi-types": "12.1.3",
47-
"@types/js-yaml": "^4.0.5",
48-
"fast-json-patch": "^3.1.1",
49-
"graphql": "16.9.0",
50-
"js-yaml": "^4.1.0",
51-
"rimraf": "^5.0.5",
52-
"ts-loader": "^8.4.0",
53-
"ts-node": "^10.9.2",
54-
"tslint": "^6.1.3",
55-
"ts-jest": "29.1.1",
56-
"typescript": "5.3.3",
57-
"vite": "5.2.6",
58-
"vite-plugin-dts": "3.6.4",
59-
"vite-plugin-singlefile": "2.0.1"
51+
"rimraf": "6.1.2",
52+
"ts-jest": "29.4.6",
53+
"ts-loader": "9.5.4",
54+
"ts-node": "10.9.2",
55+
"tslint": "6.1.3",
56+
"typescript": "5.9.3",
57+
"vite": "7.3.1",
58+
"vite-plugin-dts": "4.5.4",
59+
"vite-plugin-singlefile": "2.3.0"
6060
},
6161
"eslintConfig": {
6262
"extends": ".eslintrc.json"

test/compatibility-suites/openapi/general-operation-parameters.test.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { compareFiles, TEST_DEFAULTS_DECLARATION_PATHS } from '../utils'
2-
import { diffsMatcher } from '../../helper/matchers'
2+
import { diffsMatcher, expectOpenApiVersionChange } from '../../helper/matchers'
33
import { annotation, breaking, deprecated, DiffAction, nonBreaking } from '../../../src'
44

55
const SUITE_ID = 'general-operation-parameters'
@@ -775,10 +775,9 @@ const PATH_ITEM_PATH = [
775775
]
776776

777777
describe('Openapi3.1 PathItems', () => {
778-
test('Add method in path item', async () => {
779-
const testId = 'add-method-in-path-item'
780-
const result = await compareFiles(SUITE_ID, testId)
781-
expect(result).toEqual(diffsMatcher([
778+
test.caseForOpenApiVersionPairs('add-method-in-path-item', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
779+
expect(diffs).toEqual(diffsMatcher([
780+
expectOpenApiVersionChange(beforeVersion, afterVersion),
782781
expect.objectContaining({
783782
action: DiffAction.add,
784783
afterDeclarationPaths: [[...PATH_ITEM_PATH, 'post']],
@@ -787,22 +786,21 @@ describe('Openapi3.1 PathItems', () => {
787786
]))
788787
})
789788

790-
test('Remove unused method in path item', async () => {
791-
const testId = 'remove-unused-method-in-path-item'
792-
const result = await compareFiles(SUITE_ID, testId)
793-
expect(result).toEqual([])
789+
test.caseForOpenApiVersionPairs('remove-unused-method-in-path-item', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
790+
expect(diffs).toEqual(diffsMatcher([
791+
expectOpenApiVersionChange(beforeVersion, afterVersion),
792+
]))
794793
})
795794

796-
test('Add unused method in path item', async () => {
797-
const testId = 'add-unused-method-in-path-item'
798-
const result = await compareFiles(SUITE_ID, testId)
799-
expect(result).toEqual([])
795+
test.caseForOpenApiVersionPairs('add-unused-method-in-path-item', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
796+
expect(diffs).toEqual(diffsMatcher([
797+
expectOpenApiVersionChange(beforeVersion, afterVersion),
798+
]))
800799
})
801800

802-
test('Remove method in path item', async () => {
803-
const testId = 'remove-method-in-path-item'
804-
const result = await compareFiles(SUITE_ID, testId)
805-
expect(result).toEqual(diffsMatcher([
801+
test.caseForOpenApiVersionPairs('remove-method-in-path-item', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
802+
expect(diffs).toEqual(diffsMatcher([
803+
expectOpenApiVersionChange(beforeVersion, afterVersion),
806804
expect.objectContaining({
807805
action: DiffAction.remove,
808806
beforeDeclarationPaths: [[...PATH_ITEM_PATH, 'post']],
@@ -811,15 +809,15 @@ describe('Openapi3.1 PathItems', () => {
811809
]))
812810
})
813811

814-
test('Replace inline path item to ref', async () => {
815-
const testId = 'replace-inline-path-item-to-ref'
816-
const result = await compareFiles(SUITE_ID, testId)
817-
expect(result).toEqual([])
812+
test.caseForOpenApiVersionPairs('replace-inline-path-item-to-ref', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
813+
expect(diffs).toEqual(diffsMatcher([
814+
expectOpenApiVersionChange(beforeVersion, afterVersion),
815+
]))
818816
})
819817

820-
test('Replace ref path item to inline', async () => {
821-
const testId = 'replace-ref-path-item-to-inline'
822-
const result = await compareFiles(SUITE_ID, testId)
823-
expect(result).toEqual([])
818+
test.caseForOpenApiVersionPairs('replace-ref-path-item-to-inline', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
819+
expect(diffs).toEqual(diffsMatcher([
820+
expectOpenApiVersionChange(beforeVersion, afterVersion),
821+
]))
824822
})
825823
})

test/compatibility-suites/openapi/response-body-schema.test.ts

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { compareFiles, compareFilesWithMerge, TEST_DEFAULTS_DECLARATION_PATHS } from '../utils'
2-
import { diffsMatcher } from '../../helper/matchers'
2+
import { diffsMatcher, expectOpenApiVersionChange } from '../../helper/matchers'
33
import { annotation, breaking, DiffAction, nonBreaking, risky } from '../../../src'
44
import { JSON_SCHEMA_NODE_SYNTHETIC_TYPE_ANY } from '@netcracker/qubership-apihub-api-unifier'
55
import { runAddRemoveDefaultValuesSchemaTests } from './templates/schema'
@@ -101,46 +101,40 @@ describe('Openapi3 ResponseBody.Schema ', () => {
101101
expect(result).toEqual([])
102102
})
103103

104-
test('Mark schema value as nullable', async () => {
105-
const testId = 'mark-schema-value-as-nullable'
106-
const result = await compareFiles(SUITE_ID, testId)
107-
expect(result).toEqual(diffsMatcher(
108-
[
109-
expect.objectContaining({
110-
action: DiffAction.replace,
111-
beforeDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
112-
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
113-
type: breaking,
114-
}),
115-
expect.objectContaining({
116-
action: DiffAction.replace,
117-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
118-
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
119-
type: breaking,
120-
}),
121-
],
122-
))
104+
test.caseForOpenApiVersionPairs('mark-schema-value-as-nullable', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
105+
expect(diffs).toEqual(diffsMatcher([
106+
expectOpenApiVersionChange(beforeVersion, afterVersion),
107+
expect.objectContaining({
108+
action: DiffAction.replace,
109+
beforeDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
110+
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
111+
type: breaking,
112+
}),
113+
expect.objectContaining({
114+
action: DiffAction.replace,
115+
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
116+
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
117+
type: breaking,
118+
}),
119+
]))
123120
})
124121

125-
test('Mark schema value as non-nullable', async () => {
126-
const testId = 'mark-schema-value-as-non-nullable'
127-
const result = await compareFiles(SUITE_ID, testId)
128-
expect(result).toEqual(diffsMatcher(
129-
[
130-
expect.objectContaining({
131-
action: DiffAction.replace,
132-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
133-
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
134-
type: nonBreaking,
135-
}),
136-
expect.objectContaining({
137-
action: DiffAction.replace,
138-
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
139-
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
140-
type: nonBreaking,
141-
}),
142-
],
143-
))
122+
test.caseForOpenApiVersionPairs('mark-schema-value-as-non-nullable', SUITE_ID, async ({ beforeVersion, afterVersion, diffs }) => {
123+
expect(diffs).toEqual(diffsMatcher([
124+
expectOpenApiVersionChange(beforeVersion, afterVersion),
125+
expect.objectContaining({
126+
action: DiffAction.replace,
127+
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
128+
afterDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option1', 'nullable']],
129+
type: nonBreaking,
130+
}),
131+
expect.objectContaining({
132+
action: DiffAction.replace,
133+
beforeDeclarationPaths: [[...RESPONSE_SCHEMA_PATH, 'properties', 'option2', 'nullable']],
134+
afterDeclarationPaths: TEST_DEFAULTS_DECLARATION_PATHS,
135+
type: nonBreaking,
136+
}),
137+
]))
144138
})
145139

146140
test('Add enum', async () => {
Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { JsonPath } from '@netcracker/qubership-apihub-json-crawl'
2-
import { compareFiles } from '../../utils'
3-
import { diffsMatcher } from '../../../helper/matchers'
2+
import { diffsMatcher, expectOpenApiVersionChange } from '../../../helper/matchers'
43
import { annotation, DiffAction } from '../../../../src'
54

65
const enum OverridenFields {
@@ -17,48 +16,45 @@ export function runRefObjectSummaryTests(suiteId: string, refPath: JsonPath, com
1716
}
1817

1918
export function runReferenceObjectTests(suiteId: string, refPath: JsonPath, componentPath: JsonPath, overridenField: OverridenFields): void {
20-
test(`Add overriden ${overridenField}`, async () => {
21-
const testId = `add-overriden-${overridenField}`
22-
const result = await compareFiles(suiteId, testId)
23-
expect(result).toEqual(diffsMatcher([
19+
test.caseForOpenApiVersionPairs(`add-overriden-${overridenField}`, suiteId, async ({ beforeVersion, afterVersion, diffs }) => {
20+
expect(diffs).toEqual(diffsMatcher([
21+
expectOpenApiVersionChange(beforeVersion, afterVersion),
2422
expect.objectContaining({
2523
action: DiffAction.replace,
26-
afterDeclarationPaths: [[...refPath , overridenField]],
24+
afterDeclarationPaths: [[...refPath, overridenField]],
2725
beforeDeclarationPaths: [[...componentPath, overridenField]],
2826
type: annotation,
2927
}),
3028
]))
3129
})
3230

33-
test(`Remove overriden ${overridenField}`, async () => {
34-
const testId = `remove-overriden-${overridenField}`
35-
const result = await compareFiles(suiteId, testId)
36-
expect(result).toEqual(diffsMatcher([
31+
test.caseForOpenApiVersionPairs(`remove-overriden-${overridenField}`, suiteId, async ({ beforeVersion, afterVersion, diffs }) => {
32+
expect(diffs).toEqual(diffsMatcher([
33+
expectOpenApiVersionChange(beforeVersion, afterVersion),
3734
expect.objectContaining({
3835
action: DiffAction.replace,
3936
afterDeclarationPaths: [[...componentPath, overridenField]],
40-
beforeDeclarationPaths: [[...refPath , overridenField]],
37+
beforeDeclarationPaths: [[...refPath, overridenField]],
4138
type: annotation,
4239
}),
4340
]))
4441
})
4542

46-
test(`Change overriden ${overridenField}`, async () => {
47-
const testId = `change-overriden-${overridenField}`
48-
const result = await compareFiles(suiteId, testId)
49-
expect(result).toEqual(diffsMatcher([
43+
test.caseForOpenApiVersionPairs(`change-overriden-${overridenField}`, suiteId, async ({ beforeVersion, afterVersion, diffs }) => {
44+
expect(diffs).toEqual(diffsMatcher([
45+
expectOpenApiVersionChange(beforeVersion, afterVersion),
5046
expect.objectContaining({
5147
action: DiffAction.replace,
52-
afterDeclarationPaths: [[...refPath , overridenField]],
53-
beforeDeclarationPaths: [[...refPath , overridenField]],
48+
afterDeclarationPaths: [[...refPath, overridenField]],
49+
beforeDeclarationPaths: [[...refPath, overridenField]],
5450
type: annotation,
5551
}),
5652
]))
5753
})
5854

59-
test(`Change referenced ${overridenField} when overridden exists`, async () => {
60-
const testId = `change-referenced-${overridenField}-when-overridden-exists`
61-
const diffs = await compareFiles(suiteId, testId)
62-
expect(diffs).toBeEmpty()
55+
test.caseForOpenApiVersionPairs(`change-referenced-${overridenField}-when-overridden-exists`, suiteId, async ({ beforeVersion, afterVersion, diffs }) => {
56+
expect(diffs).toEqual(diffsMatcher([
57+
expectOpenApiVersionChange(beforeVersion, afterVersion),
58+
]))
6359
})
6460
}

0 commit comments

Comments
 (0)