Skip to content

Commit

Permalink
Added code coverage - figured out how to make the rest of the core co…
Browse files Browse the repository at this point in the history
…de testable.
  • Loading branch information
lupestro committed Feb 4, 2024
1 parent d60121e commit 64f255a
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.nyc_output/*
.vscode/*
node_modules/*
dist/*
dist/*
coverage/*
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"build:prod": "webpack --mode=production --node-env=production",
"test": "npm-run-all lint build:dev test:units",
"test:units": "mocha",
"cover": "c8 --reporter html mocha",
"watch": "webpack --mode development --watch",
"serve": "webpack serve"
},
Expand All @@ -38,6 +39,7 @@
"@babel/eslint-parser": "7.23.10",
"babel-loader": "^9.1.3",
"babel-preset-es2015": "^6.24.1",
"c8":"^9.1.0",
"cpy-cli":"^5.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
Expand Down
144 changes: 144 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 51 additions & 9 deletions test/test-stubs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ export class MockToken {
};

export class MockGame {
getSetting(modname, settingName) {
assert.equal(modname, 'torch');
let value = this.settingsData[settingName];
assert.notEqual(value, undefined, `Value for setting ${settingName} is undefined`);
return value;
};
getActor(id) {
return this.actorData.find ( (actor) => actor.system.id === id );
}
constructor (system, actors, isGM, settings) {
this.actorData = actors;
this.settingsData = settings;
Expand All @@ -100,4 +91,55 @@ export class MockGame {
get : (modname, settingName) => this.getSetting(modname, settingName)
}
};
getSetting(modname, settingName) {
assert.equal(modname, 'torch');
let value = this.settingsData[settingName];
assert.notEqual(value, undefined, `Value for setting ${settingName} is undefined`);
return value;
};
getActor(id) {
return this.actorData.find ( (actor) => actor.system.id === id );
}
};

export class MockScene {
tokens = [];
constructor(tokens) {
if (tokens) {
this.tokens = tokens;
}
}
randomNumericString() {
return Math.floor(Math.random() * 1000000).toString(16);
}
createEmbeddedDocuments (tokens) {
const newTokens = [];
// Give 'em all ids
for (const token of tokens) {
if (token.id) {
newTokens.push(Object.assign(token, {}));
} else {
newTokens.push(Object.assign(token, {id: this.randomNumericString()}));
}
}
this.tokens.concat(newTokens);
}
getEmbeddedDocument(type, id) {
assert.equal(type, 'Token');
let token = this.tokens.find( (token) => token.id === id);
assert.notEqual(token, undefined);
return token;
}
deleteEmbeddedDocuments(tokens) {
for (const token of tokens) {
assert.ok(this.tokens.find( (token) => token.id === id));
}
const remaining = [];
for (const token of this.tokens) {
if (!this.tokens.find( (token) => token.id === id)) {
remaining.push(token);
}
}
this.tokens = remaining;
}
}

0 comments on commit 64f255a

Please sign in to comment.