Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More testing #235

Merged
merged 7 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
continue-on-error: true
with:
run: npm run test:coverage
# - uses: codecov/codecov-action@v3
# with:
# directory: ./coverage
- uses: codecov/codecov-action@v3
with:
directory: ./coverage
token: ${{ secrets.CODECOV_TOKEN }}
99 changes: 68 additions & 31 deletions media/main-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ exports.CAT_NAMES = new Map([
[98, 'Daisy'],
[99, 'Amelia'],
[100, 'Oliver'],
[101, 'Ghost'],
[102, 'Midnight'],
[103, 'Pumpkin'],
[105, 'Shadow'],
[106, 'Binx'],
[107, 'Riley'],
[108, 'Lenny'],
]);
exports.DOG_NAMES = new Map([
[1, 'Bella'],
Expand Down Expand Up @@ -214,6 +221,11 @@ exports.DOG_NAMES = new Map([
[98, 'Bolt'],
[99, 'Ein'],
[100, 'Maddy'],
[101, 'Ghost'],
[102, 'Midnight'],
[103, 'Pumpkin'],
[105, 'Shadow'],
[106, 'Sparky'],
]);
exports.CRAB_NAMES = new Map([
[1, 'Ferris'],
Expand Down Expand Up @@ -385,7 +397,6 @@ exports.petPanelApp = exports.saveState = exports.allPets = void 0;
const names_1 = __webpack_require__(/*! ../common/names */ "./src/common/names.ts");
const pets_1 = __webpack_require__(/*! ./pets */ "./src/panel/pets.ts");
const states_1 = __webpack_require__(/*! ./states */ "./src/panel/states.ts");
const vscode = window.acquireVsCodeApi();
exports.allPets = new pets_1.PetCollection();
var petCounter;
function calculateBallRadius(size) {
Expand Down Expand Up @@ -448,21 +459,24 @@ function handleMouseOver(e) {
}
});
}
function startAnimations(collision, pet) {
function startAnimations(collision, pet, stateApi) {
if (!stateApi) {
stateApi = window.acquireVsCodeApi();
}
collision.addEventListener('mouseover', handleMouseOver);
setInterval(() => {
var updates = exports.allPets.seekNewFriends();
updates.forEach((message) => {
vscode.postMessage({
stateApi?.postMessage({
text: message,
command: 'info',
});
});
pet.nextFrame();
saveState();
saveState(stateApi);
}, 100);
}
function addPetToPanel(petType, basePetUri, petColor, petSize, left, bottom, floor, name) {
function addPetToPanel(petType, basePetUri, petColor, petSize, left, bottom, floor, name, stateApi) {
var petSpriteElement = document.createElement('img');
petSpriteElement.className = 'pet';
document.getElementById('petsContainer').appendChild(petSpriteElement);
Expand All @@ -478,7 +492,7 @@ function addPetToPanel(petType, basePetUri, petColor, petSize, left, bottom, flo
try {
var newPet = (0, pets_1.createPet)(petType, petSpriteElement, collisionElement, speechBubbleElement, petSize, left, bottom, root, floor, name);
petCounter++;
startAnimations(collisionElement, newPet);
startAnimations(collisionElement, newPet, stateApi);
}
catch (e) {
// Remove elements
Expand All @@ -489,7 +503,10 @@ function addPetToPanel(petType, basePetUri, petColor, petSize, left, bottom, flo
}
return new pets_1.PetElement(petSpriteElement, collisionElement, speechBubbleElement, newPet, petColor, petType);
}
function saveState() {
function saveState(stateApi) {
if (!stateApi) {
stateApi = window.acquireVsCodeApi();
}
var state = new states_1.PetPanelState();
state.petStates = new Array();
exports.allPets.pets().forEach((petItem) => {
Expand All @@ -504,25 +521,33 @@ function saveState() {
});
});
state.petCounter = petCounter;
vscode.setState(state);
stateApi.setState(state);
}
exports.saveState = saveState;
function recoverState(basePetUri, petSize, floor) {
var state = vscode.getState();
if (state.petCounter === undefined || isNaN(state.petCounter)) {
function recoverState(basePetUri, petSize, floor, stateApi) {
if (!stateApi) {
stateApi = window.acquireVsCodeApi();
}
var state = stateApi.getState();
if (!state) {
petCounter = 1;
}
else {
petCounter = state.petCounter ?? 1;
if (state.petCounter === undefined || isNaN(state.petCounter)) {
petCounter = 1;
}
else {
petCounter = state.petCounter ?? 1;
}
}
var recoveryMap = new Map();
state.petStates?.forEach((p) => {
state?.petStates?.forEach((p) => {
// Fixes a bug related to duck animations
if (p.petType === 'rubber duck') {
p.petType = 'rubber-duck';
}
try {
var newPet = addPetToPanel(p.petType ?? "cat" /* PetType.cat */, basePetUri, p.petColor ?? "brown" /* PetColor.brown */, petSize, parseInt(p.elLeft ?? '0'), parseInt(p.elBottom ?? '0'), floor, p.petName ?? (0, names_1.randomName)(p.petType ?? "cat" /* PetType.cat */));
var newPet = addPetToPanel(p.petType ?? "cat" /* PetType.cat */, basePetUri, p.petColor ?? "brown" /* PetColor.brown */, petSize, parseInt(p.elLeft ?? '0'), parseInt(p.elBottom ?? '0'), floor, p.petName ?? (0, names_1.randomName)(p.petType ?? "cat" /* PetType.cat */), stateApi);
exports.allPets.push(newPet);
recoveryMap.set(newPet.pet, p);
}
Expand Down Expand Up @@ -551,14 +576,25 @@ function randomStartPosition() {
let canvas, ctx;
function initCanvas() {
canvas = document.getElementById('petCanvas');
if (!canvas) {
console.log('Canvas not ready');
return;
}
ctx = canvas.getContext('2d');
if (!ctx) {
console.log('Canvas context not ready');
return;
}
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
}
// It cannot access the main VS Code APIs directly.
function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType, stateApi) {
const ballRadius = calculateBallRadius(petSize);
var floor = 0;
if (!stateApi) {
stateApi = window.acquireVsCodeApi();
}
// Apply Theme backgrounds
const foregroundEl = document.getElementById('foreground');
if (theme !== "none" /* Theme.none */) {
Expand Down Expand Up @@ -590,7 +626,9 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
let then = 0; // last draw
var ballState;
function resetBall() {
canvas.style.display = 'block';
if (canvas) {
canvas.style.display = 'block';
}
ballState = new states_1.BallState(100, 100, 4, 5);
}
function throwBall() {
Expand Down Expand Up @@ -633,16 +671,16 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
}
console.log('Starting pet session', petColor, basePetUri, petType);
// New session
var state = vscode.getState();
var state = stateApi.getState();
if (!state) {
console.log('No state, starting a new session.');
petCounter = 1;
exports.allPets.push(addPetToPanel(petType, basePetUri, petColor, petSize, randomStartPosition(), floor, floor, (0, names_1.randomName)(petType)));
saveState();
exports.allPets.push(addPetToPanel(petType, basePetUri, petColor, petSize, randomStartPosition(), floor, floor, (0, names_1.randomName)(petType), stateApi));
saveState(stateApi);
}
else {
console.log('Recovering state - ', state);
recoverState(basePetUri, petSize, floor);
recoverState(basePetUri, petSize, floor, stateApi);
}
initCanvas();
// Handle messages sent from the extension to the webview
Expand All @@ -659,12 +697,12 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
});
break;
case 'spawn-pet':
exports.allPets.push(addPetToPanel(message.type, basePetUri, message.color, petSize, randomStartPosition(), floor, floor, message.name ?? (0, names_1.randomName)(message.type)));
saveState();
exports.allPets.push(addPetToPanel(message.type, basePetUri, message.color, petSize, randomStartPosition(), floor, floor, message.name ?? (0, names_1.randomName)(message.type), stateApi));
saveState(stateApi);
break;
case 'list-pets':
var pets = exports.allPets.pets();
vscode.postMessage({
stateApi?.postMessage({
command: 'list-pets',
text: pets
.map((pet) => `${pet.type},${pet.pet.name()},${pet.color}`)
Expand All @@ -676,7 +714,7 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
// go through every single
// pet and then print out their name
pets.forEach((pet) => {
vscode.postMessage({
stateApi?.postMessage({
command: 'info',
text: `${pet.pet.emoji()} ${pet.pet.name()} (${pet.color} ${pet.type}): ${pet.pet.hello()}`,
});
Expand All @@ -685,14 +723,14 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
var pet = exports.allPets.locate(message.name);
if (pet) {
exports.allPets.remove(message.name);
saveState();
vscode.postMessage({
saveState(stateApi);
stateApi?.postMessage({
command: 'info',
text: '👋 Removed pet ' + message.name,
});
}
else {
vscode.postMessage({
stateApi?.postMessage({
command: 'error',
text: `Could not find pet ${message.name}`,
});
Expand All @@ -701,11 +739,11 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType) {
case 'reset-pet':
exports.allPets.reset();
petCounter = 0;
saveState();
saveState(stateApi);
break;
case 'pause-pet':
petCounter = 1;
saveState();
saveState(stateApi);
break;
}
});
Expand Down Expand Up @@ -1386,8 +1424,7 @@ class Clippy extends BasePetType {
return '📎';
}
hello() {
// TODO: #188 Add a custom message for clippy
return ` says hello 👋!`;
return ` Hi, I'm Clippy, would you like some assistance today? 👋!`;
}
}
exports.Clippy = Clippy;
Expand Down
42 changes: 17 additions & 25 deletions package-lock.json

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

22 changes: 2 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@
"lint": "eslint src --ext ts && prettier --check src",
"lint:fix": "eslint src --ext ts --fix && prettier --write src",
"test": "node ./out/test/runTest.js",
"test:coverage": "nyc npm run test"
"test:coverage": "COVERAGE=1 node ./out/test/runTest.js"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@rbarilani/remove-source-map-url-webpack-plugin": "^1.1.0",
"@types/glob": "^7.1.3",
"@types/jsdom": "^20.0.0",
Expand All @@ -206,6 +205,7 @@
"glob": "^8.0.3",
"gulp": "^4.0.2",
"jsdom": "^20.0.0",
"jsdom-global": "^3.0.2",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"prettier": "^2.7.1",
Expand All @@ -216,23 +216,5 @@
"vscode-test": "^1.4.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": true,
"all": true,
"include": [
"src/**/!(*.test.*).[tj]s?(x)"
],
"exclude": [
"src/_tests_/**/*.*"
],
"reporter": [
"html",
"lcov",
"text",
"text-summary"
],
"report-dir": "coverage"
}
}
Loading