From 4fc3657a980efdd7416787cc22d868eae020bf39 Mon Sep 17 00:00:00 2001 From: voidCounter Date: Wed, 19 Jun 2024 12:04:08 +0600 Subject: [PATCH] Refactored tests --- package.json | 2 +- test/demo.js | 12 ++++++++---- test/page_structure.js | 6 +++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 8575af5..6e5bab1 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "stylelint:css": "stylelint css/*.css", "lint": "npm run lint:js && npm run lint:html && npm run lint:css && npm run lint:tests", "pretest": "npm run stylelint:css && npm run lint", - "test": "mocha --timeout 10000", + "test": "mocha", "fix": "eslint js/everything.js test/*.js --fix", "start": "http-server --cors -o -a localhost", "snyk-monitor": "snyk monitor" diff --git a/test/demo.js b/test/demo.js index e401eb6..50a309f 100644 --- a/test/demo.js +++ b/test/demo.js @@ -3,8 +3,10 @@ const assert = require("assert"); const puppeteer = require("puppeteer"); const http = require("http-server"); -const indexHTMLURL = "http://localhost:8000/index.html"; - +const SERVER_PORT = 8000; +const TEST_TIMEOUT = 4000; +const indexHTMLURL = `http://localhost:${SERVER_PORT}/index.html`; +let server; /** Utilities **/ // TODO: with refactor into a node module, this can go away! @@ -22,15 +24,17 @@ const demos = [ "03O2yKUgrKw" // Mike Mago & Dragonette - Outlines ]; -let server; (async () => { before(async function() { server = http.createServer({root: path.join(__dirname, "..")}); - server.listen(8000); + server.listen(SERVER_PORT); global.browser = global.browser || await puppeteer.launch(); }); describe("Demo", async function() { + // set timeout for this test + this.timeout(TEST_TIMEOUT); + it("should play the demo when demo button is clicked", async function() { const page = await browser.newPage(); await page.goto(indexHTMLURL); diff --git a/test/page_structure.js b/test/page_structure.js index ffbbf6d..c9ea1e2 100644 --- a/test/page_structure.js +++ b/test/page_structure.js @@ -67,13 +67,13 @@ async function getProperty(page, selector, property) { const preloadStylesheet = "preload stylesheet"; assert.equal(await getProperty(page, "link ~ link ~ link", "rel"), preloadStylesheet); - assert.ok((await getProperty(page, "link ~ link ~ link", "href")).startsWith("https://unpkg.com/primer-css@")); + assert.ok((await getProperty(page, "link ~ link ~ link", "href")).match("https:\\/\\/unpkg.com\\/primer-css@[~^]?\\d.+\\/css\\/primer.css")); assert.equal(await getProperty(page, "link ~ link ~ link ~ link", "rel"), preloadStylesheet); - assert.ok((await getProperty(page, "link ~ link ~ link ~ link", "href")).startsWith("https://unpkg.com/font-awesome@")); + assert.ok((await getProperty(page, "link ~ link ~ link ~ link", "href")).match("https:\\/\\/unpkg.com\\/font-awesome@[~^]?\\d.+\\/css\\/font-awesome.min.css")); assert.equal(await getProperty(page, "link ~ link ~ link ~ link ~ link", "rel"), preloadStylesheet); - assert.ok((await getProperty(page, "link ~ link ~ link ~ link ~ link", "href")).startsWith("https://unpkg.com/plyr@")); + assert.ok((await getProperty(page, "link ~ link ~ link ~ link ~ link", "href")).match("https:\\/\\/unpkg.com\\/plyr@[~^]?\\d.+\\/dist\\/plyr.css")); assert.equal(await getProperty(page, "link ~ link ~ link ~ link ~ link ~ link", "rel"), preloadStylesheet); assert.ok((await getProperty(page, "link ~ link ~ link ~ link ~ link ~ link", "href")).endsWith("css/styles.css"));