Skip to content

Commit 7b2ea85

Browse files
committed
Initial
1 parent 223e42b commit 7b2ea85

18 files changed

+675
-0
lines changed

.changepacks/config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ignore": [],
3+
"baseBranch": "main",
4+
"latestPackage": null,
5+
"publish": {},
6+
"updateOn": {}
7+
}

.github/workflows/check-pr.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check Pull Request
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
jobs:
7+
check:
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- uses: oven-sh/setup-bun@v2
16+
- run: bun i
17+
- run: |
18+
bun lint
19+
bun test
20+
bun run build

.github/workflows/publish.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Publish Package to npm
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: false
14+
permissions:
15+
# create pull request comments
16+
pull-requests: write
17+
18+
# Actions > General > Workflow permissions for creating pull request
19+
# Create brench to create pull request
20+
contents: write
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
- uses: oven-sh/setup-bun@v2
25+
- run: bun i
26+
- run: |
27+
bun lint
28+
bun test
29+
bun run build
30+
- uses: changepacks/action@main
31+
id: changepacks
32+
with:
33+
publish: true
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store
35+
36+
.claude

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bun test
2+
bun lint

biome.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"enabled": true,
5+
"clientKind": "git",
6+
"useIgnoreFile": true
7+
},
8+
"files": {
9+
"includes": ["**", "!**/dist"]
10+
},
11+
"javascript": {
12+
"formatter": {
13+
"semicolons": "asNeeded",
14+
"quoteStyle": "single",
15+
"indentStyle": "space",
16+
"indentWidth": 2
17+
}
18+
},
19+
"json": {
20+
"formatter": {
21+
"indentStyle": "space",
22+
"indentWidth": 2
23+
}
24+
},
25+
"overrides": [
26+
{
27+
"includes": ["**/__tests__/**", "**/*.test.ts", "**/*.test.tsx"],
28+
"linter": {
29+
"rules": {
30+
"suspicious": {
31+
"noExplicitAny": "off"
32+
}
33+
}
34+
}
35+
}
36+
]
37+
}

bun.lock

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bunfig.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[test]
2+
preload = ["./src/index.ts"]
3+
coverage = true
4+
coverageSkipTestFiles = true
5+
coverageThreshold = 1.0
6+
coverageReporter = ["text", "lcov"]

package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "bun-test-env-dom",
3+
"type": "module",
4+
"version": "0.0.1",
5+
"description": "bun-test-env-dom is a preload library that provides a ready-to-use DOM for testing",
6+
"author": "JeongMin Oh",
7+
"license": "Apache-2.0",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/dev-five-git/bun-test-env-dom"
11+
},
12+
"main": "dist/index.cjs",
13+
"exports": {
14+
".": {
15+
"import": {
16+
"types": "./dist/index.d.ts",
17+
"default": "./dist/index.mjs"
18+
},
19+
"require": {
20+
"types": "./dist/index.d.ts",
21+
"default": "./dist/index.cjs"
22+
}
23+
}
24+
},
25+
"types": "./dist/index.d.ts",
26+
"files": [
27+
"dist"
28+
],
29+
"keywords": [
30+
"bun",
31+
"test",
32+
"dom"
33+
],
34+
"devDependencies": {
35+
"@biomejs/biome": "^2.3",
36+
"@types/bun": "latest",
37+
"@types/react": "^19.2.7",
38+
"husky": "^9.1.7",
39+
"typescript": "latest"
40+
},
41+
"dependencies": {
42+
"@happy-dom/global-registrator": ">=20.0",
43+
"@testing-library/dom": ">=10.4",
44+
"@testing-library/jest-dom": ">=6.9",
45+
"@testing-library/react": ">=16.3",
46+
"@testing-library/user-event": ">=14.6"
47+
},
48+
"scripts": {
49+
"lint:fix": "biome check --write .",
50+
"lint": "biome check .",
51+
"test": "bun test",
52+
"build": "tsc && bun build --target node src/index.ts --production --outfile dist/index.cjs --format cjs --packages external && bun build --target node src/index.ts --production --outfile dist/index.mjs --format esm --packages external",
53+
"prepare": "bun run husky"
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, test } from 'bun:test'
2+
import { formatHTMLElement } from '../formatHTMLElement.ts'
3+
4+
describe('formatHTMLElement', () => {
5+
test('should format a simple div element', () => {
6+
const div = document.createElement('div')
7+
div.textContent = 'Hello'
8+
const result = formatHTMLElement(div)
9+
expect(result).toBe(`<div>
10+
Hello
11+
</div>`)
12+
})
13+
14+
test('should format nested elements', () => {
15+
const div = document.createElement('div')
16+
const p = document.createElement('p')
17+
p.textContent = 'Paragraph'
18+
div.appendChild(p)
19+
const result = formatHTMLElement(div)
20+
expect(result).toBe(`<div>
21+
<p>
22+
Paragraph
23+
</p>
24+
</div>`)
25+
})
26+
27+
test('should format element with attributes', () => {
28+
const div = document.createElement('div')
29+
div.className = 'container'
30+
div.id = 'main'
31+
const result = formatHTMLElement(div)
32+
expect(result).toBe(`<div class="container" id="main">
33+
</div>`)
34+
})
35+
36+
test('should format element with multiple children', () => {
37+
const ul = document.createElement('ul')
38+
const li1 = document.createElement('li')
39+
li1.textContent = 'Item 1'
40+
const li2 = document.createElement('li')
41+
li2.textContent = 'Item 2'
42+
ul.appendChild(li1)
43+
ul.appendChild(li2)
44+
const result = formatHTMLElement(ul)
45+
expect(result).toBe(`<ul>
46+
<li>
47+
Item 1
48+
</li>
49+
<li>
50+
Item 2
51+
</li>
52+
</ul>`)
53+
})
54+
})

0 commit comments

Comments
 (0)