summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/feed-atom.spec.js74
-rw-r--r--tests/feed-rss.spec.js (renamed from tests/feeds.spec.js)42
-rw-r--r--tests/humans.spec.js39
3 files changed, 134 insertions, 21 deletions
diff --git a/tests/feed-atom.spec.js b/tests/feed-atom.spec.js
new file mode 100644
index 0000000..7e23328
--- /dev/null
+++ b/tests/feed-atom.spec.js
@@ -0,0 +1,74 @@
+'use strict';
+
+// @ts-check
+const { test, expect } = require('@playwright/test');
+const jsdom = require('jsdom');
+const { JSDOM } = jsdom;
+
+test('atom feed has correct updated field', async ({ page }) => {
+ await page.goto('/feeds/feed.atom.xml');
+
+ // Get the content of the page
+ const content = await page.content();
+
+ // Create a new JSDOM instance
+ const dom = new JSDOM(content, { contentType: 'text/xml' });
+
+ // Get the global window object
+ const { window } = dom;
+
+ // Get the updated field
+ const updatedField = window.document.querySelector('feed > updated');
+
+ // Check if the updated field exists
+ expect(updatedField).not.toBeNull();
+
+ // Check if the updated field is not empty
+ expect(updatedField.textContent).not.toBe('');
+
+ // Check if the updated field has the correct format
+ const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/;
+ expect(updatedField.textContent).toMatch(dateRegex);
+});
+
+test('atom feed has correct author information', async ({ page }) => {
+ await page.goto('/feeds/feed.atom.xml');
+
+ // Get the content of the page
+ const content = await page.content();
+
+ // Create a new JSDOM instance
+ const dom = new JSDOM(content, { contentType: 'text/xml' });
+
+ // Get the global window object
+ const { window } = dom;
+
+ // Get the author element
+ const authorElement = window.document.querySelector('feed > author');
+
+ // Check if the author element exists
+ expect(authorElement).not.toBeNull();
+
+ // Get the name element
+ const nameElement = authorElement.querySelector('name');
+
+ // Check if the name element exists
+ expect(nameElement).not.toBeNull();
+
+ // Check if the name element has the correct type attribute
+ expect(nameElement.getAttribute('type')).toBe('html');
+
+ // Check if the name element has the correct text content
+ expect(nameElement.textContent).not.toBeNull();
+ expect(nameElement.textContent.trim()).not.toBe('');
+
+ // Get the email element
+ const emailElement = authorElement.querySelector('email');
+
+ // Check if the email element exists
+ expect(emailElement).not.toBeNull();
+
+ // Check if the email element has the correct text content
+ expect(emailElement.textContent).not.toBeNull();
+ expect(emailElement.textContent.trim()).not.toBe('');
+});
diff --git a/tests/feeds.spec.js b/tests/feed-rss.spec.js
index e3291c3..2927140 100644
--- a/tests/feeds.spec.js
+++ b/tests/feed-rss.spec.js
@@ -5,8 +5,8 @@ const { test, expect } = require('@playwright/test');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
-test('atom feed has correct updated field', async ({ page }) => {
- await page.goto('/feeds/feed.atom.xml');
+test('rss feed has correct lastBuildDate field', async ({ page }) => {
+ await page.goto('/feeds/feed.rss.xml');
// Get the content of the page
const content = await page.content();
@@ -17,21 +17,21 @@ test('atom feed has correct updated field', async ({ page }) => {
// Get the global window object
const { window } = dom;
- // Get the updated field
- const updatedField = window.document.querySelector('feed > updated');
+ // Get the lastBuildDate field
+ const lastBuildDateField = window.document.querySelector('rss > lastBuildDate');
- // Check if the updated field exists
- expect(updatedField).not.toBeNull();
+ // Check if the lastBuildDate field exists
+ expect(lastBuildDateField).not.toBeNull();
- // Check if the updated field is not empty
- expect(updatedField.textContent).not.toBe('');
+ // Check if the lastBuildDate field is not empty
+ expect(lastBuildDateField.textContent.trim()).not.toBe('');
- // Check if the updated field has the correct format
- const dateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[+-]\d{2}:\d{2})$/;
- expect(updatedField.textContent).toMatch(dateRegex);
+ // Check if the lastBuildDate field has the correct format
+ const dateRegex = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} [+-]\d{4}$/;
+ expect(lastBuildDateField.textContent).toMatch(dateRegex);
});
-test('rss feed has correct lastBuildDate field', async ({ page }) => {
+test('rss feed has correct author information', async ({ page }) => {
await page.goto('/feeds/feed.rss.xml');
// Get the content of the page
@@ -43,16 +43,16 @@ test('rss feed has correct lastBuildDate field', async ({ page }) => {
// Get the global window object
const { window } = dom;
- // Get the lastBuildDate field
- const lastBuildDateField = window.document.querySelector('rss > lastBuildDate');
+ // Get the dc:creator element
+ const creatorElement = window.document.querySelector('rss > dc\\:creator');
- // Check if the lastBuildDate field exists
- expect(lastBuildDateField).not.toBeNull();
+ // Check if the dc:creator element exists
+ expect(creatorElement).not.toBeNull();
- // Check if the lastBuildDate field is not empty
- expect(lastBuildDateField.textContent.trim()).not.toBe('');
+ // Check if the dc:creator element has the correct type attribute
+ expect(creatorElement.getAttribute('type')).toBe('html');
- // Check if the lastBuildDate field has the correct format
- const dateRegex = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} [+-]\d{4}$/;
- expect(lastBuildDateField.textContent).toMatch(dateRegex);
+ // Check if the dc:creator element has the correct text content
+ expect(creatorElement.textContent).not.toBeNull();
+ expect(creatorElement.textContent.trim()).not.toBe('');
});
diff --git a/tests/humans.spec.js b/tests/humans.spec.js
new file mode 100644
index 0000000..2acf7e0
--- /dev/null
+++ b/tests/humans.spec.js
@@ -0,0 +1,39 @@
+'use strict';
+
+// @ts-check
+const { test, expect } = require('@playwright/test');
+
+test('humans.txt contains expected information', async ({ page }) => {
+ await page.goto('/humans.txt');
+
+ // Get the content of the page
+ const content = await page.content();
+
+ // Define the expected fields
+ const expectedFields = [
+ 'Author:',
+ 'Contact:',
+ 'GitHub:',
+ 'Twitter:',
+ 'From:',
+ 'Last update:',
+ 'Language:',
+ 'Doctype:',
+ 'Standards:',
+ 'Components:',
+ 'Hugo version:'
+ ];
+
+ // Check if each expected field is present in the content
+ for (const field of expectedFields) {
+ expect(content).toContain(field);
+ }
+
+ // Check if the content contains non-empty values for each field
+ for (const field of expectedFields) {
+ const regex = new RegExp(`${field}\\s+(.+)`, 'g');
+ const match = regex.exec(content);
+ expect(match).not.toBeNull();
+ expect(match[1].trim()).not.toBe('');
+ }
+});