Skip to content

Commit

Permalink
chore: move to bun (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Jun 21, 2024
1 parent 564d818 commit ff35d29
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 84 deletions.
32 changes: 7 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
21 changes: 6 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added bun.lockb
Binary file not shown.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions test/map/utils/parseDMS.test.ts
Original file line number Diff line number Diff line change
@@ -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]);
Expand Down
28 changes: 14 additions & 14 deletions test/map/utils/parsePB.test.ts
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
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');
expect(res).toContain('roadmap');
expect(res).toContain(tileTypes[0]);
});

it('enum satellite', ({ expect }) => {
test('enum satellite', () => {
const res = parsePB(['1e1']);

expect(res[0]).toBeTypeOf('string');
expect(res).toContain('satellite');
expect(res).toContain(tileTypes[1]);
});

it('enum empty', ({ expect }) => {
test('enum empty', () => {
const res = parsePB(['1e']);

expect(res[0]).toBeTypeOf('string');
expect(res).toContain('roadmap');
expect(res).toContain(tileTypes[0]);
});

it('enum >1', ({ expect }) => {
test('enum >1', () => {
const res = parsePB(['1e2']);

expect(res[0]).toBeTypeOf('string');
expect(res).toContain('roadmap');
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('!')
Expand Down
20 changes: 10 additions & 10 deletions test/map/utils/read.test.ts
Original file line number Diff line number Diff line change
@@ -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' }];
Expand All @@ -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'
);
Expand All @@ -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'
);
Expand All @@ -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'
);
Expand All @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions test/map/utils/zoom.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"declaration": false
"declaration": false,
"types": ["bun-types"]
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit ff35d29

Please sign in to comment.