mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
Merge branch 'main' into remove-canvas-dependency-from-config
This commit is contained in:
commit
54e6561638
6
.changeset/rich-fans-jump.md
Normal file
6
.changeset/rich-fans-jump.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"jspsych": patch
|
||||||
|
"@jspsych/config": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Patches some edge cases for `getCitations` and the build process that reads CITATION.CFF files to include citation info
|
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@ -1,11 +1,13 @@
|
|||||||
name: build
|
name: build
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, reopened, ready_for_review, review_requested]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
name: Build, lint, and test on Node.js ${{ matrix.node }}
|
name: Build, lint, and test on Node.js ${{ matrix.node }}
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
|
7874
package-lock.json
generated
7874
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,6 @@ import path from "node:path";
|
|||||||
|
|
||||||
import { Cite } from "@citation-js/core";
|
import { Cite } from "@citation-js/core";
|
||||||
import appRootPath from "app-root-path";
|
import appRootPath from "app-root-path";
|
||||||
import yaml from "yaml";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate citation data from CITATION.cff file
|
* Generate citation data from CITATION.cff file
|
||||||
@ -23,11 +22,8 @@ export default function generateCitations() {
|
|||||||
let rawCff;
|
let rawCff;
|
||||||
const getCff = (path) => {
|
const getCff = (path) => {
|
||||||
rawCff = fs.readFileSync(path, "utf-8").toString();
|
rawCff = fs.readFileSync(path, "utf-8").toString();
|
||||||
const cffData = yaml.parse(rawCff);
|
preferredCitation = rawCff.includes("preferred-citation:");
|
||||||
if (cffData["preferred-citation"]) {
|
return rawCff;
|
||||||
preferredCitation = true;
|
|
||||||
}
|
|
||||||
return yaml.stringify(rawCff);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -80,7 +76,7 @@ export default function generateCitations() {
|
|||||||
return citationBibtex;
|
return citationBibtex;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error converting CITATION.cff to BibTeX string: ${error.message}`);
|
console.log(`Error converting CITATION.cff to BibTeX string: ${error.message}`);
|
||||||
return null;
|
return "";
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
1
packages/config/jest.config.cjs
Normal file
1
packages/config/jest.config.cjs
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require("./jest.cjs").makePackageConfig(__dirname);
|
@ -3,6 +3,10 @@
|
|||||||
"version": "3.2.1",
|
"version": "3.2.1",
|
||||||
"description": "Shared (build) configuration for jsPsych packages",
|
"description": "Shared (build) configuration for jsPsych packages",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "npm test -- --watch"
|
||||||
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
"./gulp": {
|
"./gulp": {
|
||||||
"import": "./gulp.js",
|
"import": "./gulp.js",
|
||||||
@ -45,6 +49,7 @@
|
|||||||
"@sucrase/jest-plugin": "3.0.0",
|
"@sucrase/jest-plugin": "3.0.0",
|
||||||
"@types/gulp": "4.0.17",
|
"@types/gulp": "4.0.17",
|
||||||
"@types/jest": "29.5.8",
|
"@types/jest": "29.5.8",
|
||||||
|
"@types/node": "^22.10.10",
|
||||||
"alias-hq": "6.2.4",
|
"alias-hq": "6.2.4",
|
||||||
"app-root-path": "^3.1.0",
|
"app-root-path": "^3.1.0",
|
||||||
"esbuild": "0.23.1",
|
"esbuild": "0.23.1",
|
||||||
@ -66,7 +71,6 @@
|
|||||||
"rollup-plugin-node-externals": "7.1.3",
|
"rollup-plugin-node-externals": "7.1.3",
|
||||||
"sucrase": "3.34.0",
|
"sucrase": "3.34.0",
|
||||||
"tslib": "2.6.2",
|
"tslib": "2.6.2",
|
||||||
"typescript": "^5.7.0",
|
"typescript": "^5.7.0"
|
||||||
"yaml": "^2.5.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
94
packages/config/tests/generateCitations.test.js
Normal file
94
packages/config/tests/generateCitations.test.js
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import fs from "node:fs";
|
||||||
|
|
||||||
|
import generateCitations from "../generateCitations";
|
||||||
|
|
||||||
|
// Mock filesystem
|
||||||
|
jest.mock("node:fs");
|
||||||
|
jest.mock("app-root-path", () => ({
|
||||||
|
path: "/mock/root/path",
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("generateCitations", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
const validCitationCff = `
|
||||||
|
cff-version: 1.2.0
|
||||||
|
message: Please cite this software using these metadata
|
||||||
|
title: Test Software
|
||||||
|
authors:
|
||||||
|
- family-names: Doe
|
||||||
|
given-names: John
|
||||||
|
version: 1.0.0
|
||||||
|
date-released: 2023-01-01
|
||||||
|
`;
|
||||||
|
|
||||||
|
const citationCffWithPreferred = `
|
||||||
|
cff-version: 1.2.0
|
||||||
|
message: Please cite this software using these metadata
|
||||||
|
title: Test Software
|
||||||
|
authors:
|
||||||
|
- family-names: Doe
|
||||||
|
given-names: John
|
||||||
|
preferred-citation:
|
||||||
|
title: Preferred Citation
|
||||||
|
authors:
|
||||||
|
- family-names: Smith
|
||||||
|
given-names: Jane
|
||||||
|
`;
|
||||||
|
|
||||||
|
test("should generate citations when CITATION.cff exists in current directory", () => {
|
||||||
|
fs.readFileSync.mockReturnValue(validCitationCff);
|
||||||
|
|
||||||
|
const result = generateCitations();
|
||||||
|
|
||||||
|
expect(result).toHaveProperty("apa");
|
||||||
|
expect(result).toHaveProperty("bibtex");
|
||||||
|
expect(result.apa).not.toBe("");
|
||||||
|
expect(result.bibtex).not.toBe("");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle preferred-citation when present", () => {
|
||||||
|
fs.readFileSync.mockReturnValue(citationCffWithPreferred);
|
||||||
|
|
||||||
|
const result = generateCitations();
|
||||||
|
|
||||||
|
expect(result).toHaveProperty("apa");
|
||||||
|
expect(result).toHaveProperty("bibtex");
|
||||||
|
expect(result.apa.includes("Smith")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should return empty strings when CITATION.cff is not found", () => {
|
||||||
|
fs.readFileSync.mockImplementation(() => {
|
||||||
|
throw new Error("File not found");
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = generateCitations();
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
apa: "",
|
||||||
|
bibtex: "",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should handle malformed CITATION.cff", () => {
|
||||||
|
fs.readFileSync.mockReturnValue("invalid: yaml: content:");
|
||||||
|
|
||||||
|
const result = generateCitations();
|
||||||
|
|
||||||
|
expect(result).toEqual({
|
||||||
|
apa: "",
|
||||||
|
bibtex: "",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should remove newlines from citations", () => {
|
||||||
|
fs.readFileSync.mockReturnValue(validCitationCff);
|
||||||
|
|
||||||
|
const result = generateCitations();
|
||||||
|
|
||||||
|
expect(result.apa).not.toMatch(/\n/);
|
||||||
|
expect(result.bibtex).not.toMatch(/\n/);
|
||||||
|
});
|
||||||
|
});
|
@ -36,6 +36,9 @@ export class JsPsych {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
|
private citation: any = '__CITATIONS__';
|
||||||
|
|
||||||
/** Options */
|
/** Options */
|
||||||
private options: any = {};
|
private options: any = {};
|
||||||
|
|
||||||
@ -274,8 +277,6 @@ export class JsPsych {
|
|||||||
format: "apa" | "bibtex" = "apa"
|
format: "apa" | "bibtex" = "apa"
|
||||||
) {
|
) {
|
||||||
const formatOptions = ["apa", "bibtex"];
|
const formatOptions = ["apa", "bibtex"];
|
||||||
// prettier-ignore
|
|
||||||
const jsPsychCitations: any = '__CITATIONS__';
|
|
||||||
format = format.toLowerCase() as "apa" | "bibtex";
|
format = format.toLowerCase() as "apa" | "bibtex";
|
||||||
// Check if plugins is an array
|
// Check if plugins is an array
|
||||||
if (!Array.isArray(plugins)) {
|
if (!Array.isArray(plugins)) {
|
||||||
@ -287,7 +288,7 @@ export class JsPsych {
|
|||||||
}
|
}
|
||||||
// Print citations
|
// Print citations
|
||||||
else {
|
else {
|
||||||
const jsPsychCitation = jsPsychCitations[format];
|
const jsPsychCitation = this.citation[format];
|
||||||
const citationSet = new Set([jsPsychCitation]);
|
const citationSet = new Set([jsPsychCitation]);
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (const plugin of plugins) {
|
||||||
|
@ -1,32 +1,24 @@
|
|||||||
|
import { initJsPsych } from "../../src";
|
||||||
import { TestExtension } from "../extensions/TestExtension";
|
import { TestExtension } from "../extensions/TestExtension";
|
||||||
import TestPlugin from "../TestPlugin";
|
import TestPlugin from "../TestPlugin";
|
||||||
|
|
||||||
const jsPsychApaCitation =
|
const jsPsychApaCitation = "Test base APA citation";
|
||||||
"de Leeuw, J. R., Gilbert, R. A., & Luchterhandt, B. (2023). jsPsych: Enabling an Open-Source Collaborative Ecosystem of Behavioral Experiments. Journal of Open Source Software, 8(85), 5351. https://doi.org/10.21105/joss.05351 ";
|
const jsPsychBibtexCitation = "Test base BibTeX citation";
|
||||||
const jsPsychBibtexCitation =
|
|
||||||
'@article{Leeuw2023jsPsych, author = {de Leeuw, Joshua R. and Gilbert, Rebecca A. and Luchterhandt, Bj{\\" o}rn}, journal = {Journal of Open Source Software}, doi = {10.21105/joss.05351}, issn = {2475-9066}, number = {85}, year = {2023}, month = {may 11}, pages = {5351}, publisher = {Open Journals}, title = {jsPsych: Enabling an {Open}-{Source} {Collaborative} {Ecosystem} of {Behavioral} {Experiments}}, url = {https://joss.theoj.org/papers/10.21105/joss.05351}, volume = {8}, } ';
|
|
||||||
const testPluginApaCitation = "Test plugin APA citation";
|
const testPluginApaCitation = "Test plugin APA citation";
|
||||||
const testPluginBibtexCitation = "Test plugin BibTeX citation";
|
const testPluginBibtexCitation = "Test plugin BibTeX citation";
|
||||||
const testExtensionApaCitation = "Test extension APA citation";
|
const testExtensionApaCitation = "Test extension APA citation";
|
||||||
|
|
||||||
let JsPsych;
|
let jspsych;
|
||||||
|
|
||||||
/**
|
beforeEach(() => {
|
||||||
* These tests are skipped if the built version of JsPsych is not found.
|
jspsych = initJsPsych();
|
||||||
* This is because the citation functionality is only available in the built version
|
(jspsych as any).citation = {
|
||||||
* due to code injections that run during the build.
|
apa: "Test base APA citation",
|
||||||
*/
|
bibtex: "Test base BibTeX citation",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
describe("citing not using an array", () => {
|
||||||
// Try to import built version
|
|
||||||
JsPsych = require("../../dist/index").JsPsych;
|
|
||||||
let jspsych: typeof JsPsych;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
jspsych = new JsPsych();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("citing not using an array", () => {
|
|
||||||
test("citing without input", () => {
|
test("citing without input", () => {
|
||||||
expect(jspsych.getCitations()).toBe(jsPsychApaCitation);
|
expect(jspsych.getCitations()).toBe(jsPsychApaCitation);
|
||||||
});
|
});
|
||||||
@ -34,13 +26,11 @@ try {
|
|||||||
expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions");
|
expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions");
|
||||||
});
|
});
|
||||||
test("citing without input and with invalid format", () => {
|
test("citing without input and with invalid format", () => {
|
||||||
expect(() => jspsych.getCitations(null, "apa")).toThrow(
|
expect(() => jspsych.getCitations(null, "apa")).toThrow("Expected array of plugins/extensions");
|
||||||
"Expected array of plugins/extensions"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("citing using an array in different formats", () => {
|
describe("citing using an array in different formats", () => {
|
||||||
test("citing empty array with APA format", () => {
|
test("citing empty array with APA format", () => {
|
||||||
expect(jspsych.getCitations([], "apa")).toBe(jsPsychApaCitation);
|
expect(jspsych.getCitations([], "apa")).toBe(jsPsychApaCitation);
|
||||||
});
|
});
|
||||||
@ -60,9 +50,9 @@ try {
|
|||||||
"Unsupported citation format"
|
"Unsupported citation format"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("citing mix of valid plugins/extensions", () => {
|
describe("citing mix of valid plugins/extensions", () => {
|
||||||
test("citing a plugin", () => {
|
test("citing a plugin", () => {
|
||||||
expect(jspsych.getCitations([TestPlugin])).toBe(
|
expect(jspsych.getCitations([TestPlugin])).toBe(
|
||||||
jsPsychApaCitation + "\n" + testPluginApaCitation
|
jsPsychApaCitation + "\n" + testPluginApaCitation
|
||||||
@ -83,12 +73,4 @@ try {
|
|||||||
jsPsychApaCitation + "\n" + testPluginApaCitation + "\n" + testExtensionApaCitation
|
jsPsychApaCitation + "\n" + testPluginApaCitation + "\n" + testExtensionApaCitation
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
|
||||||
// Fall back to development version if built version not found
|
|
||||||
describe("skipping citation tests because of missing built version", () => {
|
|
||||||
test.skip("skip", () => {
|
|
||||||
expect(true).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
@ -542,8 +542,6 @@ describe("data simulation mode", () => {
|
|||||||
|
|
||||||
const data = getData().values()[1];
|
const data = getData().values()[1];
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
expect(data.rt).toBeGreaterThan(0);
|
expect(data.rt).toBeGreaterThan(0);
|
||||||
expect(data.response).toBeDefined();
|
expect(data.response).toBeDefined();
|
||||||
});
|
});
|
||||||
|
@ -155,8 +155,6 @@ describe("instructions plugin simulation", () => {
|
|||||||
|
|
||||||
const data = getData().values()[0];
|
const data = getData().values()[0];
|
||||||
|
|
||||||
console.log(data.view_history);
|
|
||||||
|
|
||||||
expect(data.rt).toBe(4000);
|
expect(data.rt).toBe(4000);
|
||||||
|
|
||||||
let sum_view_history_rt = 0;
|
let sum_view_history_rt = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user