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

Drop old node versions #207

Merged
merged 5 commits into from
Jun 24, 2024
Merged
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
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"root": true,
"extends": [
"exp/all"
"@bonniernews/eslint-config/all"
],
"rules": {
"no-setter-return": 0
"no-setter-return": 0,
"@bonniernews/typescript-rules/disallow-class-extends": 0
}
}
23 changes: 0 additions & 23 deletions .github/workflows/build-latest.yaml

This file was deleted.

18 changes: 10 additions & 8 deletions .github/workflows/build-pr.yaml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
name: Built pull request
name: CI

on:
pull_request:
branches: [ master ]
push:
branches: [ master ]

jobs:
build:

test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]

node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: npm i

- run: npm test
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

## 16.0.0

- Breaking: Drop support for node <18
- Bugfix: Assertion message on failed fetches now include error code and fetch uri

## 15.5.0

- Bugfix for custom elements where modifications to child elements in connectedCallback would trigger a new instance of the custom element being created and that ones connectedCallback being invoked
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Tallahassee

![Utilities](https://raw.github.com/ExpressenAB/tallahassee/master/app/assets/images/tallahassee-1.png)

[![Built latest](https://github.com/ExpressenAB/tallahassee/actions/workflows/build-latest.yaml/badge.svg)](https://github.com/ExpressenAB/tallahassee/actions/workflows/build-latest.yaml)
[![Built latest](https://github.com/ExpressenAB/tallahassee/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/ExpressenAB/tallahassee/actions/workflows/ci.yml)

Test your client scripts in a headless browser.

Expand Down
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- version -->
# 15.4.0 API Reference
# 16.0.0 API Reference
<!-- versionstop -->

<!-- toc -->
Expand Down
2 changes: 0 additions & 2 deletions lib/CustomElementRegistry.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

const DOMException = require("domexception");

const kWindow = Symbol.for("window");
const kElementFactory = Symbol.for("element factory");

Expand Down
24 changes: 8 additions & 16 deletions lib/Element.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use strict";

const DOMException = require("domexception");
const vm = require("vm");

const { DOCUMENT_FRAGMENT_NODE, TEXT_NODE } = require("./nodeTypes.js");
const { DOCUMENT_FRAGMENT_NODE } = require("./nodeTypes.js");
const { Event } = require("./Events.js");
const { getElementsByClassName, getElementsByTagName } = require("./getElements.js");
const Attr = require("./Attr.js");
Expand Down Expand Up @@ -366,21 +365,14 @@ module.exports = class Element extends Node {
this.$elm.remove();
parentElement?._emitter.emit("_insert");
}
replaceChild(newChild, oldChild) {
if (!newChild) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.");
}
if (!oldChild) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.");
}
if (this.$elm[0].children.indexOf(oldChild.$elm[0]) === -1) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.");
}

oldChild.$elm.replaceWith(newChild.nodeType === TEXT_NODE ? newChild.textContent : newChild.outerHTML);
replaceChildren(newChildren) {
this.$elm.contents().remove();

this._emitter.emit("_insert");
return oldChild;
if (newChildren !== undefined) {
this.appendChild(newChildren);
} else {
this._emitter.emit("_insert");
}
}
removeAttribute(name) {
if (!this.hasAttribute(name)) return;
Expand Down
1 change: 0 additions & 1 deletion lib/HTMLDialogElement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";

const DOMException = require("domexception");
const { Event } = require("./Events.js");
const HTMLElement = require("./HTMLElement.js");

Expand Down
19 changes: 15 additions & 4 deletions lib/Node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

const DOMException = require("domexception");

const nodeTypes = require("./nodeTypes.js");
const NodeList = require("./NodeList.js");
const EventTarget = require("./EventTarget.js");
Expand Down Expand Up @@ -144,8 +142,21 @@ module.exports = class Node extends EventTarget {
this._emitter.emit("_insert");
return child;
}
replaceChild() {
throw new Error("Not implemented");
replaceChild(newChild, oldChild) {
if (!newChild) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.");
}
if (!oldChild) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.");
}
if (this.$elm[0].children.indexOf(oldChild.$elm[0]) === -1) {
throw new DOMException("Failed to execute 'replaceChild' on 'Node': The node to be replaced is not a child of this node.");
}

oldChild.$elm.replaceWith(newChild.nodeType === nodeTypes.TEXT_NODE ? newChild.textContent : newChild.outerHTML);

this._emitter.emit("_insert");
return oldChild;
}
_getElement($ref) {
return this.ownerDocument._getElement(this.ownerDocument.$($ref));
Expand Down
4 changes: 2 additions & 2 deletions lib/WebPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = class WebPage {
method: "GET",
headers: requestHeaders,
});
assert.equal(resp.status, statusCode, `Unexepected status code. Expected: ${statusCode}. Actual: ${resp.statusCode}`);
assert(resp.headers.get("content-type").match(/text\/html/i), `Unexepected content type. Expected: text/html. Actual: ${resp.headers["content-type"]}`);
assert.equal(resp.status, statusCode, `Unexepected status code. Expected: ${statusCode}. Actual: ${resp.status} (GET ${uri})`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assert(resp.headers.get("content-type")?.match(/text\/html/i), `Unexepected content type. Expected: text/html. Actual: ${resp.headers["content-type"]}`);
const browser = new BrowserTab(this, resp);
return browser.load();
}
Expand Down
2 changes: 0 additions & 2 deletions lib/atobtoa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

const DOMException = require("domexception");

module.exports = {
btoa,
atob,
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expressen/tallahassee",
"version": "15.5.0",
"version": "16.0.0",
"description": "Lightweight client testing framework",
"main": "index.js",
"license": "BSD-3-Clause",
Expand All @@ -12,7 +12,7 @@
"toc": "node ./scripts/generate-api-toc ./docs/API.md,./docs/Examples.md"
},
"engines": {
"node": ">=14"
"node": ">=18.18"
},
"keywords": [
"headless",
Expand All @@ -31,18 +31,17 @@
"dependencies": {
"cheerio": "1.0.0-rc.3",
"cookiejar": "^2.1.3",
"domexception": "^4.0.0",
"node-fetch-commonjs": "^3.2.4"
"node-fetch-commonjs": "^3.3.2"
},
"devDependencies": {
"@bonniernews/eslint-config": "^1.2.0",
"@bonniernews/wichita": "^1.1.0",
"chai": "^4.3.7",
"eslint": "^8.34.0",
"eslint-config-exp": "^0.5.0",
"express": "^4.18.2",
"chai": "^4.4.1",
"eslint": "^8.57.0",
"express": "^4.19.2",
"markdown-toc": "^1.2.0",
"mocha": "^10.1.0",
"nock": "^13.2.9"
"mocha": "^10.4.0",
"nock": "^13.5.4"
},
"files": [
"lib/",
Expand Down
1 change: 0 additions & 1 deletion test/HTMLDialogElement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { Document } = require("../lib/index.js");
const { Event } = require("../lib/Events.js");
const DOMException = require("domexception");

describe("HTMLDialogElement", () => {
let document;
Expand Down
2 changes: 0 additions & 2 deletions test/custom-elements-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

const DOMException = require("domexception");

const { app } = require("../app/app.js");
const Browser = require("../index.js");

Expand Down
88 changes: 86 additions & 2 deletions test/elements-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"use strict";

const DOMException = require("domexception");

const DocumentFragment = require("../lib/DocumentFragment.js");
const Element = require("../lib/Element.js");
const HTMLAnchorElement = require("../lib/HTMLAnchorElement.js");
Expand Down Expand Up @@ -514,6 +512,92 @@ describe("elements", () => {
});
});

describe("replaceChild(newChild, oldChild)", () => {
let document;
beforeEach(() => {
document = new Document({
text: `
<html>
<body id="grandparent">
<div id="parent-1">
<span class="child">åäö</span>
</div>
<div id="parent-2"></div>
</body>
</html>`,
});
});

it("removes child element and replaces it with the new one", () => {
const parent = document.getElementById("parent-1");
const child = document.getElementsByClassName("child")[0];

expect(parent.children.length).to.equal(1);

const newChild = document.createElement("p");
newChild.textContent = "I will replace you";
const removed = parent.replaceChild(newChild, child);
expect(parent.children.length).to.equal(1);
expect(parent.textContent.trim()).to.equal("I will replace you");

expect(removed === child).to.be.true;
});

it("replace child text node", () => {
const parent = document.getElementsByClassName("child")[0];
const child = parent.firstChild;
expect(child.nodeType).to.equal(3);

expect(parent.childNodes.length).to.equal(1);

const newChild = document.createElement("p");
newChild.textContent = "I will replace you";
const removed = parent.replaceChild(newChild, child);
expect(parent.childNodes.length).to.equal(1);

expect(removed === child).to.be.true;
});
});

describe("replaceChildren(newChild)", () => {
let document;
beforeEach(() => {
document = new Document({
text: `
<html>
<body id="grandparent">
<div id="parent-1">
<span class="child">åäö</span>
</div>
<div id="parent-2"></div>
</body>
</html>`,
});
});

it("removes all children if no arguments supplied", () => {
const parent = document.getElementById("parent-1");

expect(parent.children.length).to.equal(1);

parent.replaceChildren();
expect(parent.children.length).to.equal(0);
});

it("replaces all children with new child", () => {
const parent = document.getElementById("grandparent");

expect(parent.children.length).to.equal(2);

const newChild = document.createElement("p");
newChild.textContent = "I will replace you";

parent.replaceChildren(newChild);
expect(parent.childNodes.length).to.equal(1);
expect(parent.textContent.trim()).to.equal("I will replace you");
});
});

describe(".style", () => {
let document;
beforeEach(() => {
Expand Down