Merge pull request 'Fix #34: Motion error' (#37) from ai/issue-34 into master
All checks were successful
Test / test (push) Successful in 2s
Build and Deploy Nuxt / build (push) Successful in 57s

Reviewed-on: #37
This commit was merged in pull request #37.
This commit is contained in:
2026-10-14 17:56:20 +00:00
2 changed files with 77 additions and 2 deletions

View File

@@ -19,7 +19,7 @@ function ShowTooltip(){
animate(tooltip, { animate(tooltip, {
opacity: [0, 1], opacity: [0, 1],
translateY: [20, 0] translateY: [20, 0]
}, {duration: 0.1, ease: 'ease-out'}); }, {duration: 0.1, ease: 'easeOut'});
showed = true; showed = true;
hided = false; hided = false;
} }
@@ -33,7 +33,7 @@ function HideTooltip(){
animate(tooltip, { animate(tooltip, {
opacity: [1, 0], opacity: [1, 0],
translateY: [0, 20] translateY: [0, 20]
}, {duration: 0.1, ease: 'ease-in'}).finished.then(() => tooltip.style.display = "none") }, {duration: 0.1, ease: 'easeIn'}).finished.then(() => tooltip.style.display = "none")
hided = true; hided = true;
showed = false; showed = false;
} }

View File

@@ -0,0 +1,75 @@
// Tests for the motion error of Syndria98/dragonroll#34: the tooltip animated itself with
// `ease: 'ease-in'`, and motion throws `Invalid easing type 'ease-in'` on that. Motion's easing
// options are its own names (`easeIn`, `easeOut`, ...), not the CSS keywords, so every string ease
// option in the frontend has to be one of the names motion accepts.
//
// `frontend/app/services/Tooltip.js` imports `vue` and `motion` and the repository root installs no
// dependencies, so the checks read the sources the way `tests/map-viewer.test.js` reads them.
//
// Run with `npm test` from the repository root, or `node --test tests/`.
const { test } = require("node:test");
const assert = require("node:assert/strict");
const fs = require("node:fs");
const path = require("node:path");
// The strings motion accepts for `ease` (https://motion.dev/troubleshooting/invalid-easing-type).
const VALID_EASINGS = [
"linear",
"easeIn",
"easeInOut",
"easeOut",
"circIn",
"circInOut",
"circOut",
"backIn",
"backInOut",
"backOut",
"anticipate",
];
function frontendSources(dir = path.join(__dirname, "..", "frontend", "app")) {
const found = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) found.push(...frontendSources(full));
else if (/\.(js|ts|vue)$/.test(entry.name)) found.push({ file: full, source: fs.readFileSync(full, "utf8") });
}
return found;
}
// An ease option is the `ease` key of a JS object (motion's options), so it is always quoted. CSS
// `transition: ... ease` declarations have no colon after `ease` and never match.
function easeOptions(source) {
return [...source.matchAll(/\bease:\s*(['"])([^'"]*)\1/g)].map((match) => match[2]);
}
function readTooltip() {
return fs.readFileSync(
path.join(__dirname, "..", "frontend", "app", "services", "Tooltip.js"),
"utf8"
);
}
test("the tooltip keeps animating itself in and out", () => {
const ease = easeOptions(readTooltip());
// Guards the checks below against silently matching nothing.
assert.equal(ease.length, 2, `expected the show and the hide ease option, found ${ease.length}`);
});
test("the tooltip options use easing names motion accepts", () => {
for (const value of easeOptions(readTooltip())) {
assert.ok(VALID_EASINGS.includes(value), `invalid easing type '${value}'`);
}
});
test("no frontend animation uses a CSS keyword as motion easing", () => {
for (const { file, source } of frontendSources()) {
for (const value of easeOptions(source)) {
assert.ok(
VALID_EASINGS.includes(value),
`${path.relative(path.join(__dirname, ".."), file)} uses invalid easing type '${value}'`
);
}
}
});