Skip to content

Commit d417bf6

Browse files
authored
Merge pull request #4 from fingerprintjs/feat/heading-option
This update supports an optional `heading` field in the plugin configuration.
2 parents 2f41e0b + 892b1ee commit d417bf6

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/@types/pluginConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export default interface PluginConfig {
1212
iOS?: IOSPlatformConfiguration
1313
/** @deprecated Use `platforms.android` instead */
1414
android?: AndroidPlatformConfiguration
15+
heading?: string
1516
}

src/generateNotes.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ const generateNotes = async (config: PluginConfig, ctx: GenerateNotesContext) =>
3737
ctx.logger.log(`Detected iOS Version: \`${iOSVersion}\``)
3838
}
3939

40-
return Object.keys(platformVersions)
40+
let notes = ''
41+
42+
if (config.heading) {
43+
notes += `### ${config.heading}\n\n`
44+
}
45+
46+
notes += Object.keys(platformVersions)
4147
.map((platformKey) => {
4248
const platform = platformKey as keyof PlatformConfig
4349
const version = platformVersions[platform]
4450
return `${platforms[platform]?.displayName ?? platform} Version Range: **\`${version}\`**`
4551
})
4652
.join('\n\n')
53+
54+
return notes
4755
}
4856

4957
export default generateNotes

test/index.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,42 @@ describe('index', () => {
108108
it('throws error when no platform specified', async () => {
109109
await expect(generateNotes({}, generateNotesContext)).rejects.toThrowErrorMatchingSnapshot('noPlatform')
110110
})
111+
describe('heading', () => {
112+
const heading = 'Example Heading'
113+
const { iOS, android } = pluginConfig.platforms
114+
115+
const expectedHeading = `### ${heading}`
116+
const expectedAndroid = `${android.displayName} Version Range: **\`>= 1.2.3 and < 4.5.6\`**`
117+
const expectedIOS = `${iOS.displayName} Version Range: **\`>= 1.2.3 and < 4.5.6\`**`
118+
119+
const subTestCases = [
120+
{
121+
platforms: { iOS, android },
122+
expected: [expectedHeading, expectedAndroid, expectedIOS].join('\n\n'),
123+
},
124+
{
125+
platforms: { iOS },
126+
expected: [expectedHeading, expectedIOS].join('\n\n'),
127+
},
128+
{
129+
platforms: { android },
130+
expected: [expectedHeading, expectedAndroid].join('\n\n'),
131+
},
132+
]
133+
134+
subTestCases.forEach((testCase) => {
135+
it(`adds heading when specified for platforms: ${Object.keys(testCase.platforms).join(', ')}`, async () => {
136+
await expect(
137+
generateNotes(
138+
{
139+
platforms: testCase.platforms,
140+
heading,
141+
},
142+
generateNotesContext
143+
)
144+
).resolves.toBe(testCase.expected)
145+
}, 30000)
146+
})
147+
})
111148
})
112149
})

0 commit comments

Comments
 (0)