generated from salesforcecli/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparseReleaseNotes.test.ts
More file actions
134 lines (104 loc) · 4.55 KB
/
parseReleaseNotes.test.ts
File metadata and controls
134 lines (104 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'node:fs';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, use as chaiUse, assert } from 'chai';
import Sinon from 'sinon';
import SinonChai from 'sinon-chai';
import { spyMethod } from '@salesforce/ts-sinon';
import { marked } from 'marked';
import { parseReleaseNotes } from '../../src/shared/parseReleaseNotes.js';
chaiUse(SinonChai);
describe('parseReleaseNotes tests', () => {
const sandbox = Sinon.createSandbox();
const notes = fs.readFileSync(`${dirname(fileURLToPath(import.meta.url))}/../fixtures/notes.md`, 'utf8');
const baseUrl = 'https://github.com/forcedotcom/cli/tree/main/releasenotes/sfdx';
let lexerSpy: Sinon.SinonSpy;
beforeEach(() => {
lexerSpy = spyMethod(sandbox, marked, 'lexer');
});
afterEach(() => {
sandbox.restore();
});
it('calls lexer with raw release notes', () => {
parseReleaseNotes(notes, '7.121.8', baseUrl);
expect(lexerSpy.called).to.be.true;
expect(lexerSpy.args[0][0]).to.deep.equal(notes);
});
it('filters out correct version from tokens', () => {
const tokens = parseReleaseNotes(notes, '7.121.8', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[0].raw).to.include('7.121.8');
expect(results).to.include('7.121.8');
expect(results).to.not.include('7.123.0');
expect(results).to.not.include('7.122.1');
expect(results).to.not.include('7.120.0');
});
it('throws error if version is not found', () => {
try {
parseReleaseNotes(notes, '1.2.3', baseUrl);
} catch (err) {
assert(err instanceof Error);
expect(err.message).to.equal(`Didn't find version '1.2.3'. View release notes online at: ${baseUrl}`);
}
});
it('matches entire version, not partial', () => {
const tokens = parseReleaseNotes(notes, '13.3.1', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[0].raw).to.include('13.3.1');
expect(results).to.include('- test for matching full version (`3.3.1 !== 13.3.1`)');
try {
// Won't find partial version (3.3.1 is part of 13.3.1)
parseReleaseNotes(notes, '3.3.1', baseUrl);
} catch (err) {
assert(err instanceof Error);
expect(err.message).to.equal(`Didn't find version '3.3.1'. View release notes online at: ${baseUrl}`);
}
});
it('fixes relative links in releasenotes', () => {
const tokens = parseReleaseNotes(notes, '7.121.8', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(results).to.include(`${baseUrl}/./test.md`);
});
it('finds a version above what was asked for if not found', () => {
const tokens = parseReleaseNotes(notes, '63.17.0', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[1].raw).to.include('63.17.2');
expect(results).to.include('- test for finding nearby versions');
});
it('finds a version below what was asked for if not found', () => {
const tokens = parseReleaseNotes(notes, '63.17.5', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[1].raw).to.include('63.17.2');
expect(results).to.include('- test for finding nearby versions');
});
it('finds highest version if multiple minors exist', () => {
const tokens = parseReleaseNotes(notes, '63.18.0', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[1].raw).to.include('63.18.2'); // 63.18.1 exists in fixtures/notes
expect(results).to.include('- testing multiple minors (higher)');
});
it('shows warning if a different version is shown', () => {
const tokens = parseReleaseNotes(notes, '63.18.0', baseUrl);
const results = JSON.stringify(tokens, null, ' ');
expect(tokens[0].raw).to.include('63.18.0'); // version asked for
expect(tokens[0].raw).to.include('63.18.2'); // version found
expect(results).to.include(
'ATTENTION: Version 63.18.0 was not found. Showing notes for closest patch version 63.18.2.'
);
});
});