Skip to content

Commit

Permalink
feat: use bun for tests and bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
believer committed Sep 12, 2023
1 parent b5e24dd commit 9be493f
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 16,148 deletions.
82 changes: 24 additions & 58 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,92 +7,58 @@ on:

permissions: write-all

# Cancel previously running workflows
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
install:
name: Install dependencies
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install

test:
name: Tests
runs-on: ubuntu-latest
needs: [install]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests
run: npm test
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun test

lint:
name: Lint
runs-on: ubuntu-latest
needs: [install]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run linting
run: npm run lint
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun lint

typecheck:
name: TypeScript
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Type check
run: npm run typecheck
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun typecheck

release:
runs-on: ubuntu-latest
needs: [test, lint, typecheck]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Build project
run: npm run build
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun build:js

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
Expand Down
1 change: 0 additions & 1 deletion .prettierignore

This file was deleted.

Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import telefonnummer, {
areaCode,
areEqual,
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/numberingArea.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { numberingArea } from '../numberingArea'

test('returns empty string if nothing is found', () => {
Expand Down
10 changes: 1 addition & 9 deletions lib/__tests__/parser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { phoneNumberParser } from '../parser'

const parserHelper = (numbers: string[], expected: string): void => {
Expand All @@ -7,10 +7,6 @@ const parserHelper = (numbers: string[], expected: string): void => {
})
}

test('handles null values', () => {
parserHelper([null, undefined], '')
})

test('parses voicemail', () => {
const numbers = [
'46888',
Expand All @@ -26,10 +22,6 @@ test('parses voicemail', () => {
parserHelper(numbers, 'Röstbrevlåda')
})

test('handles non strings', () => {
expect(phoneNumberParser(46721834008)).toEqual('072-183 40 08')
})

test('parses normal mobile numbers', () => {
expect(phoneNumberParser('46721834008')).toEqual('072-183 40 08')
expect(phoneNumberParser('0721834008')).toEqual('072-183 40 08')
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/riktnummer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, test } from 'vitest'
import { describe, expect, test } from 'bun:test'
import * as riktnummer from '../riktnummer'

describe('#findMatchingAreaCode', () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/validator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { validator } from '../validator'

test.each([
['070-abc de fg'],
['0701ggas234asdf567d'],
['070abcdefb'],
['abcdefg'],
])('errors for non-numerical inputs', (phoneNumber) => {
])('errors for non-numerical input %s', (phoneNumber) => {
expect(validator(phoneNumber)).toBe(false)
})

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/__tests__/areaCodeDigitCount.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { areaCodeDigitCount } from '../areaCodeDigitCount'

const numberHelper = (numbers: string[], expected: number): void => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/__tests__/comparePhoneNumbers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { phoneNumbersAreEqual } from '../comparePhoneNumbers'

test('returns true if phone numbers are equal', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/__tests__/makeRegex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { makeRegex } from '../makeRegex'

test('handles undefined type (long implicitly)', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/__tests__/normalize.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { normalize } from '../normalize'

test('should handle numbers with +46', () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/__tests__/numberReplace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, test } from 'vitest'
import { expect, test } from 'bun:test'
import { numberReplace } from '../numberReplace'

test('handles undefined type (long implicitly)', () => {
Expand Down
Loading

0 comments on commit 9be493f

Please sign in to comment.