|
1 | 1 | import { expect, test } from "vitest"; |
2 | 2 | import { extractExportAndGenerateChangelog } from "../../changelog/extractMetaData"; |
3 | | -import path from "path"; |
| 3 | +import path, { join } from "path"; |
4 | 4 | import { SDKType } from "../../common/types"; |
5 | | - |
6 | | -test("HLC -> Modular: Rename", async () => { |
7 | | - const oldViewPath = path.join( |
8 | | - __dirname, |
9 | | - "testCases/operationGroups.1.old.hlc.api.md" |
10 | | - ); |
11 | | - const newViewPath = path.join( |
12 | | - __dirname, |
13 | | - "testCases/operationGroups.1.new.modular.api.md" |
14 | | - ); |
15 | | - const changelog = await extractExportAndGenerateChangelog( |
16 | | - oldViewPath, |
17 | | - newViewPath, |
18 | | - SDKType.HighLevelClient, |
19 | | - SDKType.ModularClient |
20 | | - ); |
21 | | - |
22 | | - expect(changelog.addedOperationGroup.length).toBe(0); |
23 | | - expect(changelog.removedOperationGroup.length).toBe(0); |
24 | | - |
25 | | - expect(changelog.addedOperation.length).toBe(1); |
26 | | - expect(changelog.removedOperation.length).toBe(1); |
27 | | - |
28 | | - expect(changelog.addedOperation[0]).toBe( |
29 | | - "Added operation DataProductsCatalogsOperations.listByResourceGroup_NEW" |
30 | | - ); |
31 | | - expect(changelog.removedOperation[0]).toBe( |
32 | | - "Removed operation DataProductsCatalogs.listByResourceGroup" |
33 | | - ); |
34 | | -}); |
35 | | - |
36 | | -test("HLC -> HLC: Change Op", async () => { |
37 | | - const oldViewPath = path.join( |
38 | | - __dirname, |
39 | | - "testCases/operationGroups.2.old.hlc.api.md" |
40 | | - ); |
41 | | - const newViewPath = path.join( |
42 | | - __dirname, |
43 | | - "testCases/operationGroups.2.new.hlc.api.md" |
44 | | - ); |
45 | | - const changelog = await extractExportAndGenerateChangelog( |
46 | | - oldViewPath, |
47 | | - newViewPath, |
48 | | - SDKType.HighLevelClient, |
49 | | - SDKType.HighLevelClient |
50 | | - ); |
51 | | - |
52 | | - expect(changelog.addedOperationGroup.length).toBe(0); |
53 | | - expect(changelog.removedOperationGroup.length).toBe(0); |
54 | | - |
55 | | - expect(changelog.addedOperation.length).toBe(1); |
56 | | - expect(changelog.removedOperation.length).toBe(1); |
57 | | - |
58 | | - expect(changelog.addedOperation[0]).toBe( |
59 | | - "Added operation DataProductsCatalogs.get_NEW" |
60 | | - ); |
61 | | - expect(changelog.removedOperation[0]).toBe( |
62 | | - "Removed operation DataProductsCatalogs.get" |
63 | | - ); |
64 | | -}); |
65 | | - |
66 | | -test("Modular -> Modular: Change Op", async () => { |
67 | | - const oldViewPath = path.join( |
68 | | - __dirname, |
69 | | - "testCases/operationGroups.3.old.modular.api.md" |
70 | | - ); |
71 | | - const newViewPath = path.join( |
72 | | - __dirname, |
73 | | - "testCases/operationGroups.3.new.modular.api.md" |
74 | | - ); |
75 | | - const changelog = await extractExportAndGenerateChangelog( |
76 | | - oldViewPath, |
77 | | - newViewPath, |
78 | | - SDKType.ModularClient, |
79 | | - SDKType.ModularClient |
80 | | - ); |
81 | | - |
82 | | - expect(changelog.addedOperationGroup.length).toBe(0); |
83 | | - expect(changelog.removedOperationGroup.length).toBe(0); |
84 | | - |
85 | | - expect(changelog.addedOperation.length).toBe(1); |
86 | | - expect(changelog.removedOperation.length).toBe(1); |
87 | | - |
88 | | - expect(changelog.addedOperation[0]).toBe( |
89 | | - "Added operation DataProductsCatalogsOperations.listByResourceGroup_NEW" |
90 | | - ); |
91 | | - expect(changelog.removedOperation[0]).toBe( |
92 | | - "Removed operation DataProductsCatalogsOperations.listByResourceGroup" |
93 | | - ); |
| 5 | +import { describe } from "node:test"; |
| 6 | +import { mkdirSync } from "node:fs"; |
| 7 | +import { tryReadNpmPackageChangelog } from "../../common/utils"; |
| 8 | +import { rmdirSync, writeFileSync } from "fs"; |
| 9 | + |
| 10 | +function getRandomInt(max) { |
| 11 | + return Math.floor(Math.random() * max); |
| 12 | +} |
| 13 | + |
| 14 | +describe("Breaking change detection", () => { |
| 15 | + test("HLC -> Modular: Rename", async () => { |
| 16 | + const oldViewPath = path.join( |
| 17 | + __dirname, |
| 18 | + "testCases/operationGroups.1.old.hlc.api.md" |
| 19 | + ); |
| 20 | + const newViewPath = path.join( |
| 21 | + __dirname, |
| 22 | + "testCases/operationGroups.1.new.modular.api.md" |
| 23 | + ); |
| 24 | + const changelog = await extractExportAndGenerateChangelog( |
| 25 | + oldViewPath, |
| 26 | + newViewPath, |
| 27 | + SDKType.HighLevelClient, |
| 28 | + SDKType.ModularClient |
| 29 | + ); |
| 30 | + |
| 31 | + expect(changelog.addedOperationGroup.length).toBe(0); |
| 32 | + expect(changelog.removedOperationGroup.length).toBe(0); |
| 33 | + |
| 34 | + expect(changelog.addedOperation.length).toBe(1); |
| 35 | + expect(changelog.removedOperation.length).toBe(1); |
| 36 | + |
| 37 | + expect(changelog.addedOperation[0]).toBe( |
| 38 | + "Added operation DataProductsCatalogsOperations.listByResourceGroup_NEW" |
| 39 | + ); |
| 40 | + expect(changelog.removedOperation[0]).toBe( |
| 41 | + "Removed operation DataProductsCatalogs.listByResourceGroup" |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + test("HLC -> HLC: Change Op", async () => { |
| 46 | + const oldViewPath = path.join( |
| 47 | + __dirname, |
| 48 | + "testCases/operationGroups.2.old.hlc.api.md" |
| 49 | + ); |
| 50 | + const newViewPath = path.join( |
| 51 | + __dirname, |
| 52 | + "testCases/operationGroups.2.new.hlc.api.md" |
| 53 | + ); |
| 54 | + const changelog = await extractExportAndGenerateChangelog( |
| 55 | + oldViewPath, |
| 56 | + newViewPath, |
| 57 | + SDKType.HighLevelClient, |
| 58 | + SDKType.HighLevelClient |
| 59 | + ); |
| 60 | + |
| 61 | + expect(changelog.addedOperationGroup.length).toBe(0); |
| 62 | + expect(changelog.removedOperationGroup.length).toBe(0); |
| 63 | + |
| 64 | + expect(changelog.addedOperation.length).toBe(1); |
| 65 | + expect(changelog.removedOperation.length).toBe(1); |
| 66 | + |
| 67 | + expect(changelog.addedOperation[0]).toBe( |
| 68 | + "Added operation DataProductsCatalogs.get_NEW" |
| 69 | + ); |
| 70 | + expect(changelog.removedOperation[0]).toBe( |
| 71 | + "Removed operation DataProductsCatalogs.get" |
| 72 | + ); |
| 73 | + }); |
| 74 | + |
| 75 | + test("Modular -> Modular: Change Op", async () => { |
| 76 | + const oldViewPath = path.join( |
| 77 | + __dirname, |
| 78 | + "testCases/operationGroups.3.old.modular.api.md" |
| 79 | + ); |
| 80 | + const newViewPath = path.join( |
| 81 | + __dirname, |
| 82 | + "testCases/operationGroups.3.new.modular.api.md" |
| 83 | + ); |
| 84 | + const changelog = await extractExportAndGenerateChangelog( |
| 85 | + oldViewPath, |
| 86 | + newViewPath, |
| 87 | + SDKType.ModularClient, |
| 88 | + SDKType.ModularClient |
| 89 | + ); |
| 90 | + |
| 91 | + expect(changelog.addedOperationGroup.length).toBe(0); |
| 92 | + expect(changelog.removedOperationGroup.length).toBe(0); |
| 93 | + |
| 94 | + expect(changelog.addedOperation.length).toBe(1); |
| 95 | + expect(changelog.removedOperation.length).toBe(1); |
| 96 | + |
| 97 | + expect(changelog.addedOperation[0]).toBe( |
| 98 | + "Added operation DataProductsCatalogsOperations.listByResourceGroup_NEW" |
| 99 | + ); |
| 100 | + expect(changelog.removedOperation[0]).toBe( |
| 101 | + "Removed operation DataProductsCatalogsOperations.listByResourceGroup" |
| 102 | + ); |
| 103 | + }); |
| 104 | + |
| 105 | + test("HLC -> HLC: Operation Group Add/Remove/ChangeSig", async () => { |
| 106 | + const oldViewPath = path.join( |
| 107 | + __dirname, |
| 108 | + "testCases/operationGroups.4.old.hlc.api.md" |
| 109 | + ); |
| 110 | + const newViewPath = path.join( |
| 111 | + __dirname, |
| 112 | + "testCases/operationGroups.4.new.hlc.api.md" |
| 113 | + ); |
| 114 | + const changelog = await extractExportAndGenerateChangelog( |
| 115 | + oldViewPath, |
| 116 | + newViewPath, |
| 117 | + SDKType.HighLevelClient, |
| 118 | + SDKType.HighLevelClient |
| 119 | + ); |
| 120 | + |
| 121 | + expect(changelog.addedOperationGroup.length).toBe(1); |
| 122 | + expect(changelog.removedOperationGroup.length).toBe(1); |
| 123 | + |
| 124 | + expect(changelog.addedOperation.length).toBe(0); |
| 125 | + expect(changelog.removedOperation.length).toBe(0); |
| 126 | + |
| 127 | + expect(changelog.operationSignatureChange.length).toBe(1); |
| 128 | + |
| 129 | + expect(changelog.addedOperationGroup[0]).toBe( |
| 130 | + "Added operation group DataProductsCatalogs_add" |
| 131 | + ); |
| 132 | + expect(changelog.removedOperationGroup[0]).toBe( |
| 133 | + "Removed operation group DataProductsCatalogs_remove" |
| 134 | + ); |
| 135 | + expect(changelog.operationSignatureChange[0]).toBe( |
| 136 | + "Operation DataProductsCatalogs_sig_change.get has a new signature" |
| 137 | + ); |
| 138 | + }); |
94 | 139 | }); |
95 | 140 |
|
96 | | -test("HLC -> HLC: Operation Group Add/Remove/ChangeSig", async () => { |
97 | | - const oldViewPath = path.join( |
98 | | - __dirname, |
99 | | - "testCases/operationGroups.4.old.hlc.api.md" |
100 | | - ); |
101 | | - const newViewPath = path.join( |
102 | | - __dirname, |
103 | | - "testCases/operationGroups.4.new.hlc.api.md" |
104 | | - ); |
105 | | - const changelog = await extractExportAndGenerateChangelog( |
106 | | - oldViewPath, |
107 | | - newViewPath, |
108 | | - SDKType.HighLevelClient, |
109 | | - SDKType.HighLevelClient |
110 | | - ); |
111 | | - |
112 | | - expect(changelog.addedOperationGroup.length).toBe(1); |
113 | | - expect(changelog.removedOperationGroup.length).toBe(1); |
114 | | - |
115 | | - expect(changelog.addedOperation.length).toBe(0); |
116 | | - expect(changelog.removedOperation.length).toBe(0); |
117 | | - |
118 | | - expect(changelog.operationSignatureChange.length).toBe(1); |
119 | | - |
120 | | - expect(changelog.addedOperationGroup[0]).toBe( |
121 | | - "Added operation group DataProductsCatalogs_add" |
122 | | - ); |
123 | | - expect(changelog.removedOperationGroup[0]).toBe( |
124 | | - "Removed operation group DataProductsCatalogs_remove" |
125 | | - ); |
126 | | - expect(changelog.operationSignatureChange[0]).toBe( |
127 | | - "Operation DataProductsCatalogs_sig_change.get has a new signature" |
128 | | - ); |
| 141 | +describe("Changelog reading", () => { |
| 142 | + const tempPackageFolder = `./tmp/package-${getRandomInt(10000)}`; |
| 143 | + try { |
| 144 | + test("Read changelog that doesn't exist", () => { |
| 145 | + const content = tryReadNpmPackageChangelog(tempPackageFolder); |
| 146 | + expect(content).toBe(""); |
| 147 | + }); |
| 148 | + const changelogPath = join(tempPackageFolder, 'CHANGELOG.md') |
| 149 | + writeFileSync(changelogPath, 'aaa', 'utf-8'); |
| 150 | + |
| 151 | + test("Read changelog that exists", () => { |
| 152 | + const content = tryReadNpmPackageChangelog(tempPackageFolder); |
| 153 | + expect(content).toBe("aaa"); |
| 154 | + }) |
| 155 | + } finally { |
| 156 | + rmdirSync(tempPackageFolder); |
| 157 | + } |
129 | 158 | }); |
0 commit comments