mirror of
https://github.com/nasa/openmct.git
synced 2025-05-01 00:10:32 +00:00
* refactor: move package.json to type: module this is where the fun begins * chore: move webpack common and prod to esm * chore: move webpack to esm, eslint to explicit cjs * refactor: migrate all files to esm * style: lint * refactor: begin moving karma to cjs, use dynamic esm import * refactor: move index-test to cjs * refactor: begin moving e2e to ESM this was manual. I'm committing this because I'm about to try the `cjstoesm` tool * refactor: move all to esm * fix: make all e2e tests use .js imports * refactor: begin moving exports to esm * refactor: use URL transforms instead of __dirname * fix: use libraryExport: default to properly handle openmct * fix: export all playwright configs as modules * refactor: move all instances of __dirname to import.meta.url * refactor: lint, drop unnecessary URL call * fix: use correct URL path on helper/addNoneditableObject.js * fix: more incorrect URL resolve issues * fix: parse json after reading it
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
import raf from './raf.js';
|
|
|
|
describe('The raf utility function', () => {
|
|
it('Throttles function calls that arrive in quick succession using Request Animation Frame', () => {
|
|
const unthrottledFunction = jasmine.createSpy('unthrottledFunction');
|
|
const throttledCallback = jasmine.createSpy('throttledCallback');
|
|
const throttledFunction = raf(throttledCallback);
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
unthrottledFunction();
|
|
throttledFunction();
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
requestAnimationFrame(resolve);
|
|
}).then(() => {
|
|
expect(unthrottledFunction).toHaveBeenCalledTimes(10);
|
|
expect(throttledCallback).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
it('Only invokes callback once per animation frame', () => {
|
|
const throttledCallback = jasmine.createSpy('throttledCallback');
|
|
const throttledFunction = raf(throttledCallback);
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
throttledFunction();
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
requestAnimationFrame(resolve);
|
|
})
|
|
.then(() => {
|
|
return new Promise((resolve) => {
|
|
requestAnimationFrame(resolve);
|
|
});
|
|
})
|
|
.then(() => {
|
|
expect(throttledCallback).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
it('Invokes callback again if called in subsequent animation frame', () => {
|
|
const throttledCallback = jasmine.createSpy('throttledCallback');
|
|
const throttledFunction = raf(throttledCallback);
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
throttledFunction();
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
requestAnimationFrame(resolve);
|
|
})
|
|
.then(() => {
|
|
for (let i = 0; i < 10; i++) {
|
|
throttledFunction();
|
|
}
|
|
|
|
return new Promise((resolve) => {
|
|
requestAnimationFrame(resolve);
|
|
});
|
|
})
|
|
.then(() => {
|
|
expect(throttledCallback).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|
|
});
|