diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9c5626c..26eb700 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,23 +19,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - - name: Load cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install - run: npm ci + run: bun install --frozen-lockfile - name: Lint - run: npm run format + run: bun lint test: name: Test @@ -44,19 +35,10 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - - name: Load cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- + - uses: oven-sh/setup-bun@v1 - name: Install - run: npm ci + run: bun install --frozen-lockfile - name: Test - run: npm run test:cov + run: bun test --coverage diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8a76001..c56d029 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,27 +15,18 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - - - name: Load cache - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node- + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v1 - name: Install - run: npm ci + run: bun install --frozen-lockfile - name: Build extension - run: npm run build + run: bun run build - name: Bundle extension - run: npm run bundle - + run: bun run bundle + - name: Bundle source run: git archive --format=zip ${{ github.event.release.tag_name }} --output out/replace_maps_source.zip diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..457a13c Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json index b8802be..22d55e2 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,8 @@ }, "scripts": { "icons": "inkscape -w 48 -h 48 icons/icon.svg -o public/icons/48.png && inkscape -w 48 -h 48 icons/icon-grey.svg -o public/icons/48-grey.png && inkscape -w 96 -h 96 icons/icon.svg -o public/icons/96.png && inkscape -w 96 -h 96 icons/icon-grey.svg -o public/icons/96-grey.png", - "format": "prettier . --check", - "format:fix": "npm run format -- --write", - "test": "vitest run", - "test:watch": "vitest", - "test:cov": "vitest run --coverage", + "lint": "prettier . --check", + "lint:fix": "npm run format -- --write", "dev": "run-p -rl vite:watch serve:firefox", "vite:site": "vite", "vite:watch": "vite build --watch --mode development --minify false", @@ -31,21 +28,24 @@ "release": "release-it" }, "devDependencies": { + "@types/bun": "latest", "@types/leaflet": "^1.9.12", "@types/leaflet-fullscreen": "^1.0.9", "@types/webextension-polyfill": "^0.10.7", "@vitest/coverage-v8": "^1.6.0", + "bun-types": "^1.1.15", "npm-run-all": "^4.1.5", "prettier": "^3.3.2", "release-it": "^17.4.0", "release-it-changelogen": "^0.1.0", - "typescript": "^5.5.2", "vite": "^5.3.1", "vite-plugin-static-copy": "^1.0.5", - "vitest": "^1.6.0", "web-ext": "^8.2.0", "webextension-polyfill": "^0.12.0" }, + "peerDependencies": { + "typescript": "^5.0.0" + }, "dependencies": { "leaflet": "^1.9.4", "leaflet-fullscreen": "^1.0.2" @@ -72,9 +72,9 @@ }, "hooks": { "before:init": [ - "npm run format", - "npm test", - "npm run build" + "bun lint", + "bun test", + "bun run build" ], "after:bump": [ "sh scripts/bump.sh" diff --git a/test/map/utils/parseDMS.test.ts b/test/map/utils/parseDMS.test.ts index 89ac518..656ba64 100644 --- a/test/map/utils/parseDMS.test.ts +++ b/test/map/utils/parseDMS.test.ts @@ -1,14 +1,14 @@ -import { describe, it } from 'vitest'; +import { describe, test, expect } from 'bun:test'; import { parseDMS } from '../../../src/map/utils/parseDMS'; -describe.concurrent('Parse Degrees Minutes Seconds Direction', () => { - it('Example', ({ expect }) => { +describe('Parse Degrees Minutes Seconds Direction', () => { + test('Example', () => { const res = parseDMS(`10°60'36.0"N 10°60'36.0"E`); expect(res).toStrictEqual([11.01, 11.01]); }); - it('Negative Example', ({ expect }) => { + test('Negative Example', () => { const res = parseDMS(`10°60'36.0"S 10°60'36.0"W`); expect(res).toStrictEqual([-11.01, -11.01]); diff --git a/test/map/utils/parsePB.test.ts b/test/map/utils/parsePB.test.ts index ded3af9..c3f9a69 100644 --- a/test/map/utils/parsePB.test.ts +++ b/test/map/utils/parsePB.test.ts @@ -1,42 +1,42 @@ -import { describe, it } from 'vitest'; +import { describe, test, expect } from 'bun:test'; import { parsePB, tileTypes } from '../../../src/map/utils/parsePB'; -describe.concurrent('Parse PB', () => { - it('empty list', ({ expect }) => { +describe('Parse PB', () => { + test('empty list', () => { const res = parsePB([]); expect(res).empty; expect(res).toEqual([]); }); - it('contains empty list', ({ expect }) => { + test('contains empty list', () => { const res = parsePB(['1m0']); expect(res).toStrictEqual([[]]); }); - it('double', ({ expect }) => { + test('double', () => { const res = parsePB(['1d1.1']); expect(res[0]).toBeTypeOf('number'); expect(res).toContain(1.1); }); - it('float', ({ expect }) => { + test('float', () => { const res = parsePB(['1f1.1']); expect(res[0]).toBeTypeOf('number'); expect(res).toContain(1.1); }); - it('int', ({ expect }) => { + test('int', () => { const res = parsePB(['1i1']); expect(res[0]).toBeTypeOf('number'); expect(res).toContain(1); }); - it('enum roadmap', ({ expect }) => { + test('enum roadmap', () => { const res = parsePB(['1e0'])[0]; expect(res[0]).toBeTypeOf('string'); @@ -44,7 +44,7 @@ describe.concurrent('Parse PB', () => { expect(res).toContain(tileTypes[0]); }); - it('enum satellite', ({ expect }) => { + test('enum satellite', () => { const res = parsePB(['1e1']); expect(res[0]).toBeTypeOf('string'); @@ -52,7 +52,7 @@ describe.concurrent('Parse PB', () => { expect(res).toContain(tileTypes[1]); }); - it('enum empty', ({ expect }) => { + test('enum empty', () => { const res = parsePB(['1e']); expect(res[0]).toBeTypeOf('string'); @@ -60,7 +60,7 @@ describe.concurrent('Parse PB', () => { expect(res).toContain(tileTypes[0]); }); - it('enum >1', ({ expect }) => { + test('enum >1', () => { const res = parsePB(['1e2']); expect(res[0]).toBeTypeOf('string'); @@ -68,20 +68,20 @@ describe.concurrent('Parse PB', () => { expect(res).toContain(tileTypes[0]); }); - it('wrongly encoded base64', ({ expect }) => { + test('wrongly encoded base64', () => { expect(() => parsePB(['1zM'])).toThrowError( 'The string to be decoded is not correctly encoded.' ); }); - it('base64 encoded coordinates', ({ expect }) => { + test('base64 encoded coordinates', () => { const res = parsePB(['1zMTHCsDExJzExLjEiTiAxMcKwMTEnMTEuMSJF'])[0]; expect(res).toBeTypeOf('string'); expect(res).toBe(`11°11'11.1"N 11°11'11.1"E`); }); - it('"real" world example', ({ expect }) => { + test('"real" world example', () => { const splitted = '!1m14!1m12!1m3!1d1.1!2d1.1!3d1.1!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sde!2sde!4v1680097499131!5m2!1sde!2sde' .split('!') diff --git a/test/map/utils/read.test.ts b/test/map/utils/read.test.ts index a351e6b..728afcc 100644 --- a/test/map/utils/read.test.ts +++ b/test/map/utils/read.test.ts @@ -1,7 +1,7 @@ -import { describe, it, vi } from 'vitest'; +import { describe, test, expect, jest } from 'bun:test'; import { readPB, readQ, nominatimQ } from '../../../src/map/utils/read'; -global.fetch = vi.fn(); +global.fetch = jest.fn(); const input = 'test position'; const result = [{ lat: '1.1', lon: '1.1' }]; @@ -10,8 +10,8 @@ function mockNominatimResponse(data: { lat: string; lon: string }[], status: boo return { ok: status, json: () => new Promise((resolve) => resolve(data)) }; } -describe.concurrent('read pb', () => { - it('read example', async ({ expect }) => { +describe('read pb', () => { + test('read example', async () => { const res = await readPB( '!1m14!1m12!1m3!1d1.1!2d1.1!3d1.1!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!5e0!3m2!1sde!2sde!4v1680097499131!5m2!1sde!2sde' ); @@ -27,7 +27,7 @@ describe.concurrent('read pb', () => { }); }); - it('pb base64 marker', async ({ expect }) => { + test('pb base64 marker', async () => { const res = await readPB( '!1m17!1m12!1m3!1d1.1!2d1.1!3d1.1!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m2!1m1!1zMTDCsDYwJzM2LjAiTiAxMMKwNjAnMzYuMCJF!5e0!3m2!1sde!2sde!4v1557583694739!5m2!1sde!2sde' ); @@ -49,7 +49,7 @@ describe.concurrent('read pb', () => { }); }); - it('pb id marker', async ({ expect }) => { + test('pb id marker', async () => { const res = await readPB( '!1m17!1m12!1m3!1d1.1!2d1.1!3d1.1!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m2!1m1!1s0x0:0x0!5e0!3m2!1sde!2sde!4v1557583694739!5m2!1sde!2sde' ); @@ -65,7 +65,7 @@ describe.concurrent('read pb', () => { }); }); - it('pb markers to readQ', async ({ expect }) => { + test('pb markers to readQ', async () => { // @ts-ignore fetch.mockResolvedValue(mockNominatimResponse(result, true)); @@ -91,8 +91,8 @@ describe.concurrent('read pb', () => { }); }); -describe.concurrent('read query', () => { - it('nominatim request', async ({ expect }) => { +describe('read query', () => { + test('nominatim request', async () => { // @ts-ignore fetch.mockResolvedValue(mockNominatimResponse(result, true)); @@ -107,7 +107,7 @@ describe.concurrent('read query', () => { }); }); - it('failing nominatim request', async ({ expect }) => { + test('failing nominatim request', async () => { // @ts-ignore-next fetch.mockResolvedValue(mockNominatimResponse(result, false)); diff --git a/test/map/utils/zoom.test.ts b/test/map/utils/zoom.test.ts index 58b7fbe..2b4afdc 100644 --- a/test/map/utils/zoom.test.ts +++ b/test/map/utils/zoom.test.ts @@ -1,22 +1,22 @@ -import { describe, it } from 'vitest'; +import { describe, test, expect } from 'bun:test'; import { getMapZoom } from '../../../src/map/utils/zoom'; -describe.concurrent('', () => { - it('zoom > 19', ({ expect }) => { +describe('Zoom levels', () => { + test('zoom > 19', () => { const res = getMapZoom(1); expect(res).toBeTypeOf('number'); expect(res).toBe(19); }); - it('zoom < 0', ({ expect }) => { + test('zoom < 0', () => { const res = getMapZoom(100000000); expect(res).toBeTypeOf('number'); expect(res).toBe(0); }); - it('specific zoom', ({ expect }) => { + test('specific zoom', () => { const res = getMapZoom(1000); expect(res).toBe(18.5); diff --git a/tsconfig.json b/tsconfig.json index 5df485c..4d452ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,7 +18,8 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "declaration": false + "declaration": false, + "types": ["bun-types"] }, "include": ["src"], "exclude": ["node_modules"]