-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
943 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: Tester | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
paths: | ||
- "src/**" | ||
- "test/**" | ||
- "package.json" | ||
- "tsconfig.json" | ||
- ".github/workflows/tester.yml" | ||
pull_request: | ||
paths: | ||
- "src/**" | ||
- "test/**" | ||
- "package.json" | ||
- "tsconfig.json" | ||
- ".github/workflows/tester.yml" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
tester: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: ["18.x"] | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Test | ||
run: npm test | ||
env: | ||
CI: true | ||
coverage: | ||
permissions: | ||
checks: write # for coverallsapp/github-action to create new checks | ||
contents: read # for actions/checkout to fetch code | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
node-version: ["18.x"] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Install Dependencies | ||
run: npm install | ||
- name: Coverage | ||
run: npm run test-cov | ||
env: | ||
CI: true | ||
- name: Coveralls | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import chai from "chai"; | ||
import "./jsdom"; | ||
import evalScript from "../src/evalScript"; | ||
|
||
const should = chai.should(); | ||
|
||
describe("evalScript", () => { | ||
it("test evalScript method", () => { | ||
document.body.className = ""; | ||
const script = document.createElement("script"); | ||
script.innerHTML = "document.body.className = 'executed'"; | ||
|
||
document.body.className.should.equal(""); | ||
evalScript(script); | ||
document.body.className.should.equal("executed"); | ||
|
||
script.innerHTML = "document.write('failure')"; | ||
|
||
const bodyText = "document.write hasn't been executed"; | ||
// @ts-expect-error | ||
document.body.text = bodyText; | ||
evalScript(script); | ||
// @ts-expect-error | ||
document.body.text.should.equal(bodyText); | ||
}); | ||
|
||
it("evalScript should not throw an error if the script removed itself", () => { | ||
const script = document.createElement("script"); | ||
script.id = "myScript"; | ||
script.innerHTML = | ||
"const script = document.querySelector('#myScript');" + | ||
"script.parentNode.removeChild(script);"; | ||
|
||
try { | ||
evalScript(script); | ||
} catch (e) { | ||
should.fail("evalScript should not throw an error if the script removed itself"); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import chai from "chai"; | ||
import "./jsdom"; | ||
import executeScripts from "../src/executeScripts"; | ||
|
||
const should = chai.should(); | ||
|
||
describe("executeScripts", () => { | ||
it("test executeScripts method when the script tag is inside a container", () => { | ||
document.body.className = ""; | ||
|
||
const container = document.createElement("div"); | ||
container.innerHTML = ` | ||
<script>document.body.className = 'executed';</script> | ||
<script>document.body.className += ' correctly';</script>`; | ||
document.body.className.should.equal(""); | ||
executeScripts(container); | ||
document.body.className.should.equal("executed correctly"); | ||
}); | ||
|
||
it("test executeScripts method with just a script tag", () => { | ||
document.body.className = ""; | ||
|
||
const script = document.createElement("script"); | ||
script.innerHTML = "document.body.className = 'executed correctly';"; | ||
document.body.className.should.equal(""); | ||
executeScripts(script); | ||
document.body.className.should.equal("executed correctly"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import chai from "chai"; | ||
import "./jsdom"; | ||
import forEachEls from "../src/forEachEls"; | ||
|
||
const should = chai.should(); | ||
|
||
const div = document.createElement("div"); | ||
const span = document.createElement("span"); | ||
const cb = (el) => { | ||
el.innerHTML = "boom"; | ||
}; | ||
|
||
describe("forEachEls", () => { | ||
it("test forEachEls on one element", () => { | ||
div.innerHTML = "div tag"; | ||
forEachEls(div, cb); | ||
div.innerHTML.should.equal("boom"); | ||
}); | ||
|
||
it("test forEachEls on an array", () => { | ||
div.innerHTML = "div tag"; | ||
span.innerHTML = "span tag"; | ||
|
||
forEachEls([div, span], cb); | ||
div.innerHTML.should.equal("boom"); | ||
span.innerHTML.should.equal("boom"); | ||
}); | ||
|
||
it("test forEachEls on a NodeList", () => { | ||
div.innerHTML = "div tag"; | ||
span.innerHTML = "span tag"; | ||
|
||
const frag = document.createDocumentFragment(); | ||
frag.appendChild(div); | ||
frag.appendChild(span); | ||
forEachEls(frag.childNodes, cb); | ||
div.innerHTML.should.equal("boom"); | ||
span.innerHTML.should.equal("boom"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import chai from "chai"; | ||
import "./jsdom"; | ||
import forEachSelectors from "../src/forEachSelectors"; | ||
|
||
const should = chai.should(); | ||
|
||
const cb = (el) =>{ | ||
el.className = "modified"; | ||
}; | ||
|
||
describe("forEachSelectors", () => { | ||
it("test forEachSelector", () => { | ||
forEachSelectors(["html", "body"], cb); | ||
document.documentElement.className.should.equal("modified"); | ||
document.body.className.should.equal("modified"); | ||
|
||
document.documentElement.className = ""; | ||
document.body.className = ""; | ||
|
||
forEachSelectors(["html", "body"], cb, null, document.documentElement); | ||
|
||
document.documentElement.className.should.equal(""); | ||
document.body.className.should.equal("modified"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import jsdom from "jsdom"; | ||
|
||
const { JSDOM } = jsdom; | ||
|
||
const dom = new JSDOM("", { | ||
url: "https://example.org/", | ||
runScripts: "dangerously", | ||
}); | ||
|
||
// @ts-ignore | ||
globalThis.window = dom.window; | ||
globalThis.document = dom.window.document; | ||
globalThis.navigator = dom.window.navigator; | ||
globalThis.location = dom.window.location; | ||
globalThis.Element = dom.window.Element; | ||
globalThis.HTMLElement = dom.window.HTMLElement; | ||
globalThis.HTMLScriptElement = dom.window.HTMLScriptElement; | ||
globalThis.HTMLHeadElement = dom.window.HTMLHeadElement; | ||
globalThis.HTMLBodyElement = dom.window.HTMLBodyElement; | ||
globalThis.Node = dom.window.Node; | ||
globalThis.HTMLCollection = dom.window.HTMLCollection; | ||
globalThis.NodeList = dom.window.NodeList; | ||
globalThis.XMLHttpRequest = dom.window.XMLHttpRequest; | ||
globalThis.CustomEvent = dom.window.CustomEvent; | ||
globalThis.Event = dom.window.Event; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import chai from "chai"; | ||
import newUid from "../src/newUid"; | ||
|
||
const should = chai.should(); | ||
|
||
describe("newUid", () => { | ||
it("test uniqueid", () => { | ||
const a = newUid(); | ||
const b = newUid(); | ||
a.should.not.equal(b); | ||
}); | ||
}); |
Oops, something went wrong.