Skip to content

Commit

Permalink
add jest to eslint and fix lint issues in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Aug 20, 2022
1 parent 248b4be commit 95eec5c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 54 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:unicorn/recommended",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:jest/recommended",
"plugin:jest/style"
],
"parserOptions": {
"ecmaVersion": 2022
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"cross-env": "^7.0.3",
"eslint": "8.20.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "^26.8.2",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-unicorn": "^43.0.2",
"husky": "8.0.1",
Expand Down
4 changes: 0 additions & 4 deletions packages/core/tests/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,6 @@ describe('schema', () => {
test(`${number + 1} is valid`, () => {
const value = schema().parse(example)
expect(value).toMatchObject(expected)
if (value.replacers) {
for (const [index, arrayValue] of value.replacers.entries())
expect(arrayValue.search).toEqual(expected.replacers[index].search)
}
})
}
})
Expand Down
14 changes: 7 additions & 7 deletions packages/core/tests/template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('template', () => {
it('replaces $A with B', () => {
const output = template('$A', { $A: 'B' })

expect(output).toEqual('B')
expect(output).toBe('B')
})

it('replaces $MAJOR.$MINOR.$PATCH with 1.0.0', () => {
Expand All @@ -19,7 +19,7 @@ describe('template', () => {
$PATCH: 0,
})

expect(output).toEqual('1.0.0')
expect(output).toBe('1.0.0')
})

it('replaces $CHANGES but leaves $NEXT_PATCH_VERSION', () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('template', () => {
} as never,
})

expect(output).toEqual('1.0.0.THIRD LEVEL')
expect(output).toBe('1.0.0.THIRD LEVEL')
})
it('single custom replacer', () => {
const customReplacer = [
Expand All @@ -66,7 +66,7 @@ describe('template', () => {
customReplacer,
)

expect(output).toEqual(
expect(output).toBe(
'This is my body [https://issues.jenkins-ci.org/browse/JENKINS-1234](JENKINS-1234) [https://issues.jenkins-ci.org/browse/JENKINS-1234](JENKINS-1234) [https://issues.jenkins-ci.org/browse/JENKINS-1234](JENKINS-1234)',
)
})
Expand All @@ -79,7 +79,7 @@ describe('template', () => {
]
const output = template('This is my body JENKINS-1234', {}, customReplacer)

expect(output).toEqual('This is my body heyyyyyyy-1234')
expect(output).toBe('This is my body heyyyyyyy-1234')
})
it('overlapping replacer', () => {
const customReplacer = [
Expand All @@ -94,7 +94,7 @@ describe('template', () => {
]
const output = template('This is my body JENKINS-1234', {}, customReplacer)

expect(output).toEqual('This is my body something else-1234')
expect(output).toBe('This is my body something else-1234')
})
it('multiple custom replacer', () => {
const customReplacer = [
Expand All @@ -117,7 +117,7 @@ describe('template', () => {
customReplacer,
)

expect(output).toEqual(
expect(output).toBe(
'This is my body [https://issues.jenkins-ci.org/browse/JENKINS-1234](JENKINS-1234) [https://issues.jenkins-ci.org/browse/JENKINS-456](JENKINS-456)',
)
})
Expand Down
98 changes: 56 additions & 42 deletions packages/core/tests/versions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,58 @@ import { describe, it, expect } from '@jest/globals'

import { getVersionInfo, defaultVersionInfo } from '../src/versions.js'
import { ReleaseType } from 'semver'
import { VersionInfo } from '../src/types.js'

function expected(
versionInfo: VersionInfo,
major = '11.0.0',
minor = '10.1.0',
patch = '10.0.4',
) {
expect(versionInfo.$NEXT_MAJOR_VERSION?.version).toEqual(major)
expect(versionInfo.$NEXT_MAJOR_VERSION?.template).toEqual(
'$MAJOR.$MINOR.$PATCH',
)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR?.version).toEqual(major)
expect(versionInfo.$NEXT_MAJOR_VERSION_MAJOR?.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR?.version).toEqual(major)
expect(versionInfo.$NEXT_MAJOR_VERSION_MINOR?.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_MAJOR_VERSION_PATCH?.version).toEqual(major)
expect(versionInfo.$NEXT_MAJOR_VERSION_PATCH?.template).toEqual('$PATCH')
expect(versionInfo.$NEXT_MINOR_VERSION?.version).toEqual(minor)
expect(versionInfo.$NEXT_MINOR_VERSION?.template).toEqual(
'$MAJOR.$MINOR.$PATCH',
)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR?.version).toEqual(minor)
expect(versionInfo.$NEXT_MINOR_VERSION_MAJOR?.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR?.version).toEqual(minor)
expect(versionInfo.$NEXT_MINOR_VERSION_MINOR?.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_MINOR_VERSION_PATCH?.version).toEqual(minor)
expect(versionInfo.$NEXT_MINOR_VERSION_PATCH?.template).toEqual('$PATCH')
expect(versionInfo.$NEXT_PATCH_VERSION?.version).toEqual(patch)
expect(versionInfo.$NEXT_PATCH_VERSION?.template).toEqual(
'$MAJOR.$MINOR.$PATCH',
)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR?.version).toEqual(patch)
expect(versionInfo.$NEXT_PATCH_VERSION_MAJOR?.template).toEqual('$MAJOR')
expect(versionInfo.$NEXT_PATCH_VERSION_MINOR?.version).toEqual(patch)
expect(versionInfo.$NEXT_PATCH_VERSION_MINOR?.template).toEqual('$MINOR')
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH?.version).toEqual(patch)
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH?.template).toEqual('$PATCH')

function expected(major = '11.0.0', minor = '10.1.0', patch = '10.0.4') {
return {
$NEXT_MAJOR_VERSION: {
version: major,
template: '$MAJOR.$MINOR.$PATCH',
},
$NEXT_MAJOR_VERSION_MAJOR: {
version: major,
template: '$MAJOR',
},
$NEXT_MAJOR_VERSION_MINOR: {
version: major,
template: '$MINOR',
},
$NEXT_MAJOR_VERSION_PATCH: {
version: major,
template: '$PATCH',
},
$NEXT_MINOR_VERSION: {
version: minor,
template: '$MAJOR.$MINOR.$PATCH',
},
$NEXT_MINOR_VERSION_MAJOR: {
version: minor,
template: '$MAJOR',
},
$NEXT_MINOR_VERSION_MINOR: {
version: minor,
template: '$MINOR',
},
$NEXT_MINOR_VERSION_PATCH: {
version: minor,
template: '$PATCH',
},
$NEXT_PATCH_VERSION: {
version: patch,
template: '$MAJOR.$MINOR.$PATCH',
},
$NEXT_PATCH_VERSION_MAJOR: {
version: patch,
template: '$MAJOR',
},
$NEXT_PATCH_VERSION_MINOR: {
version: patch,
template: '$MINOR',
},
$NEXT_PATCH_VERSION_PATCH: {
version: patch,
template: '$PATCH',
},
}
}

describe('versions', () => {
Expand All @@ -58,7 +72,7 @@ describe('versions', () => {
'$MAJOR.$MINOR.$PATCH',
)

expected(versionInfo)
expect(versionInfo).toMatchObject(expected())
})

it('extracts a version-like string from the last release name if the tag isnt a version', () => {
Expand All @@ -74,7 +88,7 @@ describe('versions', () => {
'$MAJOR.$MINOR.$PATCH',
)

expected(versionInfo)
expect(versionInfo).toMatchObject(expected())
})

it('preferences tags over release names', () => {
Expand All @@ -90,7 +104,7 @@ describe('versions', () => {
'$MAJOR.$MINOR.$PATCH',
)

expected(versionInfo)
expect(versionInfo).toMatchObject(expected())
})

it('handles alpha/beta releases', () => {
Expand All @@ -107,7 +121,7 @@ describe('versions', () => {
'v10.0.4-alpha',
)

expected(versionInfo, undefined, undefined, '10.0.3')
expect(versionInfo).toMatchObject(expected(undefined, undefined, '10.0.3'))
})

it('handles stripping of the tag_name', () => {
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 95eec5c

Please sign in to comment.