Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1. cover the code #1

Draft
wants to merge 31 commits into
base: bun
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Bun

on:
push:

jobs:
bun-coverage:
runs-on: ubuntu-latest

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

- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash
echo "${HOME}/.bun/bin" >> $GITHUB_PATH

- name: Install Dependencies
working-directory: typescript-bun
run: bun install --backend copyfile

- name: Start and Seed MySQL Database
run: |
sudo systemctl start mysql
mysql -uroot -proot < database/initDatabase.sql

- name: Run Tests
working-directory: typescript-bun
env:
DB_PASSWORD: root
run: bun test

- name: Check Coverage with Mutation Tests
working-directory: typescript-bun
env:
DB_PASSWORD: root
run: bun stryker run
3 changes: 3 additions & 0 deletions typescript-bun/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
.stryker-tmp
reports
counter.json
14 changes: 13 additions & 1 deletion typescript-bun/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
bun install
```

# Wait for mysql docker

```shell
(timeout 10 docker logs -f mariadb 2>&1 &) | grep -m 1 'ready for connections'
```

# Start the server

```shell
Expand All @@ -19,8 +25,14 @@ with different port (default is 3000)
PORT=3001 bun --hot prices.ts
```

# Run the (failing, e2e) test
# Run the coverage e2e test

```shell
bun test
```

# Mutation Tests

```shell
bun stryker run
```
18 changes: 18 additions & 0 deletions typescript-bun/approvals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { file, write } from "bun";
import { expect } from "bun:test";
import { EOL } from "os";

export const approval = (baseName: string) => {
const things: any[] = [];

const str = () => things.map(String).join(EOL);
const approvedFile = () => file(`${baseName}.approved`);
const approvedText = async () =>
approvedFile().size == 0 ? "" : await approvedFile().text();

const add = (thing: any) => things.push(thing);
const update = () => write(approvedFile(), str());
const verify = async () => expect(str()).toEqual(await approvedText());

return { add, update, verify };
};
Binary file modified typescript-bun/bun.lockb
Binary file not shown.
19 changes: 19 additions & 0 deletions typescript-bun/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { file, write } from "bun";

export const count = async () => {
const f = file("counter.json");

let _count = 0;

if (f.size > 0) {
const { count, updated } = await f.json();

if (Date.now() - 3000 < updated) {
_count = count + 1;
}
}

write(f, JSON.stringify({ count: _count, updated: Date.now() }));

return _count;
};
Loading