@jspsych/config 3.2.1 → 3.2.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @jspsych/config
2
2
 
3
+ ## 3.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#3488](https://github.com/jspsych/jsPsych/pull/3488) [`64a01292c350b5f6fd9f3f2e0dad5124262d53c9`](https://github.com/jspsych/jsPsych/commit/64a01292c350b5f6fd9f3f2e0dad5124262d53c9) Thanks [@jodeleeuw](https://github.com/jodeleeuw)! - Replaces the dependency on `canvas` in `@jspsych/config` with `jest-canvas-mock`.
8
+
9
+ - [#3484](https://github.com/jspsych/jsPsych/pull/3484) [`e710cb01e8ab2f992d0be902016e3e6540197f67`](https://github.com/jspsych/jsPsych/commit/e710cb01e8ab2f992d0be902016e3e6540197f67) Thanks [@jadeddelta](https://github.com/jadeddelta)! - Patches some edge cases for `getCitations` and the build process that reads CITATION.CFF files to include citation info
10
+
3
11
  ## 3.2.1
4
12
 
5
13
  ### Patch Changes
@@ -7,7 +7,6 @@ import path from "node:path";
7
7
 
8
8
  import { Cite } from "@citation-js/core";
9
9
  import appRootPath from "app-root-path";
10
- import yaml from "yaml";
11
10
 
12
11
  /**
13
12
  * Generate citation data from CITATION.cff file
@@ -23,11 +22,8 @@ export default function generateCitations() {
23
22
  let rawCff;
24
23
  const getCff = (path) => {
25
24
  rawCff = fs.readFileSync(path, "utf-8").toString();
26
- const cffData = yaml.parse(rawCff);
27
- if (cffData["preferred-citation"]) {
28
- preferredCitation = true;
29
- }
30
- return yaml.stringify(rawCff);
25
+ preferredCitation = rawCff.includes("preferred-citation:");
26
+ return rawCff;
31
27
  };
32
28
 
33
29
  try {
@@ -80,7 +76,7 @@ export default function generateCitations() {
80
76
  return citationBibtex;
81
77
  } catch (error) {
82
78
  console.log(`Error converting CITATION.cff to BibTeX string: ${error.message}`);
83
- return null;
79
+ return "";
84
80
  }
85
81
  })();
86
82
 
package/jest.cjs CHANGED
@@ -18,6 +18,7 @@ module.exports.makePackageConfig = (dirname) => {
18
18
  displayName: {
19
19
  name: packageBaseName,
20
20
  color: packageBaseName === "jspsych" ? "white" : "cyanBright",
21
- }
21
+ },
22
+ setupFiles: [require.resolve("jest-canvas-mock")],
22
23
  };
23
24
  };
@@ -0,0 +1 @@
1
+ module.exports = require("./jest.cjs").makePackageConfig(__dirname);
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@jspsych/config",
3
- "version": "3.2.1",
3
+ "version": "3.2.2",
4
4
  "description": "Shared (build) configuration for jsPsych packages",
5
5
  "type": "module",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "test:watch": "npm test -- --watch"
9
+ },
6
10
  "exports": {
7
11
  "./gulp": {
8
12
  "import": "./gulp.js",
@@ -45,9 +49,9 @@
45
49
  "@sucrase/jest-plugin": "3.0.0",
46
50
  "@types/gulp": "4.0.17",
47
51
  "@types/jest": "29.5.8",
52
+ "@types/node": "^22.10.10",
48
53
  "alias-hq": "6.2.4",
49
54
  "app-root-path": "^3.1.0",
50
- "canvas": "^2.11.2",
51
55
  "esbuild": "0.23.1",
52
56
  "glob": "7.2.3",
53
57
  "gulp": "5.0.0",
@@ -57,6 +61,7 @@
57
61
  "gulp-replace": "1.1.4",
58
62
  "gulp-zip": "6.0.0",
59
63
  "jest": "29.7.0",
64
+ "jest-canvas-mock": "2.5.0",
60
65
  "jest-environment-jsdom": "29.7.0",
61
66
  "merge-stream": "2.0.0",
62
67
  "rollup": "4.21.2",
@@ -66,7 +71,6 @@
66
71
  "rollup-plugin-node-externals": "7.1.3",
67
72
  "sucrase": "3.34.0",
68
73
  "tslib": "2.6.2",
69
- "typescript": "^5.2.2",
70
- "yaml": "^2.5.1"
74
+ "typescript": "^5.7.0"
71
75
  }
72
76
  }
@@ -0,0 +1,94 @@
1
+ import fs from "node:fs";
2
+
3
+ import generateCitations from "../generateCitations";
4
+
5
+ // Mock filesystem
6
+ jest.mock("node:fs");
7
+ jest.mock("app-root-path", () => ({
8
+ path: "/mock/root/path",
9
+ }));
10
+
11
+ describe("generateCitations", () => {
12
+ beforeEach(() => {
13
+ jest.clearAllMocks();
14
+ });
15
+
16
+ const validCitationCff = `
17
+ cff-version: 1.2.0
18
+ message: Please cite this software using these metadata
19
+ title: Test Software
20
+ authors:
21
+ - family-names: Doe
22
+ given-names: John
23
+ version: 1.0.0
24
+ date-released: 2023-01-01
25
+ `;
26
+
27
+ const citationCffWithPreferred = `
28
+ cff-version: 1.2.0
29
+ message: Please cite this software using these metadata
30
+ title: Test Software
31
+ authors:
32
+ - family-names: Doe
33
+ given-names: John
34
+ preferred-citation:
35
+ title: Preferred Citation
36
+ authors:
37
+ - family-names: Smith
38
+ given-names: Jane
39
+ `;
40
+
41
+ test("should generate citations when CITATION.cff exists in current directory", () => {
42
+ fs.readFileSync.mockReturnValue(validCitationCff);
43
+
44
+ const result = generateCitations();
45
+
46
+ expect(result).toHaveProperty("apa");
47
+ expect(result).toHaveProperty("bibtex");
48
+ expect(result.apa).not.toBe("");
49
+ expect(result.bibtex).not.toBe("");
50
+ });
51
+
52
+ test("should handle preferred-citation when present", () => {
53
+ fs.readFileSync.mockReturnValue(citationCffWithPreferred);
54
+
55
+ const result = generateCitations();
56
+
57
+ expect(result).toHaveProperty("apa");
58
+ expect(result).toHaveProperty("bibtex");
59
+ expect(result.apa.includes("Smith")).toBeTruthy();
60
+ });
61
+
62
+ test("should return empty strings when CITATION.cff is not found", () => {
63
+ fs.readFileSync.mockImplementation(() => {
64
+ throw new Error("File not found");
65
+ });
66
+
67
+ const result = generateCitations();
68
+
69
+ expect(result).toEqual({
70
+ apa: "",
71
+ bibtex: "",
72
+ });
73
+ });
74
+
75
+ test("should handle malformed CITATION.cff", () => {
76
+ fs.readFileSync.mockReturnValue("invalid: yaml: content:");
77
+
78
+ const result = generateCitations();
79
+
80
+ expect(result).toEqual({
81
+ apa: "",
82
+ bibtex: "",
83
+ });
84
+ });
85
+
86
+ test("should remove newlines from citations", () => {
87
+ fs.readFileSync.mockReturnValue(validCitationCff);
88
+
89
+ const result = generateCitations();
90
+
91
+ expect(result.apa).not.toMatch(/\n/);
92
+ expect(result.bibtex).not.toMatch(/\n/);
93
+ });
94
+ });