Skip to content

Commit

Permalink
Refactored tests
Browse files Browse the repository at this point in the history
  • Loading branch information
voidCounter committed Jun 19, 2024
1 parent 3d24025 commit 4fc3657
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 8 additions & 4 deletions test/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions test/page_structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 4fc3657

Please sign in to comment.