Revert "start of e2e tests"

This reverts commit 717b5324bf.
This commit is contained in:
Alec Maier
2020-04-29 23:20:24 -04:00
parent 717b5324bf
commit 7e7977a4c8
10 changed files with 65 additions and 226 deletions

View File

@@ -24,9 +24,11 @@ const port = Array
app.set("port", port);
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'assets')));
app.use(express.static(path.join(__dirname, 'static')));
app.use(express.static(path.join(__dirname, 'images')));
app.use(express.static(path.join(__dirname, 'fonts')));
app.use(express.static(path.join(__dirname, 'views')));
app.use(express.static(path.join(__dirname, 'scripts')));
app.use(express.static(path.join(__dirname, 'stylesheets')));
app.use(express.static(path.join(__dirname, 'spec')));
app.get("/tests",function(request, response){

View File

@@ -4,10 +4,8 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node server.js",
"test": "jasmine && node browsertest.js openBrowser socket",
"test:unit": "jasmine",
"test:e2e": "node browsertest.js"
"test": "jasmine",
"test:all": "jasmine && node browsertest.js openBrowser socket"
},
"author": "",
"license": "ISC",

View File

@@ -5,7 +5,7 @@ const socketIO = require('socket.io');
const app = express();
const server = http.Server(app);
const io = socketIO(server);
const ServerHelper = require('./server-helper');
const ServerHelper = require('server-helper.js');
const secure = require('express-force-https');
app.use(secure);

View File

@@ -1,93 +0,0 @@
let socket;
// Jasmine lifecycle hooks
beforeEach(() => {
cleanupPlayground();
// jasmine.addMatchers({ /* provide matcher function here if you want to, I guess */});
});
beforeAll(() => {
if(window.location.search.includes("socket=true")) {
socket = io();
}
});
afterEach(() => {
/*
if(socket !== undefined) {
socket.emit("test result",parseTestResults());
}
How to get only the newest result? No clue right now.
*/
});
afterAll(() => {
resportResultsOnSocket();
});
// Utility functions
const parseTestResults = function() {
const resultsElement = document.querySelector("span.jasmine-overall-result.jasmine-bar");
if(resultsElement !== null) {
const results = /.*(\d+) specs.*(\d+) failure.*(\d+).*/.exec(resultsElement.textContent);
const total = parseInt(results[1]);
const failures = parseInt(results[2]);
const pending = parseInt(results[3]);
return Promise.resolve({
"totalCount": total,
"failureCount": failures,
"pendingCount": pending
});
} else {
let maxRetries = 60;
return new Promise((resolve, reject) => {
const resultsInterval = setInterval(() => {
maxRetries--;
const resultsElem = document.querySelector("span.jasmine-overall-result.jasmine-bar");
if (maxRetries === 0) {
reject("Required results element not found.");
} else {
if (resultsElem !== null) {
const results = /.*(\d+) spec.*(\d+) failure.*(\d+).*/.exec(resultsElem.textContent);
const pendingResults = /.*(\d+) pending.*/.exec(resultsElem.textContent);
const total = parseInt(results[1]);
const failures = parseInt(results[2]);
const pending = pendingResults ? parseInt(pendingResults[1]) : 0;
clearInterval(resultsInterval);
resolve({
"totalCount": total,
"failureCount": failures,
"pendingCount": pending
});
}
}
}, 500);
});
}
};
export const addStubElement = function(element) {
document.getElementById("playground").appendChild(element);
};
export const cleanupPlayground = function() {
document.getElementById("playground").innerHTML = "";
};
export const resportResultsOnSocket = function() {
if(socket === undefined) {
socket = io();
}
parseTestResults().then((results) => {
socket.emit("all-results",results);
}).catch((e) => {console.error(e);});
};

View File

@@ -1,37 +0,0 @@
import { addStubElement } from "../SpecHelper.js"
import { setup } from "../../static/setup.js"
describe("Home page", function() {
beforeEach(function() {
});
it("should render the set of standard and custom roles", function() {
// arrange
let goodCards = document.createElement("div");
goodCards.setAttribute("id", "card-select-good");
let evilCards = document.createElement("div");
evilCards.setAttribute("id", "card-select-evil");
let roles = document.createElement("div");
roles.setAttribute("id", "roles");
let customRoles = document.createElement("div");
customRoles.setAttribute("id", "custom-roles");
addStubElement(goodCards);
addStubElement(evilCards);
addStubElement(roles);
addStubElement(customRoles);
// act
setup.renderAvailableCards(false);
//assert
expect(document.getElementById("card-0")).toBeDefined();
});
});

View File

@@ -1,5 +1,5 @@
{
"spec_dir": "spec/unit/",
"spec_dir": "spec/unit",
"spec_files": [
"**/*[sS]pec.js"
],

View File

@@ -1,20 +0,0 @@
module.exports = function(debugMode = false){
return {
log(message = "") {
const now = new Date();
console.log('LOG ', now.toGMTString(), ': ', message);
},
debug(message = "") {
if (!debugMode) return;
const now = new Date();
console.debug('DEBUG ', now.toGMTString(), ': ', message);
},
error(message = "") {
if (!debugMode) return;
const now = new Date();
console.error('ERROR ', now.toGMTString(), ': ', message);
}
};
};

View File

@@ -21,10 +21,6 @@ const fullDeck = [];
let gameSize = 0;
let atLeastOnePlayer = false;
export class Setup {
constructor() {
// render all of the available cards to the user
window.onload = function() {
// register event listeners on buttons
document.getElementById("reset-btn").addEventListener("click", resetCardQuantities);
document.getElementById("create-btn").addEventListener("click", createGame);
@@ -39,15 +35,13 @@ export class Setup {
element.addEventListener('click', closeModal);
});
// render all of the available cards to the user
window.onload = function() {
readInUserCustomRoles();
setup.renderAvailableCards(false);
renderAvailableCards(false);
};
}
}
export const setup = {
renderAvailableCards(isCondensed) {
function renderAvailableCards(isCondensed) {
cards.sort(function(a, b) {
return a.role.toUpperCase().localeCompare(b.role);
});
@@ -77,7 +71,6 @@ export const setup = {
displayModal("custom-card-modal", "Evil");
});
}
};
function renderGoodRole(cardInfo, i, isCondensed) {
const card = CardManager.createCard(cardInfo);
@@ -159,7 +152,7 @@ function addCustomCardToRoles(e) {
saved: document.getElementById("custom-role-remember").checked
};
cards.push(newCard);
setup.renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
if (newCard.saved === true) {
let existingRoles = localStorage.getItem("play-werewolf-custom-roles");
@@ -257,7 +250,7 @@ function toggleViewChanger(isCondensed) {
document.getElementById("role-view-changer-gallery").classList.add("selected");
document.getElementById("role-view-changer-list").classList.remove("selected");
}
setup.renderAvailableCards(isCondensed);
renderAvailableCards(isCondensed);
}
function buildRoleEditForm(index) {
@@ -307,7 +300,7 @@ function removeCustomRole(name) {
localStorage.setItem("play-werewolf-custom-roles", JSON.stringify(userCustomRoles));
}
updateCustomRoleModal();
setup.renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
}
}
@@ -322,7 +315,7 @@ function updateCustomRole(event, index) {
removeOrAddSavedRoleIfNeeded(cardToUpdate);
toggleEditForm(event, index);
setup.renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
renderAvailableCards(document.getElementById("role-view-changer-list").classList.contains("selected"));
}
}

View File

@@ -17,8 +17,8 @@
<!--<script src="../server-helper.js" type="module"></script>-->
<!-- include spec files here... -->
<script src="../spec/SpecHelper.js" type="module"></script>
<script src="../spec/e2e/SetupSpec.js" type="module"></script>
<script src="/spec/SpecHelper.js" type="module"></script>
<script src="/spec/HomeSpec.js" type="module"></script>
<style>
div#playground {
visibility: hidden;

View File

@@ -118,9 +118,5 @@
</div>
</div>
<script type="module" src="/static/setup.js"></script>
<script type="module">
import { Setup } from "/static/setup.js";
const testSetup = new Setup();
</script>
</body>
</html>