@jspsych/test-utils 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +92 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -0
- package/dist/index.js +89 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +104 -0
package/dist/index.cjs
CHANGED
|
@@ -50,6 +50,51 @@ function mouseDownMouseUpTarget(target) {
|
|
|
50
50
|
function clickTarget(target) {
|
|
51
51
|
target.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
55
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
56
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
57
|
+
* @param container The DOM element for relative location of the event.
|
|
58
|
+
*/
|
|
59
|
+
function mouseMove(x, y, container) {
|
|
60
|
+
const containerRect = container.getBoundingClientRect();
|
|
61
|
+
const eventInit = {
|
|
62
|
+
clientX: containerRect.x + x,
|
|
63
|
+
clientY: containerRect.y + y,
|
|
64
|
+
bubbles: true,
|
|
65
|
+
};
|
|
66
|
+
container.dispatchEvent(new MouseEvent("mousemove", eventInit));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Dispatch a `mouseup` event, with x and y defined relative to the container element.
|
|
70
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
71
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
72
|
+
* @param container The DOM element for relative location of the event.
|
|
73
|
+
*/
|
|
74
|
+
function mouseUp(x, y, container) {
|
|
75
|
+
const containerRect = container.getBoundingClientRect();
|
|
76
|
+
const eventInit = {
|
|
77
|
+
clientX: containerRect.x + x,
|
|
78
|
+
clientY: containerRect.y + y,
|
|
79
|
+
bubbles: true,
|
|
80
|
+
};
|
|
81
|
+
container.dispatchEvent(new MouseEvent("mouseup", eventInit));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
85
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
86
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
87
|
+
* @param container The DOM element for relative location of the event.
|
|
88
|
+
*/
|
|
89
|
+
function mouseDown(x, y, container) {
|
|
90
|
+
const containerRect = container.getBoundingClientRect();
|
|
91
|
+
const eventInit = {
|
|
92
|
+
clientX: containerRect.x + x,
|
|
93
|
+
clientY: containerRect.y + y,
|
|
94
|
+
bubbles: true,
|
|
95
|
+
};
|
|
96
|
+
container.dispatchEvent(new MouseEvent("mousedown", eventInit));
|
|
97
|
+
}
|
|
53
98
|
/**
|
|
54
99
|
* https://github.com/facebook/jest/issues/2157#issuecomment-279171856
|
|
55
100
|
*/
|
|
@@ -94,6 +139,49 @@ function startTimeline(timeline, jsPsych = {}) {
|
|
|
94
139
|
finished,
|
|
95
140
|
};
|
|
96
141
|
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.
|
|
145
|
+
*
|
|
146
|
+
* @param timeline The timeline that is passed to `jsPsych.run()`
|
|
147
|
+
* @param simulation_mode Either 'data-only' mode or 'visual' mode.
|
|
148
|
+
* @param simulation_options Options to pass to `jsPsych.simulate()`
|
|
149
|
+
* @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If
|
|
150
|
+
* a settings object is passed instead, the settings will be used to create the jsPsych instance.
|
|
151
|
+
*
|
|
152
|
+
* @returns An object containing test helper functions, the jsPsych instance, and the jsPsych
|
|
153
|
+
* display element
|
|
154
|
+
*/
|
|
155
|
+
function simulateTimeline(timeline, simulation_mode = "data-only", simulation_options = {}, jsPsych = {}) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const jsPsychInstance = jsPsych instanceof jspsych.JsPsych ? jsPsych : new jspsych.JsPsych(jsPsych);
|
|
158
|
+
let hasFinished = false;
|
|
159
|
+
const finished = jsPsychInstance
|
|
160
|
+
.simulate(timeline, simulation_mode, simulation_options)
|
|
161
|
+
.then(() => {
|
|
162
|
+
hasFinished = true;
|
|
163
|
+
});
|
|
164
|
+
yield flushPromises();
|
|
165
|
+
const displayElement = jsPsychInstance.getDisplayElement();
|
|
166
|
+
return {
|
|
167
|
+
jsPsych: jsPsychInstance,
|
|
168
|
+
displayElement,
|
|
169
|
+
/** Shorthand for `jsPsych.getDisplayElement().innerHTML` */
|
|
170
|
+
getHTML: () => displayElement.innerHTML,
|
|
171
|
+
/** Shorthand for `jsPsych.data.get()` */
|
|
172
|
+
getData: () => jsPsychInstance.data.get(),
|
|
173
|
+
expectFinished: () => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
yield flushPromises();
|
|
175
|
+
expect(hasFinished).toBe(true);
|
|
176
|
+
}),
|
|
177
|
+
expectRunning: () => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
yield flushPromises();
|
|
179
|
+
expect(hasFinished).toBe(false);
|
|
180
|
+
}),
|
|
181
|
+
/** A promise that is resolved when `jsPsych.simulate()` is done. */
|
|
182
|
+
finished,
|
|
183
|
+
};
|
|
184
|
+
});
|
|
97
185
|
}
|
|
98
186
|
|
|
99
187
|
exports.clickTarget = clickTarget;
|
|
@@ -101,7 +189,11 @@ exports.dispatchEvent = dispatchEvent;
|
|
|
101
189
|
exports.flushPromises = flushPromises;
|
|
102
190
|
exports.keyDown = keyDown;
|
|
103
191
|
exports.keyUp = keyUp;
|
|
192
|
+
exports.mouseDown = mouseDown;
|
|
104
193
|
exports.mouseDownMouseUpTarget = mouseDownMouseUpTarget;
|
|
194
|
+
exports.mouseMove = mouseMove;
|
|
195
|
+
exports.mouseUp = mouseUp;
|
|
105
196
|
exports.pressKey = pressKey;
|
|
197
|
+
exports.simulateTimeline = simulateTimeline;
|
|
106
198
|
exports.startTimeline = startTimeline;
|
|
107
199
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../node_modules/tslib/tslib.es6.js","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import { setImmediate as flushMicroTasks } from \"timers\";\n\nimport { JsPsych } from \"jspsych\";\n\nexport function dispatchEvent(event: Event) {\n document.body.dispatchEvent(event);\n}\n\nexport function keyDown(key: string) {\n dispatchEvent(new KeyboardEvent(\"keydown\", { key }));\n}\n\nexport function keyUp(key: string) {\n dispatchEvent(new KeyboardEvent(\"keyup\", { key }));\n}\n\nexport function pressKey(key: string) {\n keyDown(key);\n keyUp(key);\n}\n\nexport function mouseDownMouseUpTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"mousedown\", { bubbles: true }));\n target.dispatchEvent(new MouseEvent(\"mouseup\", { bubbles: true }));\n}\n\nexport function clickTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"click\", { bubbles: true }));\n}\n\n/**\n * https://github.com/facebook/jest/issues/2157#issuecomment-279171856\n */\nexport function flushPromises() {\n return new Promise((resolve) => flushMicroTasks(resolve));\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.run()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function startTimeline(timeline: any[], jsPsych: JsPsych | any = {}) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance.run(timeline).then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.run()` is done. */\n finished,\n };\n}\n"],"names":["flushMicroTasks","JsPsych"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,E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C,GAAG,EAAE;YACzC,cAAc,EAAE;gBACd,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChC,CAAA;YACD,aAAa,EAAE;gBACb,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACjC,CAAA;;YAED,QAAQ;SACT,CAAC;KACH;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../node_modules/tslib/tslib.es6.js","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import { setImmediate as flushMicroTasks } from \"timers\";\n\nimport { JsPsych } from \"jspsych\";\n\nexport function dispatchEvent(event: Event) {\n document.body.dispatchEvent(event);\n}\n\nexport function keyDown(key: string) {\n dispatchEvent(new KeyboardEvent(\"keydown\", { key }));\n}\n\nexport function keyUp(key: string) {\n dispatchEvent(new KeyboardEvent(\"keyup\", { key }));\n}\n\nexport function pressKey(key: string) {\n keyDown(key);\n keyUp(key);\n}\n\nexport function mouseDownMouseUpTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"mousedown\", { bubbles: true }));\n target.dispatchEvent(new MouseEvent(\"mouseup\", { bubbles: true }));\n}\n\nexport function clickTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"click\", { bubbles: true }));\n}\n\n/**\n * Dispatch a `mousemove` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseMove(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mousemove\", eventInit));\n}\n\n/**\n * Dispatch a `mouseup` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseUp(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mouseup\", eventInit));\n}\n\n/**\n * Dispatch a `mousemove` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseDown(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mousedown\", eventInit));\n}\n\n/**\n * https://github.com/facebook/jest/issues/2157#issuecomment-279171856\n */\nexport function flushPromises() {\n return new Promise((resolve) => flushMicroTasks(resolve));\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.run()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function startTimeline(timeline: any[], jsPsych: JsPsych | any = {}) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance.run(timeline).then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.run()` is done. */\n finished,\n };\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param simulation_mode Either 'data-only' mode or 'visual' mode.\n * @param simulation_options Options to pass to `jsPsych.simulate()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function simulateTimeline(\n timeline: any[],\n simulation_mode: \"data-only\" | \"visual\" = \"data-only\",\n simulation_options: any = {},\n jsPsych: JsPsych | any = {}\n) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance\n .simulate(timeline, simulation_mode, simulation_options)\n .then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.simulate()` is done. */\n finished,\n };\n}\n"],"names":["flushMicroTasks","JsPsych"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACnG,QAAQ,SAAS,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,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AAC,QAAQ,EAAE,eAAe,EAAE,kBAAkB,CAAC;aACvD,IAAI,CAAC;YACJ,WAAW,GAAG,IAAI,CAAC;SACpB,CAAC,CAAC;QACL,MAAM,aAAa,EAAE,CAAC;QAEtB,MAAM,cAAc,GAAG,eAAe,CAAC,iBAAiB,EAAE,CAAC;QAE3D,OAAO;YACL,OAAO,EAAE,eAAe;YACxB,cAAc;;YAEd,OAAO,EAAE,MAAM,cAAc,CAAC,SAAS;;YAEvC,OAAO,EAAE,MAAM,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;YACzC,cAAc,EAAE;gBACd,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChC,CAAA;YACD,aAAa,EAAE;gBACb,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACjC,CAAA;;YAED,QAAQ;SACT,CAAC;KACH;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,27 @@ export declare function keyUp(key: string): void;
|
|
|
5
5
|
export declare function pressKey(key: string): void;
|
|
6
6
|
export declare function mouseDownMouseUpTarget(target: Element): void;
|
|
7
7
|
export declare function clickTarget(target: Element): void;
|
|
8
|
+
/**
|
|
9
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
10
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
11
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
12
|
+
* @param container The DOM element for relative location of the event.
|
|
13
|
+
*/
|
|
14
|
+
export declare function mouseMove(x: number, y: number, container: Element): void;
|
|
15
|
+
/**
|
|
16
|
+
* Dispatch a `mouseup` event, with x and y defined relative to the container element.
|
|
17
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
18
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
19
|
+
* @param container The DOM element for relative location of the event.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mouseUp(x: number, y: number, container: Element): void;
|
|
22
|
+
/**
|
|
23
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
24
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
25
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
26
|
+
* @param container The DOM element for relative location of the event.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mouseDown(x: number, y: number, container: Element): void;
|
|
8
29
|
/**
|
|
9
30
|
* https://github.com/facebook/jest/issues/2157#issuecomment-279171856
|
|
10
31
|
*/
|
|
@@ -31,3 +52,27 @@ export declare function startTimeline(timeline: any[], jsPsych?: JsPsych | any):
|
|
|
31
52
|
/** A promise that is resolved when `jsPsych.run()` is done. */
|
|
32
53
|
finished: Promise<void>;
|
|
33
54
|
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.
|
|
57
|
+
*
|
|
58
|
+
* @param timeline The timeline that is passed to `jsPsych.run()`
|
|
59
|
+
* @param simulation_mode Either 'data-only' mode or 'visual' mode.
|
|
60
|
+
* @param simulation_options Options to pass to `jsPsych.simulate()`
|
|
61
|
+
* @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If
|
|
62
|
+
* a settings object is passed instead, the settings will be used to create the jsPsych instance.
|
|
63
|
+
*
|
|
64
|
+
* @returns An object containing test helper functions, the jsPsych instance, and the jsPsych
|
|
65
|
+
* display element
|
|
66
|
+
*/
|
|
67
|
+
export declare function simulateTimeline(timeline: any[], simulation_mode?: "data-only" | "visual", simulation_options?: any, jsPsych?: JsPsych | any): Promise<{
|
|
68
|
+
jsPsych: JsPsych;
|
|
69
|
+
displayElement: HTMLElement;
|
|
70
|
+
/** Shorthand for `jsPsych.getDisplayElement().innerHTML` */
|
|
71
|
+
getHTML: () => string;
|
|
72
|
+
/** Shorthand for `jsPsych.data.get()` */
|
|
73
|
+
getData: () => import("jspsych/dist/modules/data/DataCollection").DataCollection;
|
|
74
|
+
expectFinished: () => Promise<void>;
|
|
75
|
+
expectRunning: () => Promise<void>;
|
|
76
|
+
/** A promise that is resolved when `jsPsych.simulate()` is done. */
|
|
77
|
+
finished: Promise<void>;
|
|
78
|
+
}>;
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,51 @@ function mouseDownMouseUpTarget(target) {
|
|
|
46
46
|
function clickTarget(target) {
|
|
47
47
|
target.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
51
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
52
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
53
|
+
* @param container The DOM element for relative location of the event.
|
|
54
|
+
*/
|
|
55
|
+
function mouseMove(x, y, container) {
|
|
56
|
+
const containerRect = container.getBoundingClientRect();
|
|
57
|
+
const eventInit = {
|
|
58
|
+
clientX: containerRect.x + x,
|
|
59
|
+
clientY: containerRect.y + y,
|
|
60
|
+
bubbles: true,
|
|
61
|
+
};
|
|
62
|
+
container.dispatchEvent(new MouseEvent("mousemove", eventInit));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Dispatch a `mouseup` event, with x and y defined relative to the container element.
|
|
66
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
67
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
68
|
+
* @param container The DOM element for relative location of the event.
|
|
69
|
+
*/
|
|
70
|
+
function mouseUp(x, y, container) {
|
|
71
|
+
const containerRect = container.getBoundingClientRect();
|
|
72
|
+
const eventInit = {
|
|
73
|
+
clientX: containerRect.x + x,
|
|
74
|
+
clientY: containerRect.y + y,
|
|
75
|
+
bubbles: true,
|
|
76
|
+
};
|
|
77
|
+
container.dispatchEvent(new MouseEvent("mouseup", eventInit));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
81
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
82
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
83
|
+
* @param container The DOM element for relative location of the event.
|
|
84
|
+
*/
|
|
85
|
+
function mouseDown(x, y, container) {
|
|
86
|
+
const containerRect = container.getBoundingClientRect();
|
|
87
|
+
const eventInit = {
|
|
88
|
+
clientX: containerRect.x + x,
|
|
89
|
+
clientY: containerRect.y + y,
|
|
90
|
+
bubbles: true,
|
|
91
|
+
};
|
|
92
|
+
container.dispatchEvent(new MouseEvent("mousedown", eventInit));
|
|
93
|
+
}
|
|
49
94
|
/**
|
|
50
95
|
* https://github.com/facebook/jest/issues/2157#issuecomment-279171856
|
|
51
96
|
*/
|
|
@@ -90,7 +135,50 @@ function startTimeline(timeline, jsPsych = {}) {
|
|
|
90
135
|
finished,
|
|
91
136
|
};
|
|
92
137
|
});
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.
|
|
141
|
+
*
|
|
142
|
+
* @param timeline The timeline that is passed to `jsPsych.run()`
|
|
143
|
+
* @param simulation_mode Either 'data-only' mode or 'visual' mode.
|
|
144
|
+
* @param simulation_options Options to pass to `jsPsych.simulate()`
|
|
145
|
+
* @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If
|
|
146
|
+
* a settings object is passed instead, the settings will be used to create the jsPsych instance.
|
|
147
|
+
*
|
|
148
|
+
* @returns An object containing test helper functions, the jsPsych instance, and the jsPsych
|
|
149
|
+
* display element
|
|
150
|
+
*/
|
|
151
|
+
function simulateTimeline(timeline, simulation_mode = "data-only", simulation_options = {}, jsPsych = {}) {
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);
|
|
154
|
+
let hasFinished = false;
|
|
155
|
+
const finished = jsPsychInstance
|
|
156
|
+
.simulate(timeline, simulation_mode, simulation_options)
|
|
157
|
+
.then(() => {
|
|
158
|
+
hasFinished = true;
|
|
159
|
+
});
|
|
160
|
+
yield flushPromises();
|
|
161
|
+
const displayElement = jsPsychInstance.getDisplayElement();
|
|
162
|
+
return {
|
|
163
|
+
jsPsych: jsPsychInstance,
|
|
164
|
+
displayElement,
|
|
165
|
+
/** Shorthand for `jsPsych.getDisplayElement().innerHTML` */
|
|
166
|
+
getHTML: () => displayElement.innerHTML,
|
|
167
|
+
/** Shorthand for `jsPsych.data.get()` */
|
|
168
|
+
getData: () => jsPsychInstance.data.get(),
|
|
169
|
+
expectFinished: () => __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
yield flushPromises();
|
|
171
|
+
expect(hasFinished).toBe(true);
|
|
172
|
+
}),
|
|
173
|
+
expectRunning: () => __awaiter(this, void 0, void 0, function* () {
|
|
174
|
+
yield flushPromises();
|
|
175
|
+
expect(hasFinished).toBe(false);
|
|
176
|
+
}),
|
|
177
|
+
/** A promise that is resolved when `jsPsych.simulate()` is done. */
|
|
178
|
+
finished,
|
|
179
|
+
};
|
|
180
|
+
});
|
|
93
181
|
}
|
|
94
182
|
|
|
95
|
-
export { clickTarget, dispatchEvent, flushPromises, keyDown, keyUp, mouseDownMouseUpTarget, pressKey, startTimeline };
|
|
183
|
+
export { clickTarget, dispatchEvent, flushPromises, keyDown, keyUp, mouseDown, mouseDownMouseUpTarget, mouseMove, mouseUp, pressKey, simulateTimeline, startTimeline };
|
|
96
184
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../node_modules/tslib/tslib.es6.js","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import { setImmediate as flushMicroTasks } from \"timers\";\n\nimport { JsPsych } from \"jspsych\";\n\nexport function dispatchEvent(event: Event) {\n document.body.dispatchEvent(event);\n}\n\nexport function keyDown(key: string) {\n dispatchEvent(new KeyboardEvent(\"keydown\", { key }));\n}\n\nexport function keyUp(key: string) {\n dispatchEvent(new KeyboardEvent(\"keyup\", { key }));\n}\n\nexport function pressKey(key: string) {\n keyDown(key);\n keyUp(key);\n}\n\nexport function mouseDownMouseUpTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"mousedown\", { bubbles: true }));\n target.dispatchEvent(new MouseEvent(\"mouseup\", { bubbles: true }));\n}\n\nexport function clickTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"click\", { bubbles: true }));\n}\n\n/**\n * https://github.com/facebook/jest/issues/2157#issuecomment-279171856\n */\nexport function flushPromises() {\n return new Promise((resolve) => flushMicroTasks(resolve));\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.run()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function startTimeline(timeline: any[], jsPsych: JsPsych | any = {}) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance.run(timeline).then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.run()` is done. */\n finished,\n };\n}\n"],"names":["flushMicroTasks"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,E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"version":3,"file":"index.js","sources":["../../../node_modules/tslib/tslib.es6.js","../src/index.ts"],"sourcesContent":["/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n","import { setImmediate as flushMicroTasks } from \"timers\";\n\nimport { JsPsych } from \"jspsych\";\n\nexport function dispatchEvent(event: Event) {\n document.body.dispatchEvent(event);\n}\n\nexport function keyDown(key: string) {\n dispatchEvent(new KeyboardEvent(\"keydown\", { key }));\n}\n\nexport function keyUp(key: string) {\n dispatchEvent(new KeyboardEvent(\"keyup\", { key }));\n}\n\nexport function pressKey(key: string) {\n keyDown(key);\n keyUp(key);\n}\n\nexport function mouseDownMouseUpTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"mousedown\", { bubbles: true }));\n target.dispatchEvent(new MouseEvent(\"mouseup\", { bubbles: true }));\n}\n\nexport function clickTarget(target: Element) {\n target.dispatchEvent(new MouseEvent(\"click\", { bubbles: true }));\n}\n\n/**\n * Dispatch a `mousemove` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseMove(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mousemove\", eventInit));\n}\n\n/**\n * Dispatch a `mouseup` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseUp(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mouseup\", eventInit));\n}\n\n/**\n * Dispatch a `mousemove` event, with x and y defined relative to the container element.\n * @param x The x location of the event, relative to the x location of `container`.\n * @param y The y location of the event, relative to the y location of `container`.\n * @param container The DOM element for relative location of the event.\n */\nexport function mouseDown(x: number, y: number, container: Element) {\n const containerRect = container.getBoundingClientRect();\n\n const eventInit = {\n clientX: containerRect.x + x,\n clientY: containerRect.y + y,\n bubbles: true,\n };\n\n container.dispatchEvent(new MouseEvent(\"mousedown\", eventInit));\n}\n\n/**\n * https://github.com/facebook/jest/issues/2157#issuecomment-279171856\n */\nexport function flushPromises() {\n return new Promise((resolve) => flushMicroTasks(resolve));\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.run()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function startTimeline(timeline: any[], jsPsych: JsPsych | any = {}) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance.run(timeline).then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.run()` is done. */\n finished,\n };\n}\n\n/**\n * Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.\n *\n * @param timeline The timeline that is passed to `jsPsych.run()`\n * @param simulation_mode Either 'data-only' mode or 'visual' mode.\n * @param simulation_options Options to pass to `jsPsych.simulate()`\n * @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If\n * a settings object is passed instead, the settings will be used to create the jsPsych instance.\n *\n * @returns An object containing test helper functions, the jsPsych instance, and the jsPsych\n * display element\n */\nexport async function simulateTimeline(\n timeline: any[],\n simulation_mode: \"data-only\" | \"visual\" = \"data-only\",\n simulation_options: any = {},\n jsPsych: JsPsych | any = {}\n) {\n const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);\n\n let hasFinished = false;\n const finished = jsPsychInstance\n .simulate(timeline, simulation_mode, simulation_options)\n .then(() => {\n hasFinished = true;\n });\n await flushPromises();\n\n const displayElement = jsPsychInstance.getDisplayElement();\n\n return {\n jsPsych: jsPsychInstance,\n displayElement,\n /** Shorthand for `jsPsych.getDisplayElement().innerHTML` */\n getHTML: () => displayElement.innerHTML,\n /** Shorthand for `jsPsych.data.get()` */\n getData: () => jsPsychInstance.data.get(),\n expectFinished: async () => {\n await flushPromises();\n expect(hasFinished).toBe(true);\n },\n expectRunning: async () => {\n await flushPromises();\n expect(hasFinished).toBe(false);\n },\n /** A promise that is resolved when `jsPsych.simulate()` is done. */\n finished,\n };\n}\n"],"names":["flushMicroTasks"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAuDA;AACO,SAAS,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,EAAE,SAAS,EAAE;AAC7D,IAAI,SAAS,KAAK,CAAC,KAAK,EAAE,EAAE,OAAO,KAAK,YAAY,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,CAAC,UAAU,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;AAChH,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,EAAE,UAAU,OAAO,EAAE,MAAM,EAAE;AAC/D,QAAQ,SAAS,SAAS,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACnG,QAAQ,SAAS,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE;AACtG,QAAQ,SAAS,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,EAAE;AACtH,QAAQ,IAAI,CAAC,CAAC,SAAS,GAAG,S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AE;YACzC,cAAc,EAAE;gBACd,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;aAChC,CAAA;YACD,aAAa,EAAE;gBACb,MAAM,aAAa,EAAE,CAAC;gBACtB,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aACjC,CAAA;;YAED,QAAQ;SACT,CAAC;KACH;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jspsych/test-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Test utility functions for jsPsych-related test cases",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"jspsych": ">=7.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@jspsych/config": "^1.
|
|
36
|
+
"@jspsych/config": "^1.1.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,60 @@ export function clickTarget(target: Element) {
|
|
|
28
28
|
target.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
33
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
34
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
35
|
+
* @param container The DOM element for relative location of the event.
|
|
36
|
+
*/
|
|
37
|
+
export function mouseMove(x: number, y: number, container: Element) {
|
|
38
|
+
const containerRect = container.getBoundingClientRect();
|
|
39
|
+
|
|
40
|
+
const eventInit = {
|
|
41
|
+
clientX: containerRect.x + x,
|
|
42
|
+
clientY: containerRect.y + y,
|
|
43
|
+
bubbles: true,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
container.dispatchEvent(new MouseEvent("mousemove", eventInit));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Dispatch a `mouseup` event, with x and y defined relative to the container element.
|
|
51
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
52
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
53
|
+
* @param container The DOM element for relative location of the event.
|
|
54
|
+
*/
|
|
55
|
+
export function mouseUp(x: number, y: number, container: Element) {
|
|
56
|
+
const containerRect = container.getBoundingClientRect();
|
|
57
|
+
|
|
58
|
+
const eventInit = {
|
|
59
|
+
clientX: containerRect.x + x,
|
|
60
|
+
clientY: containerRect.y + y,
|
|
61
|
+
bubbles: true,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
container.dispatchEvent(new MouseEvent("mouseup", eventInit));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Dispatch a `mousemove` event, with x and y defined relative to the container element.
|
|
69
|
+
* @param x The x location of the event, relative to the x location of `container`.
|
|
70
|
+
* @param y The y location of the event, relative to the y location of `container`.
|
|
71
|
+
* @param container The DOM element for relative location of the event.
|
|
72
|
+
*/
|
|
73
|
+
export function mouseDown(x: number, y: number, container: Element) {
|
|
74
|
+
const containerRect = container.getBoundingClientRect();
|
|
75
|
+
|
|
76
|
+
const eventInit = {
|
|
77
|
+
clientX: containerRect.x + x,
|
|
78
|
+
clientY: containerRect.y + y,
|
|
79
|
+
bubbles: true,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
container.dispatchEvent(new MouseEvent("mousedown", eventInit));
|
|
83
|
+
}
|
|
84
|
+
|
|
31
85
|
/**
|
|
32
86
|
* https://github.com/facebook/jest/issues/2157#issuecomment-279171856
|
|
33
87
|
*/
|
|
@@ -75,3 +129,53 @@ export async function startTimeline(timeline: any[], jsPsych: JsPsych | any = {}
|
|
|
75
129
|
finished,
|
|
76
130
|
};
|
|
77
131
|
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Runs the given timeline by calling `jsPsych.simulate()` on the provided JsPsych object.
|
|
135
|
+
*
|
|
136
|
+
* @param timeline The timeline that is passed to `jsPsych.run()`
|
|
137
|
+
* @param simulation_mode Either 'data-only' mode or 'visual' mode.
|
|
138
|
+
* @param simulation_options Options to pass to `jsPsych.simulate()`
|
|
139
|
+
* @param jsPsych The jsPsych instance to be used. If left empty, a new instance will be created. If
|
|
140
|
+
* a settings object is passed instead, the settings will be used to create the jsPsych instance.
|
|
141
|
+
*
|
|
142
|
+
* @returns An object containing test helper functions, the jsPsych instance, and the jsPsych
|
|
143
|
+
* display element
|
|
144
|
+
*/
|
|
145
|
+
export async function simulateTimeline(
|
|
146
|
+
timeline: any[],
|
|
147
|
+
simulation_mode: "data-only" | "visual" = "data-only",
|
|
148
|
+
simulation_options: any = {},
|
|
149
|
+
jsPsych: JsPsych | any = {}
|
|
150
|
+
) {
|
|
151
|
+
const jsPsychInstance = jsPsych instanceof JsPsych ? jsPsych : new JsPsych(jsPsych);
|
|
152
|
+
|
|
153
|
+
let hasFinished = false;
|
|
154
|
+
const finished = jsPsychInstance
|
|
155
|
+
.simulate(timeline, simulation_mode, simulation_options)
|
|
156
|
+
.then(() => {
|
|
157
|
+
hasFinished = true;
|
|
158
|
+
});
|
|
159
|
+
await flushPromises();
|
|
160
|
+
|
|
161
|
+
const displayElement = jsPsychInstance.getDisplayElement();
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
jsPsych: jsPsychInstance,
|
|
165
|
+
displayElement,
|
|
166
|
+
/** Shorthand for `jsPsych.getDisplayElement().innerHTML` */
|
|
167
|
+
getHTML: () => displayElement.innerHTML,
|
|
168
|
+
/** Shorthand for `jsPsych.data.get()` */
|
|
169
|
+
getData: () => jsPsychInstance.data.get(),
|
|
170
|
+
expectFinished: async () => {
|
|
171
|
+
await flushPromises();
|
|
172
|
+
expect(hasFinished).toBe(true);
|
|
173
|
+
},
|
|
174
|
+
expectRunning: async () => {
|
|
175
|
+
await flushPromises();
|
|
176
|
+
expect(hasFinished).toBe(false);
|
|
177
|
+
},
|
|
178
|
+
/** A promise that is resolved when `jsPsych.simulate()` is done. */
|
|
179
|
+
finished,
|
|
180
|
+
};
|
|
181
|
+
}
|