Skip to content

Commit

Permalink
Fix lint, build
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-matt-hillsdon committed Apr 16, 2024
1 parent f6250f3 commit 89531b7
Show file tree
Hide file tree
Showing 8 changed files with 3,481 additions and 74 deletions.
5 changes: 3 additions & 2 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ rules:
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'off',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
'@typescript-eslint/unbound-method': 'error',
'prefer-template': 'off'
}
76 changes: 36 additions & 40 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import assert from 'node:assert'
import { contextFromEnvironment, generateVersion } from '../src/version'

describe(`generateVersion`, () => {
Expand All @@ -15,7 +14,7 @@ describe(`generateVersion`, () => {
...defaultContext,
ci: false
}
assert.deepEqual(generateVersion('1.2.3-foo', context), {
expect(generateVersion('1.2.3-foo', context)).toEqual({
version: '1.2.3-local'
})
})
Expand All @@ -25,7 +24,7 @@ describe(`generateVersion`, () => {
...defaultContext,
tag: '3.2.1'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '3.2.1'
})
})
Expand All @@ -35,7 +34,7 @@ describe(`generateVersion`, () => {
...defaultContext,
tag: 'v3.2.1'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '3.2.1'
})
})
Expand All @@ -45,7 +44,7 @@ describe(`generateVersion`, () => {
...defaultContext,
tag: 'v1.1.1'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.1.1'
})
})
Expand All @@ -55,7 +54,7 @@ describe(`generateVersion`, () => {
...defaultContext,
tag: 'wibble'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
error: 'Invalid semver tag: wibble'
})
})
Expand All @@ -65,7 +64,7 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: 'wobble'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-wobble.34'
})
})
Expand All @@ -77,14 +76,14 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: usesDev
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-dev.34'
})
})
}

it(`should error if no branch or tag`, () => {
assert.deepEqual(generateVersion('1.0.0-local', defaultContext), {
expect(generateVersion('1.0.0-local', defaultContext)).toEqual({
error: 'Could not determine a version. CI environment invalid?'
})
})
Expand All @@ -94,7 +93,7 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: 'feature/£-foo-bar\\blort-1234.99'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-feature.foo.bar.blort.1234.99.34'
})
})
Expand All @@ -104,7 +103,7 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: 'feature/my-fave-feature'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-feature.my.fave.feature.34'
})
})
Expand All @@ -114,7 +113,7 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: 'foo_bar'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-foo.bar.34'
})
})
Expand All @@ -124,59 +123,56 @@ describe(`generateVersion`, () => {
...defaultContext,
branch: '---'
}
assert.deepEqual(generateVersion('1.0.0-local', context), {
expect(generateVersion('1.0.0-local', context)).toEqual({
version: '1.0.0-branch.34'
})
})
})

describe('contextFromEnvironment', () => {
it('works for GitHub actions branch case', () => {
assert.deepEqual(
expect(
contextFromEnvironment({
GITHUB_ACTION: 'lala',
CI: 'true',
GITHUB_REF: 'refs/heads/asdf',
GITHUB_RUN_NUMBER: '12'
}),
{
branch: 'asdf',
buildNumber: 12,
ci: true,
tag: undefined
}
)
})
).toEqual({
branch: 'asdf',
buildNumber: 12,
ci: true,
tag: undefined
})
})
it('works for GitHub actions tag case', () => {
assert.deepEqual(
expect(
contextFromEnvironment({
GITHUB_ACTION: 'lala',
CI: 'true',
GITHUB_REF: 'refs/tags/asdf',
GITHUB_RUN_NUMBER: '12'
}),
{
branch: undefined,
buildNumber: 12,
ci: true,
tag: 'asdf'
}
)
})
).toEqual({
branch: undefined,
buildNumber: 12,
ci: true,
tag: 'asdf'
})
})
it('works for GitHub actions tag case numeric', () => {
assert.deepEqual(
expect(
contextFromEnvironment({
GITHUB_ACTION: 'lala',
CI: 'true',
GITHUB_REF: 'refs/tags/v1.1.1',
GITHUB_RUN_NUMBER: '12'
}),
{
branch: undefined,
buildNumber: 12,
ci: true,
tag: 'v1.1.1'
}
)
})
).toEqual({
branch: undefined,
buildNumber: 12,
ci: true,
tag: 'v1.1.1'
})
})
})
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 89531b7

Please sign in to comment.