Skip to content

Commit

Permalink
fix: made inject readme consider more things as matching
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Nov 14, 2022
1 parent 7ec7b26 commit 33acfff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/presets/semver-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function closeEnough(a: string, b: string) {
const bLines = b.split('\n')

const matchingLines = aLines.filter((line) => bLines.find((bLine) => bLine === line)).length
const isCloseEnough = matchingLines > aLines.length * 0.5
const isCloseEnough = matchingLines >= aLines.length * 0.5
return isCloseEnough
}

Expand Down
28 changes: 24 additions & 4 deletions test/semver-workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tap from 'tap'
import {missingSections, readmeBaseurl} from '../src/presets/semver-workflow'
import {PackageJson} from '../src/actions/verify/types'
import outdent from 'outdent'
import {getLicenseText} from '../src/util/readme'

tap.test('readmeBaseUrl', async (t) => {
const testCases: {pkg: PackageJson; expectedUrl: string}[] = [
Expand Down Expand Up @@ -36,18 +37,29 @@ tap.test('missingSections', async (t) => {
matches b
exactly c
`

const exactMatch2 = getLicenseText('MIT', {name: 'yolo'})

const over50PercentMatch = outdent`
This x
matches y
enough z
`
const only50PercentMatch = outdent`
const fiftyPercentMatch = outdent`
This
does
not
barely
match
`

const lessThan50PercentMatch = outdent`
This not
does not
not not
match
`
const sections = [exactMatch, over50PercentMatch, only50PercentMatch]

const sections = [exactMatch, over50PercentMatch, fiftyPercentMatch, lessThan50PercentMatch]

const readme = outdent`
This a
Expand All @@ -58,11 +70,19 @@ tap.test('missingSections', async (t) => {
matches y
enough zzzzzz
This
does
barely
match
This
does
miss
${exactMatch2}
`

const missing = missingSections(readme, sections)
t.same(missing, [only50PercentMatch])
t.same(missing, [lessThan50PercentMatch])
})

0 comments on commit 33acfff

Please sign in to comment.