From a5a3494f7c7fb7a20ceec4fb671f41ff5607dbf8 Mon Sep 17 00:00:00 2001
From: ItzNotABug
Date: Mon, 20 May 2024 18:08:02 +0530
Subject: [PATCH 1/3] tests: add/fix tests against `appexpress-essentials`
libraries.
---
source/package.json | 10 ++++---
source/tests/src/function/index.js | 13 ++++----
source/tests/src/function/views/article.ejs | 6 ++--
source/tests/src/function/views/article.hbs | 6 ++--
source/tests/src/function/views/article.html | 6 ++--
source/tests/src/function/views/article.jsx | 22 ++++++++++++++
source/tests/src/function/views/article.tsx | 29 ++++++++++++++++++
.../src/function/views/partials/content.jsx | 17 +++++++++++
.../src/function/views/partials/content.tsx | 23 ++++++++++++++
source/tests/src/function/views/sample.js | 5 ++++
source/tests/src/function/views/sample.jsx | 5 ++++
source/tests/src/function/views/sample.tsx | 7 +++++
source/tests/test.js | 30 +++++++++++++------
13 files changed, 149 insertions(+), 30 deletions(-)
create mode 100644 source/tests/src/function/views/article.jsx
create mode 100644 source/tests/src/function/views/article.tsx
create mode 100644 source/tests/src/function/views/partials/content.jsx
create mode 100644 source/tests/src/function/views/partials/content.tsx
create mode 100644 source/tests/src/function/views/sample.js
create mode 100644 source/tests/src/function/views/sample.jsx
create mode 100644 source/tests/src/function/views/sample.tsx
diff --git a/source/package.json b/source/package.json
index 3c07dcb..8154c07 100644
--- a/source/package.json
+++ b/source/package.json
@@ -1,6 +1,6 @@
{
"name": "@itznotabug/appexpress",
- "version": "0.2.4",
+ "version": "0.2.5",
"description": "An `express.js` like framework for Appwrite Functions, enabling super-easy navigation!",
"author": "@itznotabug",
"type": "module",
@@ -24,11 +24,13 @@
"mime-types": "2.1.35"
},
"devDependencies": {
- "ejs": "3.1.10",
- "express-hbs": "2.5.0",
"pug": "3.0.2",
+ "ejs": "3.1.10",
+ "showdown": "2.1.0",
"prettier": "3.2.5",
- "showdown": "2.1.0"
+ "express-hbs": "2.5.0",
+ "@itznotabug/appexpress-jsx": "^0.0.4",
+ "@itznotabug/appexpress-nocookies": "^0.0.2"
},
"keywords": [
"appwrite",
diff --git a/source/tests/src/function/index.js b/source/tests/src/function/index.js
index 5745703..133f57a 100644
--- a/source/tests/src/function/index.js
+++ b/source/tests/src/function/index.js
@@ -6,7 +6,10 @@ import showdown from 'showdown';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
+
+import jsx from '@itznotabug/appexpress-jsx';
import AppExpress from '../../../appexpress.js';
+import noCookies from '@itznotabug/appexpress-nocookies';
/**
* Sample repository for `DI`.
@@ -30,6 +33,7 @@ express.static('public', [/^\..*env.*/i]);
express.engine('ejs', ejs); // ejs
express.engine('pug', pug); // pub
+express.engine(['js', 'jsx', 'tsx'], jsx.engine); // react
// hbs, html
express.engine(
@@ -106,14 +110,7 @@ express.middleware({
});
// hard cookie remover
-express.middleware({
- incoming: (request) => {
- if (request.path === '/cookies') delete request.headers.cookie;
- },
- outgoing: (request, interceptor) => {
- if (request.path === '/cookies') delete interceptor.headers.cookie;
- },
-});
+express.middleware(noCookies.middleware);
// override body content
express.middleware({
diff --git a/source/tests/src/function/views/article.ejs b/source/tests/src/function/views/article.ejs
index 4a30041..89ead25 100644
--- a/source/tests/src/function/views/article.ejs
+++ b/source/tests/src/function/views/article.ejs
@@ -1,9 +1,9 @@
-
-
-
+
+
+
<%= title; %>
diff --git a/source/tests/src/function/views/article.hbs b/source/tests/src/function/views/article.hbs
index d076ef8..db10dc8 100644
--- a/source/tests/src/function/views/article.hbs
+++ b/source/tests/src/function/views/article.hbs
@@ -1,9 +1,9 @@
-
-
-
+
+
+
{{title}}
diff --git a/source/tests/src/function/views/article.html b/source/tests/src/function/views/article.html
index d076ef8..db10dc8 100644
--- a/source/tests/src/function/views/article.html
+++ b/source/tests/src/function/views/article.html
@@ -1,9 +1,9 @@
-
-
-
+
+
+
{{title}}
diff --git a/source/tests/src/function/views/article.jsx b/source/tests/src/function/views/article.jsx
new file mode 100644
index 0000000..88dbca9
--- /dev/null
+++ b/source/tests/src/function/views/article.jsx
@@ -0,0 +1,22 @@
+import Content from './partials/content.jsx';
+
+const Article = ({ title, content, subtitle, author }) => {
+ const headContents = `
+
+
+
+ ${title}
+ `;
+
+ return (
+
+
+
+ {title}
+
+
+
+ );
+};
+
+export default Article;
\ No newline at end of file
diff --git a/source/tests/src/function/views/article.tsx b/source/tests/src/function/views/article.tsx
new file mode 100644
index 0000000..37e5720
--- /dev/null
+++ b/source/tests/src/function/views/article.tsx
@@ -0,0 +1,29 @@
+import Content from './partials/content.jsx';
+
+type ArticleProps = {
+ title: string;
+ content: string;
+ subtitle: string;
+ author: string;
+}
+
+const Article = ({ title, content, subtitle, author }: ArticleProps) => {
+ const headContents = `
+
+
+
+ ${title}
+ `;
+
+ return (
+
+
+ {title}
+
+
+
+ );
+};
+
+export default Article;
\ No newline at end of file
diff --git a/source/tests/src/function/views/partials/content.jsx b/source/tests/src/function/views/partials/content.jsx
new file mode 100644
index 0000000..3bd4141
--- /dev/null
+++ b/source/tests/src/function/views/partials/content.jsx
@@ -0,0 +1,17 @@
+const Content = ({ subtitle, content, author }) => {
+ return (
+
+
+
+
+
+ );
+};
+
+export default Content;
\ No newline at end of file
diff --git a/source/tests/src/function/views/partials/content.tsx b/source/tests/src/function/views/partials/content.tsx
new file mode 100644
index 0000000..99a78ec
--- /dev/null
+++ b/source/tests/src/function/views/partials/content.tsx
@@ -0,0 +1,23 @@
+type ContentProps = {
+ subtitle: string;
+ content: string;
+ author: string;
+}
+
+const Content = ({ subtitle, content, author }: ContentProps) => {
+ return (
+
+
+
+
+
+ );
+};
+
+export default Content;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.js b/source/tests/src/function/views/sample.js
new file mode 100644
index 0000000..31d30e8
--- /dev/null
+++ b/source/tests/src/function/views/sample.js
@@ -0,0 +1,5 @@
+const SamplePlainReactComponent = ({ title }) => {
+ return Welcome to {title}
;
+};
+
+export default SamplePlainReactComponent;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.jsx b/source/tests/src/function/views/sample.jsx
new file mode 100644
index 0000000..b6b25ca
--- /dev/null
+++ b/source/tests/src/function/views/sample.jsx
@@ -0,0 +1,5 @@
+const SampleReactComponent = ({ title }) => {
+ return Welcome to {title}
;
+};
+
+export default SampleReactComponent;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.tsx b/source/tests/src/function/views/sample.tsx
new file mode 100644
index 0000000..aaa986b
--- /dev/null
+++ b/source/tests/src/function/views/sample.tsx
@@ -0,0 +1,7 @@
+type SampleTypedReactComponentProps = { title: string; };
+
+const SampleTypedReactComponent = ({ title }: SampleTypedReactComponentProps) => {
+ return Welcome to {title}
;
+};
+
+export default SampleTypedReactComponent;
diff --git a/source/tests/test.js b/source/tests/test.js
index f7c57b5..a0b0389 100644
--- a/source/tests/test.js
+++ b/source/tests/test.js
@@ -220,22 +220,26 @@ describe('Injected dependency validation', () => {
describe('Render template contents', () => {
const expected = `Welcome to AppExpress
`;
- ['ejs', 'hbs', 'pug', 'apw', 'md'].forEach((template) => {
- it(`should return rendered content from ${template.toUpperCase()} template`, async () => {
- const context = createContext({ path: `/engines/${template}` });
- const { body } = await index(context);
- assert.strictEqual(body, expected);
- });
- });
+ ['ejs', 'hbs', 'pug', 'apw', 'md', 'js', 'jsx', 'tsx'].forEach(
+ (template) => {
+ it(`should return rendered content from ${template.toUpperCase()} template`, async () => {
+ const context = createContext({ path: `/engines/${template}` });
+ const { body } = await index(context);
+ assert.strictEqual(body, expected);
+ });
+ },
+ );
});
describe('Render partials contents on supported engines', () => {
- const expected = `AppExpressAppExpress
Routing for Appwrite Functions!
An express.js like framework for Appwrite Functions, enabling super-easy navigation!`;
+ const expected = `AppExpressAppExpress
Routing for Appwrite Functions!
An express.js like framework for Appwrite Functions, enabling super-easy navigation!`;
[
{ engine: 'HBS', extension: 'hbs' },
{ engine: 'HBS', extension: 'html' },
{ engine: 'EJS', extension: 'ejs' },
+ { engine: 'JSX', extension: 'jsx' },
+ { engine: 'JSX', extension: 'tsx' },
].forEach(({ engine, extension }) => {
it(`should render an article using ${engine.toUpperCase()} engine & ${extension.toUpperCase()} extension`, async () => {
const context = createContext({
@@ -244,7 +248,15 @@ describe('Render partials contents on supported engines', () => {
});
const { body } = await index(context);
- const cleanBody = body.replace(/\n/g, '').replace(/ {2,}/g, '');
+ let cleanBody = body.replace(/\n/g, '').replace(/ {2,}/g, '');
+
+ if (['jsx', 'tsx'].includes(extension)) {
+ cleanBody = cleanBody.replace(
+ /<([^>\s]+)([^>]*)\/>/g,
+ '<$1$2 />',
+ );
+ }
+
assert.strictEqual(cleanBody, expected);
});
});
From 2708e48981d60f47ff91261013d0e57f88437b21 Mon Sep 17 00:00:00 2001
From: ItzNotABug
Date: Mon, 20 May 2024 22:40:39 +0530
Subject: [PATCH 2/3] tests: remove `jsx` tests.
---
source/package.json | 1 -
source/tests/src/function/index.js | 2 --
source/tests/src/function/views/article.jsx | 22 --------------
source/tests/src/function/views/article.tsx | 29 -------------------
.../src/function/views/partials/content.jsx | 17 -----------
.../src/function/views/partials/content.tsx | 23 ---------------
source/tests/src/function/views/sample.js | 5 ----
source/tests/src/function/views/sample.jsx | 5 ----
source/tests/src/function/views/sample.tsx | 7 -----
source/tests/test.js | 26 +++++------------
10 files changed, 7 insertions(+), 130 deletions(-)
delete mode 100644 source/tests/src/function/views/article.jsx
delete mode 100644 source/tests/src/function/views/article.tsx
delete mode 100644 source/tests/src/function/views/partials/content.jsx
delete mode 100644 source/tests/src/function/views/partials/content.tsx
delete mode 100644 source/tests/src/function/views/sample.js
delete mode 100644 source/tests/src/function/views/sample.jsx
delete mode 100644 source/tests/src/function/views/sample.tsx
diff --git a/source/package.json b/source/package.json
index 8154c07..2b2510e 100644
--- a/source/package.json
+++ b/source/package.json
@@ -29,7 +29,6 @@
"showdown": "2.1.0",
"prettier": "3.2.5",
"express-hbs": "2.5.0",
- "@itznotabug/appexpress-jsx": "^0.0.4",
"@itznotabug/appexpress-nocookies": "^0.0.2"
},
"keywords": [
diff --git a/source/tests/src/function/index.js b/source/tests/src/function/index.js
index 133f57a..af1a085 100644
--- a/source/tests/src/function/index.js
+++ b/source/tests/src/function/index.js
@@ -7,7 +7,6 @@ import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
-import jsx from '@itznotabug/appexpress-jsx';
import AppExpress from '../../../appexpress.js';
import noCookies from '@itznotabug/appexpress-nocookies';
@@ -33,7 +32,6 @@ express.static('public', [/^\..*env.*/i]);
express.engine('ejs', ejs); // ejs
express.engine('pug', pug); // pub
-express.engine(['js', 'jsx', 'tsx'], jsx.engine); // react
// hbs, html
express.engine(
diff --git a/source/tests/src/function/views/article.jsx b/source/tests/src/function/views/article.jsx
deleted file mode 100644
index 88dbca9..0000000
--- a/source/tests/src/function/views/article.jsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import Content from './partials/content.jsx';
-
-const Article = ({ title, content, subtitle, author }) => {
- const headContents = `
-
-
-
- ${title}
- `;
-
- return (
-
-
-
- {title}
-
-
-
- );
-};
-
-export default Article;
\ No newline at end of file
diff --git a/source/tests/src/function/views/article.tsx b/source/tests/src/function/views/article.tsx
deleted file mode 100644
index 37e5720..0000000
--- a/source/tests/src/function/views/article.tsx
+++ /dev/null
@@ -1,29 +0,0 @@
-import Content from './partials/content.jsx';
-
-type ArticleProps = {
- title: string;
- content: string;
- subtitle: string;
- author: string;
-}
-
-const Article = ({ title, content, subtitle, author }: ArticleProps) => {
- const headContents = `
-
-
-
- ${title}
- `;
-
- return (
-
-
- {title}
-
-
-
- );
-};
-
-export default Article;
\ No newline at end of file
diff --git a/source/tests/src/function/views/partials/content.jsx b/source/tests/src/function/views/partials/content.jsx
deleted file mode 100644
index 3bd4141..0000000
--- a/source/tests/src/function/views/partials/content.jsx
+++ /dev/null
@@ -1,17 +0,0 @@
-const Content = ({ subtitle, content, author }) => {
- return (
-
-
-
-
-
- );
-};
-
-export default Content;
\ No newline at end of file
diff --git a/source/tests/src/function/views/partials/content.tsx b/source/tests/src/function/views/partials/content.tsx
deleted file mode 100644
index 99a78ec..0000000
--- a/source/tests/src/function/views/partials/content.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-type ContentProps = {
- subtitle: string;
- content: string;
- author: string;
-}
-
-const Content = ({ subtitle, content, author }: ContentProps) => {
- return (
-
-
-
-
-
- );
-};
-
-export default Content;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.js b/source/tests/src/function/views/sample.js
deleted file mode 100644
index 31d30e8..0000000
--- a/source/tests/src/function/views/sample.js
+++ /dev/null
@@ -1,5 +0,0 @@
-const SamplePlainReactComponent = ({ title }) => {
- return Welcome to {title}
;
-};
-
-export default SamplePlainReactComponent;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.jsx b/source/tests/src/function/views/sample.jsx
deleted file mode 100644
index b6b25ca..0000000
--- a/source/tests/src/function/views/sample.jsx
+++ /dev/null
@@ -1,5 +0,0 @@
-const SampleReactComponent = ({ title }) => {
- return Welcome to {title}
;
-};
-
-export default SampleReactComponent;
\ No newline at end of file
diff --git a/source/tests/src/function/views/sample.tsx b/source/tests/src/function/views/sample.tsx
deleted file mode 100644
index aaa986b..0000000
--- a/source/tests/src/function/views/sample.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-type SampleTypedReactComponentProps = { title: string; };
-
-const SampleTypedReactComponent = ({ title }: SampleTypedReactComponentProps) => {
- return Welcome to {title}
;
-};
-
-export default SampleTypedReactComponent;
diff --git a/source/tests/test.js b/source/tests/test.js
index a0b0389..a84bdfb 100644
--- a/source/tests/test.js
+++ b/source/tests/test.js
@@ -220,15 +220,13 @@ describe('Injected dependency validation', () => {
describe('Render template contents', () => {
const expected = `Welcome to AppExpress
`;
- ['ejs', 'hbs', 'pug', 'apw', 'md', 'js', 'jsx', 'tsx'].forEach(
- (template) => {
- it(`should return rendered content from ${template.toUpperCase()} template`, async () => {
- const context = createContext({ path: `/engines/${template}` });
- const { body } = await index(context);
- assert.strictEqual(body, expected);
- });
- },
- );
+ ['ejs', 'hbs', 'pug', 'apw', 'md'].forEach((template) => {
+ it(`should return rendered content from ${template.toUpperCase()} template`, async () => {
+ const context = createContext({ path: `/engines/${template}` });
+ const { body } = await index(context);
+ assert.strictEqual(body, expected);
+ });
+ });
});
describe('Render partials contents on supported engines', () => {
@@ -238,8 +236,6 @@ describe('Render partials contents on supported engines', () => {
{ engine: 'HBS', extension: 'hbs' },
{ engine: 'HBS', extension: 'html' },
{ engine: 'EJS', extension: 'ejs' },
- { engine: 'JSX', extension: 'jsx' },
- { engine: 'JSX', extension: 'tsx' },
].forEach(({ engine, extension }) => {
it(`should render an article using ${engine.toUpperCase()} engine & ${extension.toUpperCase()} extension`, async () => {
const context = createContext({
@@ -249,14 +245,6 @@ describe('Render partials contents on supported engines', () => {
const { body } = await index(context);
let cleanBody = body.replace(/\n/g, '').replace(/ {2,}/g, '');
-
- if (['jsx', 'tsx'].includes(extension)) {
- cleanBody = cleanBody.replace(
- /<([^>\s]+)([^>]*)\/>/g,
- '<$1$2 />',
- );
- }
-
assert.strictEqual(cleanBody, expected);
});
});
From d9be9ed37903947b7a70839313927f9f785ecf40 Mon Sep 17 00:00:00 2001
From: ItzNotABug
Date: Mon, 20 May 2024 22:48:35 +0530
Subject: [PATCH 3/3] tests: revert closing tags refactoring.
---
source/tests/src/function/index.js | 1 -
source/tests/src/function/views/article.ejs | 6 +++---
source/tests/src/function/views/article.hbs | 6 +++---
source/tests/src/function/views/article.html | 6 +++---
source/tests/test.js | 4 ++--
5 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/source/tests/src/function/index.js b/source/tests/src/function/index.js
index af1a085..385e293 100644
--- a/source/tests/src/function/index.js
+++ b/source/tests/src/function/index.js
@@ -6,7 +6,6 @@ import showdown from 'showdown';
import fs from 'fs';
import path from 'path';
import crypto from 'crypto';
-
import AppExpress from '../../../appexpress.js';
import noCookies from '@itznotabug/appexpress-nocookies';
diff --git a/source/tests/src/function/views/article.ejs b/source/tests/src/function/views/article.ejs
index 89ead25..4a30041 100644
--- a/source/tests/src/function/views/article.ejs
+++ b/source/tests/src/function/views/article.ejs
@@ -1,9 +1,9 @@
-
-
-
+
+
+
<%= title; %>
diff --git a/source/tests/src/function/views/article.hbs b/source/tests/src/function/views/article.hbs
index db10dc8..d076ef8 100644
--- a/source/tests/src/function/views/article.hbs
+++ b/source/tests/src/function/views/article.hbs
@@ -1,9 +1,9 @@
-
-
-
+
+
+
{{title}}
diff --git a/source/tests/src/function/views/article.html b/source/tests/src/function/views/article.html
index db10dc8..d076ef8 100644
--- a/source/tests/src/function/views/article.html
+++ b/source/tests/src/function/views/article.html
@@ -1,9 +1,9 @@
-
-
-
+
+
+
{{title}}
diff --git a/source/tests/test.js b/source/tests/test.js
index a84bdfb..f7c57b5 100644
--- a/source/tests/test.js
+++ b/source/tests/test.js
@@ -230,7 +230,7 @@ describe('Render template contents', () => {
});
describe('Render partials contents on supported engines', () => {
- const expected = `AppExpressAppExpress
Routing for Appwrite Functions!
An express.js like framework for Appwrite Functions, enabling super-easy navigation!`;
+ const expected = `AppExpressAppExpress
Routing for Appwrite Functions!
An express.js like framework for Appwrite Functions, enabling super-easy navigation!`;
[
{ engine: 'HBS', extension: 'hbs' },
@@ -244,7 +244,7 @@ describe('Render partials contents on supported engines', () => {
});
const { body } = await index(context);
- let cleanBody = body.replace(/\n/g, '').replace(/ {2,}/g, '');
+ const cleanBody = body.replace(/\n/g, '').replace(/ {2,}/g, '');
assert.strictEqual(cleanBody, expected);
});
});