Skip to content

Commit

Permalink
[add] Format & Test scripts in Git hooks (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Jul 5, 2024
1 parent 89dace5 commit e0b73ce
Show file tree
Hide file tree
Showing 10 changed files with 1,264 additions and 48 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run build
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
docs/
test/
.husky/
.github/
44 changes: 30 additions & 14 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,27 @@ Any one of these methods shown below is available.
### 1. CDN

```html
<head>
<script src="https://polyfill.web-cell.dev/feature/DeclarativeShadowDOM.js"></script>
</head>
<html>
<head>
<script src="https://polyfill.web-cell.dev/feature/DeclarativeShadowDOM.js"></script>

<script src="./my-tag.js"></script>
<script>
window.onload = () => {
const { shadowRoot } = document.querySelector("my-tag");
console.log(shadowRoot);
};
</script>
</head>
<body>
<my-tag>
<template shadowrootmode="open">
<p>Hello, Declarative Shadow DOM!</p>
</template>
</my-tag>
</body>
</html>
```

### 2. Polyfill import
Expand All @@ -34,16 +52,16 @@ const markup = `
<my-tag>
<template shadowrootmode="open">
<p>Hello, Declarative Shadow DOM!</p>
<template/>
</template>
</my-tag>`;

document.body.setHTMLUnsafe(markup);

console.assert(markup === document.body.getHTML(), "Shadow DOM serialization");
console.log(document.body.getHTML());

const newDocument = Document.parseHTMLUnsafe(markup);

console.assert(markup === newDocument.body.getHTML(), "Shadow DOM parsing");
console.log(newDocument.body.getHTML());
```

### 3. Ponyfill import
Expand All @@ -59,18 +77,16 @@ const markup = `
<my-tag>
<template shadowrootmode="open">
<p>Hello, Declarative Shadow DOM!</p>
<template/>
</template>
</my-tag>`;

setHTMLUnsafe.call(document.body, markup);

console.assert(
markup === getHTML.call(document.body),
"Shadow DOM serialization"
);
console.log(getHTML.call(document.body));

const newDocument = parseHTMLUnsafe(markup);

console.assert(markup === getHTML.call(newDocument.body), "Shadow DOM parsing");
console.log(getHTML.call(newDocument.body));
```

### 4. Node.js & Bun
Expand All @@ -80,9 +96,9 @@ console.assert(markup === getHTML.call(newDocument.body), "Shadow DOM parsing");
Either `jsdom`, `happy-dom` or `linkedom` is available DOM implementation.

```javascript
import { Window } from "happy-dom";
import { JSDOM } from "jsdom";

const window = new Window(),
const { window } = new JSDOM(),
RequiredAPI = [
"Text",
"Comment",
Expand Down
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@
"main": "dist/index.js",
"types": "dist/index.d.ts",
"devDependencies": {
"@types/jsdom": "^21.1.7",
"@types/node": "^18.19.39",
"husky": "^9.0.11",
"jsdom": "^24.1.0",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"tsx": "^4.16.2",
"typedoc": "^0.26.3",
"typedoc-plugin-mdn-links": "^3.2.2",
"typescript": "^5.5.3"
},
"prettier": {
"trailingComma": "none"
},
"lint-staged": {
"*.{md,json,yml,ts}": "prettier --write"
},
"scripts": {
"prepare": "husky",
"test": "lint-staged && tsx test/index.spec.ts",
"build": "rm -rf dist/ docs/ && tsc && typedoc source/",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm test && npm run build"
}
}
Loading

0 comments on commit e0b73ce

Please sign in to comment.