|
| 1 | +import { initJsPsych } from "../../src"; |
1 | 2 | import { TestExtension } from "../extensions/TestExtension";
|
2 | 3 | import TestPlugin from "../TestPlugin";
|
3 | 4 |
|
4 |
| -const jsPsychApaCitation = |
5 |
| - "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 "; |
6 |
| -const jsPsychBibtexCitation = |
7 |
| - '@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}, } '; |
| 5 | +const jsPsychApaCitation = "Test base APA citation"; |
| 6 | +const jsPsychBibtexCitation = "Test base BibTeX citation"; |
8 | 7 | const testPluginApaCitation = "Test plugin APA citation";
|
9 | 8 | const testPluginBibtexCitation = "Test plugin BibTeX citation";
|
10 | 9 | const testExtensionApaCitation = "Test extension APA citation";
|
11 | 10 |
|
12 |
| -let JsPsych; |
| 11 | +let jspsych; |
13 | 12 |
|
14 |
| -/** |
15 |
| - * These tests are skipped if the built version of JsPsych is not found. |
16 |
| - * This is because the citation functionality is only available in the built version |
17 |
| - * due to code injections that run during the build. |
18 |
| - */ |
| 13 | +beforeEach(() => { |
| 14 | + jspsych = initJsPsych(); |
| 15 | + (jspsych as any).citation = { |
| 16 | + apa: "Test base APA citation", |
| 17 | + bibtex: "Test base BibTeX citation", |
| 18 | + }; |
| 19 | +}); |
19 | 20 |
|
20 |
| -try { |
21 |
| - // Try to import built version |
22 |
| - JsPsych = require("../../dist/index").JsPsych; |
23 |
| - let jspsych: typeof JsPsych; |
24 |
| - |
25 |
| - beforeEach(() => { |
26 |
| - jspsych = new JsPsych(); |
| 21 | +describe("citing not using an array", () => { |
| 22 | + test("citing without input", () => { |
| 23 | + expect(jspsych.getCitations()).toBe(jsPsychApaCitation); |
27 | 24 | });
|
28 |
| - |
29 |
| - describe("citing not using an array", () => { |
30 |
| - test("citing without input", () => { |
31 |
| - expect(jspsych.getCitations()).toBe(jsPsychApaCitation); |
32 |
| - }); |
33 |
| - test("citing null", () => { |
34 |
| - expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions"); |
35 |
| - }); |
36 |
| - test("citing without input and with invalid format", () => { |
37 |
| - expect(() => jspsych.getCitations(null, "apa")).toThrow( |
38 |
| - "Expected array of plugins/extensions" |
39 |
| - ); |
40 |
| - }); |
| 25 | + test("citing null", () => { |
| 26 | + expect(() => jspsych.getCitations(null)).toThrow("Expected array of plugins/extensions"); |
| 27 | + }); |
| 28 | + test("citing without input and with invalid format", () => { |
| 29 | + expect(() => jspsych.getCitations(null, "apa")).toThrow("Expected array of plugins/extensions"); |
41 | 30 | });
|
| 31 | +}); |
42 | 32 |
|
43 |
| - describe("citing using an array in different formats", () => { |
44 |
| - test("citing empty array with APA format", () => { |
45 |
| - expect(jspsych.getCitations([], "apa")).toBe(jsPsychApaCitation); |
46 |
| - }); |
47 |
| - test("citing empty array with BibTeX format", () => { |
48 |
| - expect(jspsych.getCitations([], "bibtex")).toBe(jsPsychBibtexCitation); |
49 |
| - }); |
50 |
| - test("citing empty array without format", () => { |
51 |
| - expect(jspsych.getCitations([])).toBe(jsPsychApaCitation); |
52 |
| - }); |
53 |
| - test("citing one plugin with valid format in all caps", () => { |
54 |
| - expect(jspsych.getCitations([TestPlugin], "APA")).toBe( |
55 |
| - jsPsychApaCitation + "\n" + testPluginApaCitation |
56 |
| - ); |
57 |
| - }); |
58 |
| - test("citing with unsupported format", () => { |
59 |
| - expect(() => jspsych.getCitations([TestPlugin], "DummyTex")).toThrow( |
60 |
| - "Unsupported citation format" |
61 |
| - ); |
62 |
| - }); |
| 33 | +describe("citing using an array in different formats", () => { |
| 34 | + test("citing empty array with APA format", () => { |
| 35 | + expect(jspsych.getCitations([], "apa")).toBe(jsPsychApaCitation); |
| 36 | + }); |
| 37 | + test("citing empty array with BibTeX format", () => { |
| 38 | + expect(jspsych.getCitations([], "bibtex")).toBe(jsPsychBibtexCitation); |
| 39 | + }); |
| 40 | + test("citing empty array without format", () => { |
| 41 | + expect(jspsych.getCitations([])).toBe(jsPsychApaCitation); |
63 | 42 | });
|
| 43 | + test("citing one plugin with valid format in all caps", () => { |
| 44 | + expect(jspsych.getCitations([TestPlugin], "APA")).toBe( |
| 45 | + jsPsychApaCitation + "\n" + testPluginApaCitation |
| 46 | + ); |
| 47 | + }); |
| 48 | + test("citing with unsupported format", () => { |
| 49 | + expect(() => jspsych.getCitations([TestPlugin], "DummyTex")).toThrow( |
| 50 | + "Unsupported citation format" |
| 51 | + ); |
| 52 | + }); |
| 53 | +}); |
64 | 54 |
|
65 |
| - describe("citing mix of valid plugins/extensions", () => { |
66 |
| - test("citing a plugin", () => { |
67 |
| - expect(jspsych.getCitations([TestPlugin])).toBe( |
68 |
| - jsPsychApaCitation + "\n" + testPluginApaCitation |
69 |
| - ); |
70 |
| - }); |
71 |
| - test("citing a plugin in BibTeX", () => { |
72 |
| - expect(jspsych.getCitations([TestPlugin], "bibtex")).toBe( |
73 |
| - jsPsychBibtexCitation + "\n" + testPluginBibtexCitation |
74 |
| - ); |
75 |
| - }); |
76 |
| - test("citing multiple plugins", () => { |
77 |
| - expect(jspsych.getCitations([TestPlugin, TestPlugin])).toBe( |
78 |
| - jsPsychApaCitation + "\n" + testPluginApaCitation |
79 |
| - ); |
80 |
| - }); |
81 |
| - test("citing mix of plugins and extensions", () => { |
82 |
| - expect(jspsych.getCitations([TestPlugin, TestExtension])).toBe( |
83 |
| - jsPsychApaCitation + "\n" + testPluginApaCitation + "\n" + testExtensionApaCitation |
84 |
| - ); |
85 |
| - }); |
| 55 | +describe("citing mix of valid plugins/extensions", () => { |
| 56 | + test("citing a plugin", () => { |
| 57 | + expect(jspsych.getCitations([TestPlugin])).toBe( |
| 58 | + jsPsychApaCitation + "\n" + testPluginApaCitation |
| 59 | + ); |
| 60 | + }); |
| 61 | + test("citing a plugin in BibTeX", () => { |
| 62 | + expect(jspsych.getCitations([TestPlugin], "bibtex")).toBe( |
| 63 | + jsPsychBibtexCitation + "\n" + testPluginBibtexCitation |
| 64 | + ); |
| 65 | + }); |
| 66 | + test("citing multiple plugins", () => { |
| 67 | + expect(jspsych.getCitations([TestPlugin, TestPlugin])).toBe( |
| 68 | + jsPsychApaCitation + "\n" + testPluginApaCitation |
| 69 | + ); |
86 | 70 | });
|
87 |
| -} catch (e) { |
88 |
| - // Fall back to development version if built version not found |
89 |
| - describe("skipping citation tests because of missing built version", () => { |
90 |
| - test.skip("skip", () => { |
91 |
| - expect(true).toBe(true); |
92 |
| - }); |
| 71 | + test("citing mix of plugins and extensions", () => { |
| 72 | + expect(jspsych.getCitations([TestPlugin, TestExtension])).toBe( |
| 73 | + jsPsychApaCitation + "\n" + testPluginApaCitation + "\n" + testExtensionApaCitation |
| 74 | + ); |
93 | 75 | });
|
94 |
| -} |
| 76 | +}); |
0 commit comments