Skip to content

Commit

Permalink
fix: update dependency typings
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed May 14, 2024
1 parent d94c093 commit bf4bc75
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
8 changes: 1 addition & 7 deletions lib/podlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@

import {
HttpIncoming,
// @ts-ignore
pathnameBuilder,
AssetCss,
AssetJs,
} from '@podium/utils';
// @ts-ignore
import * as schema from '@podium/schemas';
import Metrics from '@metrics/client';
// @ts-ignore
import abslog from 'abslog';
// @ts-ignore
import objobj from 'objobj';
import * as utils from '@podium/utils';
// @ts-ignore
import Proxy from '@podium/proxy';
import { join, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand All @@ -31,7 +26,6 @@ const pkgJson = fs.readFileSync(
);
const pkg = JSON.parse(pkgJson);

// @ts-ignore
const { template } = utils;

/**
Expand All @@ -47,7 +41,7 @@ const { template } = utils;
* @property {string} [fallback] - path where the podlet fallback HTML markup is served from (default '/fallback')
* @property {boolean} [development] - a boolean flag that, when true, enables additional development setup (default false)
* @property {Console | AbsLogger} [logger] - a logger to use when provided. Can be the console object if console logging is desired but can also be any Log4j compatible logging object as well. Nothing is logged if no logger is provided. (default null)
* @property {import("@podium/proxy").default.PodiumProxyOptions} [proxy] - options that can be provided to configure the @podium/proxy instance used by the podlet. See that module for details.
* @property {import("@podium/proxy").PodiumProxyOptions} [proxy] - options that can be provided to configure the @podium/proxy instance used by the podlet. See that module for details.
*
* @typedef {{ debug: 'true' | 'false', locale: string, deviceType: string, requestedBy: string, mountOrigin: string, mountPathname: string, publicPathname: string }} PodletContext
* @typedef {{ as?: string | false | null, crossorigin?: string | null | boolean, disabled?: boolean | '' | null, hreflang?: string | false | null, title?: string | false | null, media?: string | false | null, rel?: string | false | null, type?: string | false | null, value: string | false | null, data?: Array<{ key: string; value: string }>, strategy?: "beforeInteractive" | "afterInteractive" | "lazy", scope?: "content" | "fallback" | "all", [key: string]: any }} AssetCssLike
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint --fix .",
"test:snapshots": "tap --snapshot --disable-coverage --allow-empty-coverage && tsc --project tsconfig.test.json",
"test": "tap --disable-coverage --allow-empty-coverage && tsc --project tsconfig.test.json",
"types": "tsc --declaration --emitDeclarationOnly && ./fixup.sh"
},
"dependencies": {
"@metrics/client": "2.5.2",
"@podium/proxy": "5.0.14",
"@podium/schemas": "5.0.1",
"@podium/proxy": "5.0.16",
"@podium/schemas": "5.0.2",
"@podium/utils": "5.0.6",
"abslog": "2.4.4",
"ajv": "8.13.0",
Expand All @@ -48,6 +48,7 @@
"@semantic-release/npm": "11.0.3",
"@semantic-release/release-notes-generator": "12.1.0",
"@types/node": "^20.10.3",
"@types/readable-stream": "4.0.14",
"eslint": "8.57.0",
"eslint-config-airbnb-base": "15.0.0",
"eslint-config-prettier": "9.1.0",
Expand Down
73 changes: 45 additions & 28 deletions tests/podlet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ const SIMPLE_RES = {
*/

class FakeHttpServer {
constructor({ podlet, process } = {}, onRequest) {
/**
* @param {{ podlet: Podlet, process?: { proxy: boolean } }} options
* @param {(incoming: import('@podium/utils').HttpIncoming) => void} [onRequest]
*/
constructor({ podlet, process }, onRequest) {
this.app = http.createServer(async (req, res) => {
const incoming = new HttpIncoming(req, res);
const reslt = await podlet.process(incoming, process);
Expand All @@ -68,15 +72,17 @@ class FakeHttpServer {
}

close() {
return new Promise((resolve, reject) => {
this.server.close((err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
return /** @type {Promise<void>} */ (
new Promise((resolve, reject) => {
this.server.close((err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
})
);
}

get(options = {}) {
Expand Down Expand Up @@ -109,14 +115,20 @@ class FakeHttpServer {
}

class FakeExpressServer {
/**
* @param {Podlet} podlet
* @param {(incoming: import('@podium/utils').HttpIncoming) => void} [onRequest]
* @param {{ path: string; handler: import('express').Handler } | import('express').Handler} [onContentRoute]
* @param {import('express').Handler} [onFallbackRoute]
*/
constructor(podlet, onRequest, onContentRoute, onFallbackRoute) {
this.app = express();
this.app.use(podlet.middleware());
if (onContentRoute) {
if (onContentRoute.path && onContentRoute.handler) {
this.app.get(onContentRoute.path, onContentRoute.handler);
} else {
if (typeof onContentRoute === 'function') {
this.app.get(podlet.content({ prefix: true }), onContentRoute);
} else {
this.app.get(onContentRoute.path, onContentRoute.handler);
}
}
if (onFallbackRoute)
Expand All @@ -143,15 +155,17 @@ class FakeExpressServer {
}

close() {
return new Promise((resolve, reject) => {
this.server.close((err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
return /** @type {Promise<void>} */ (
new Promise((resolve, reject) => {
this.server.close((err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
})
);
}

get(options = {}) {
Expand All @@ -167,6 +181,7 @@ class FakeExpressServer {
res.on('end', () => {
resolve({
headers: res.headers,
// @ts-ignore
response: opts.raw
? chunks.join('')
: JSON.parse(chunks.join('')),
Expand Down Expand Up @@ -203,6 +218,7 @@ tap.test('Podlet() - object tag - should be PodiumPodlet', (t) => {

tap.test('Podlet() - no value given to "name" argument - should throw', (t) => {
t.throws(() => {
// @ts-expect-error Testing bad input
const podlet = new Podlet({ version: 'v1.0.0', pathname: '/' }); // eslint-disable-line no-unused-vars
}, 'The value, "", for the required argument "name" on the Podlet constructor is not defined or not valid.');
t.end();
Expand All @@ -212,7 +228,6 @@ tap.test(
'Podlet() - invalid value given to "name" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = {
name: 'foo bar',
version: 'v1.0.0',
Expand All @@ -228,6 +243,7 @@ tap.test(
'Podlet() - no value given to "version" argument - should throw',
(t) => {
t.throws(() => {
// @ts-expect-error Testing bad input
const podlet = new Podlet({ name: 'foo', pathname: '/' }); // eslint-disable-line no-unused-vars
}, 'The value, "", for the required argument "version" on the Podlet constructor is not defined or not valid.');
t.end();
Expand All @@ -238,12 +254,12 @@ tap.test(
'Podlet() - invalid value given to "version" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = {
name: 'foo',
version: true,
pathname: '/',
};
// @ts-expect-error Testing bad input
const podlet = new Podlet(options); // eslint-disable-line no-unused-vars
}, 'The value, "true", for the required argument "version" on the Podlet constructor is not defined or not valid.');
t.end();
Expand All @@ -254,6 +270,7 @@ tap.test(
'Podlet() - no value given to "pathname" argument - should throw',
(t) => {
t.throws(() => {
// @ts-expect-error Testing bad input
const podlet = new Podlet({ name: 'foo', version: 'v1.0.0' }); // eslint-disable-line no-unused-vars
}, 'The value, "", for the required argument "pathname" on the Podlet constructor is not defined or not valid.');
t.end();
Expand All @@ -264,7 +281,6 @@ tap.test(
'Podlet() - invalid value given to "pathname" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = {
name: 'foo',
version: 'v1.0.0',
Expand All @@ -280,7 +296,6 @@ tap.test(
'Podlet() - invalid value given to "manifest" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = { manifest: 'æ / ø', ...DEFAULT_OPTIONS };
const podlet = new Podlet(options); // eslint-disable-line no-unused-vars
}, 'The value, "æ / ø", for the optional argument "manifest" on the Podlet constructor is not valid.');
Expand All @@ -292,7 +307,6 @@ tap.test(
'Podlet() - invalid value given to "content" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = { content: 'æ / ø', ...DEFAULT_OPTIONS };
const podlet = new Podlet(options); // eslint-disable-line no-unused-vars
}, 'The value, "æ / ø", for the optional argument "content" on the Podlet constructor is not valid.');
Expand All @@ -304,7 +318,6 @@ tap.test(
'Podlet() - invalid value given to "fallback" argument - should throw',
(t) => {
t.throws(() => {
// Yeah; silly formatting, but only way to please ESLint
const options = { fallback: 'æ / ø', ...DEFAULT_OPTIONS };
const podlet = new Podlet(options); // eslint-disable-line no-unused-vars
}, 'The value, "æ / ø", for the optional argument "fallback" on the Podlet constructor is not valid.');
Expand Down Expand Up @@ -677,6 +690,7 @@ tap.test(
tap.test('.css() - call method with no arguments - should throw', (t) => {
const podlet = new Podlet(DEFAULT_OPTIONS);
t.throws(() => {
// @ts-expect-error Testing bad input
podlet.css();
}, 'Value for argument variable "value", "undefined", is not valid');
t.end();
Expand Down Expand Up @@ -937,6 +951,7 @@ tap.test(
{
value: '/foo/bar',
data: {
// @ts-expect-error Testing older input
bar: 'a',
foo: 'b',
},
Expand Down Expand Up @@ -1435,6 +1450,7 @@ tap.test(
tap.test('.proxy() - no arguments - should throw', (t) => {
const podlet = new Podlet(DEFAULT_OPTIONS);
t.throws(() => {
// @ts-expect-error Testing bad input
podlet.proxy();
}, 'Value on argument variable "target", "null", is not valid');
t.end();
Expand Down Expand Up @@ -1491,6 +1507,7 @@ tap.test(
tap.test('.view() - set a non valid argument value - should throw', (t) => {
const podlet = new Podlet(DEFAULT_OPTIONS);
t.throws(() => {
// @ts-expect-error Testing bad input
podlet.view('test');
}, 'Value on argument variable "template" must be a function');
t.end();
Expand Down

0 comments on commit bf4bc75

Please sign in to comment.