-
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
38 changed files
with
2,453 additions
and
91 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
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 |
---|---|---|
@@ -1,124 +1,101 @@ | ||
import { existsSync, mkdirSync, rmSync } from "node:fs"; | ||
|
||
import { basename, join } from "path"; | ||
import { richies, testProps } from "../lib/types"; | ||
import { richie } from "../richie"; | ||
|
||
const opfolder = "./test/outputs"; | ||
let iterN = 0; | ||
|
||
function mkDestPath(testfile: string): string { | ||
iterN += 1; | ||
const opFolder = "./test/outputs/node-env"; | ||
let iteration = 0; | ||
|
||
// Generate a unique destination path for test output | ||
function createDestinationPath(testFile: string): string { | ||
iteration += 1; | ||
return join( | ||
process.cwd(), | ||
opfolder, | ||
`OP_Of_(${iterN}) ${basename(testfile)}`, | ||
opFolder, | ||
`Output_${iteration}_${basename(testFile)}`, | ||
); | ||
} | ||
|
||
function createTestProps(testfile: string): testProps { | ||
// Create test properties object | ||
function createTestProps(testFile: string): testProps { | ||
return { | ||
testfile: testfile, | ||
destFile: mkDestPath(testfile), | ||
testfile: testFile, | ||
destFile: createDestinationPath(testFile), | ||
}; | ||
} | ||
|
||
// Define test cases | ||
const testRecords: Record<richies, testProps> = { | ||
article: createTestProps("test/test-sample/article.html"), | ||
|
||
breadcrumb: createTestProps( | ||
"test/test-sample/breadcrumb/sub-breadcrumb/notindex.html", | ||
), | ||
|
||
crecipe: createTestProps("test/test-sample/carousels/recipies.html"), | ||
recipe: createTestProps("test/test-sample/carousels/recipies.html"), | ||
|
||
movie: createTestProps("test/test-sample/carousels/movies.html"), | ||
cmovie: createTestProps("test/test-sample/carousels/movies.html"), | ||
|
||
restaurant: createTestProps( | ||
"test/test-sample/carousels/restaurants.html", | ||
), | ||
crestaurant: createTestProps( | ||
"test/test-sample/carousels/restaurants.html", | ||
), | ||
|
||
course: createTestProps("test/test-sample/carousels/courses.html"), | ||
ccourse: createTestProps("test/test-sample/carousels/courses.html"), | ||
|
||
event: createTestProps("test/test-sample/events.html"), | ||
|
||
faq: createTestProps("test/test-sample/faq.html"), | ||
|
||
video: createTestProps("test/test-sample/videos.html"), | ||
|
||
localbusiness: createTestProps("test/test-sample/localbusiness.html"), | ||
|
||
organization: createTestProps("test/test-sample/org.html"), | ||
|
||
product: createTestProps("test/test-sample/product.html"), | ||
productwv: createTestProps( | ||
"test/test-sample/productVarient/productCombined.html", | ||
), | ||
|
||
profile: createTestProps("test/test-sample/profilepage.html"), | ||
|
||
searchbox: createTestProps( | ||
"test/test-sample/Sitesearch/searchpage.html", | ||
), | ||
|
||
software: createTestProps("test/test-sample/softwareapp.html"), | ||
}; | ||
|
||
function run(richieName: richies): Promise<void> { | ||
const testfile = testRecords[richieName].testfile; | ||
const destinationFile = testRecords[richieName].destFile; | ||
|
||
return richie([richieName], testfile, destinationFile); | ||
// Execute a single test case | ||
async function executeTest(richieName: richies): Promise<void> { | ||
const { testfile, destFile } = testRecords[richieName]; | ||
await richie([richieName], testfile, destFile); | ||
} | ||
|
||
function runAll(): Promise<string> { | ||
//delete old artifacts | ||
try { | ||
rmSync(opfolder, { recursive: true }); | ||
} catch { | ||
//nothing to do | ||
} finally { | ||
//make op dir | ||
mkdirSync(opfolder, { recursive: true }); | ||
} | ||
|
||
const testOps: Promise<void>[] = []; | ||
|
||
for (const richieName of Object.keys(testRecords)) { | ||
testOps.push(run(richieName as richies)); | ||
} | ||
// Execute all test cases | ||
async function executeAllTests(): Promise<string> { | ||
// Clean up and prepare output directory | ||
rmSync(opFolder, { recursive: true, force: true }); | ||
mkdirSync(opFolder, { recursive: true }); | ||
|
||
// Run all tests in parallel | ||
await Promise.all( | ||
Object.keys(testRecords).map((richieName) => | ||
executeTest(richieName as richies), | ||
), | ||
); | ||
|
||
return new Promise((resolve, reject) => { | ||
Promise.all(testOps) | ||
.then(() => { | ||
resolve("passed"); | ||
}) | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
return "passed"; | ||
} | ||
|
||
function outputCheck(): string { | ||
for (const richieName of Object.keys(testRecords)) { | ||
if (!existsSync(testRecords[richieName as richies].destFile)) { | ||
return "failed"; | ||
} | ||
} | ||
return "passed"; | ||
// Verify output files | ||
function verifyOutputs(): string { | ||
return ( | ||
Object.values(testRecords).every(({ destFile }) => | ||
existsSync(destFile), | ||
) | ||
) ? | ||
"passed" | ||
: "failed"; | ||
} | ||
|
||
test("InAction test", async () => { | ||
expect(await runAll()).toBe("passed"); | ||
// Test cases | ||
test("Execute all tests", async () => { | ||
expect(await executeAllTests()).toBe("passed"); | ||
}); | ||
|
||
test("Output files Check", () => { | ||
expect(outputCheck()).toBe("passed"); | ||
test("Verify output files", () => { | ||
expect(verifyOutputs()).toBe("passed"); | ||
}); |
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,27 @@ | ||
<!DOCTYPE html><html lang="en"><head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Search Form</title> | ||
|
||
<script src="./client.js" type="text/javascript" defer=""></script> | ||
<script src="../bundle.min.js"> | ||
</script> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
RichieJS.default({ richieNames: ['searchbox'] }) | ||
}); | ||
</script> | ||
|
||
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebSite","url":"https://www.cresteem.com/","potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://www.cresteem.com//A:/Git/cresteem/Richie-JS/test/test-sample/Sitesearch/searchpage?q={searchTerm}"},"query-input":"required name=searchTerm"}}</script></head> | ||
|
||
<body> | ||
<h1>Search Form</h1> | ||
<form onsubmit="return search()"> | ||
<label for="searchInput">Search:</label> | ||
<input type="text" id="searchTerm" name="searchTerm"> | ||
<button type="submit">Search</button> | ||
</form> | ||
<div id="result"></div> | ||
|
||
|
||
</body></html> |
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,52 @@ | ||
<!DOCTYPE html><html lang="en"><head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Article Test Page</title> | ||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"> | ||
|
||
<script src="./bundle.min.js"> | ||
</script> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function() { | ||
RichieJS.default({richieNames:['article']}) | ||
}); | ||
</script> | ||
|
||
<script type="application/ld+json">{"@context":"https://schema.org","@type":"NewsArticle","headline":"Article Test Page","image":["https://i.imgur.com/X3E4UxT.jpeg","https://i.imgur.com/pJSzybj.jpeg"],"datePublished":"2024-02-06T20:37:00+05:30","dateModified":"2024-06-26T17:23:00+05:30","author":[{"@type":"Person","honorificPrefix":"Dr","name":"Phil","url":"https://www.instagram.com/iamspdarsan/","jobTitle":"Software Engineer"},{"@type":"Organization","name":"Winchester","url":"https://www.linkedin.com/in/iamspdarsan/"}],"publisher":[{"name":"Cresteem","url":"https://cresteem.com/blogs/"},{"name":"Google","url":"https://google.com/blogs/"}]}</script></head> | ||
|
||
|
||
<body data-articletype="NewsArticle"><!-- article type - Article, NewsArticle, BlogPosting--> | ||
<!-- published date --> | ||
<p class="rjs-article-pdt">2024-02-06 08:37 PM</p> | ||
<!-- modified date --> | ||
<p class="rjs-article-mdt">2024-06-26 05:23 PM</p> | ||
|
||
<main> | ||
<!-- thumbnail images or cover images --> | ||
<img class="rjs-article-img" src="https://i.imgur.com/X3E4UxT.jpeg" alt=""> | ||
<img class="rjs-article-img" src="https://i.imgur.com/pJSzybj.jpeg" alt=""> | ||
|
||
<!-- authorname --> | ||
<!-- anameP is Person type --> | ||
<!-- anameO is Organisation type --> | ||
<!-- HonorPrefix supported e.g.: Mr, Mrs, Miss, Ms, Mx, Sir, Dame, Dr, Cllr, Lady, or Lord, or other titles or positions--> | ||
<p class="rjs-article-anameP-1">Dr.Phil</p> | ||
|
||
<!-- author profile url --> | ||
<a class="rjs-article-aurl-1" href="https://www.instagram.com/iamspdarsan/">User Profile</a> | ||
|
||
<!-- author job title - this is optional--> | ||
<p class="rjs-article-ajob-1">Software Engineer</p> | ||
|
||
<p class="rjs-article-anameO-2">Winchester</p> | ||
<a class="rjs-article-aurl-2" href="https://www.linkedin.com/in/iamspdarsan/">User Profile</a> | ||
|
||
<p class="rjs-article-pname-1">Cresteem</p> | ||
<a class="rjs-article-purl-1" href="https://cresteem.com/blogs/"></a> | ||
|
||
<p class="rjs-article-pname-2">Google</p> | ||
<a class="rjs-article-purl-2" href="https://google.com/blogs/"></a> | ||
</main> | ||
|
||
|
||
</body></html> |
Oops, something went wrong.