scorm-again 2.3.0 → 2.4.1
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/README.md +2 -1
- package/dist/aicc.js +3165 -2799
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +1 -1
- package/dist/aicc.min.js.map +1 -1
- package/dist/esm/aicc.js +4573 -0
- package/dist/esm/aicc.js.map +1 -0
- package/dist/esm/aicc.min.js +2 -0
- package/dist/esm/aicc.min.js.map +1 -0
- package/dist/esm/scorm-again.js +6959 -0
- package/dist/esm/scorm-again.js.map +1 -0
- package/dist/esm/scorm-again.min.js +2 -0
- package/dist/esm/scorm-again.min.js.map +1 -0
- package/dist/esm/scorm12.js +3641 -0
- package/dist/esm/scorm12.js.map +1 -0
- package/dist/esm/scorm12.min.js +2 -0
- package/dist/esm/scorm12.min.js.map +1 -0
- package/dist/esm/scorm2004.js +4635 -0
- package/dist/esm/scorm2004.js.map +1 -0
- package/dist/esm/scorm2004.min.js +2 -0
- package/dist/esm/scorm2004.min.js.map +1 -0
- package/dist/scorm-again.js +4506 -4086
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +1 -1
- package/dist/scorm-again.min.js.map +1 -1
- package/dist/scorm12.js +3079 -2757
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +1 -1
- package/dist/scorm12.min.js.map +1 -1
- package/dist/scorm2004.js +2434 -2221
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/index.d.ts +69 -4
- package/package.json +11 -8
- package/src/AICC.ts +7 -5
- package/src/BaseAPI.ts +39 -22
- package/src/Scorm12API.ts +27 -32
- package/src/Scorm2004API.ts +16 -21
- package/src/ScormAgain.ts +9 -0
- package/src/cmi/aicc/attempts.ts +7 -7
- package/src/cmi/aicc/cmi.ts +4 -4
- package/src/cmi/aicc/core.ts +1 -1
- package/src/cmi/aicc/evaluation.ts +1 -1
- package/src/cmi/aicc/student_data.ts +2 -2
- package/src/cmi/aicc/student_preferences.ts +2 -2
- package/src/cmi/aicc/tries.ts +7 -7
- package/src/cmi/scorm12/cmi.ts +1 -1
- package/src/cmi/scorm12/interactions.ts +1 -1
- package/src/cmi/scorm2004/adl.ts +2 -2
- package/src/cmi/scorm2004/cmi.ts +1 -1
- package/src/cmi/scorm2004/interactions.ts +1 -1
- package/src/cmi/scorm2004/objectives.ts +1 -1
- package/src/cmi/scorm2004/score.ts +1 -1
- package/src/constants/default_settings.ts +6 -1
- package/src/types/api_types.ts +1 -0
- package/test/AICC.spec.ts +2 -2
- package/test/Scorm12API.spec.ts +174 -3
- package/test/Scorm2004API.spec.ts +18 -18
- package/tsconfig.json +1 -0
- package/webpack.config.js +38 -15
- package/src/exports/aicc.js +0 -3
- package/src/exports/scorm-again.js +0 -7
- package/src/exports/scorm12.js +0 -3
- package/src/exports/scorm2004.js +0 -3
- package/src/utilities/debounce.ts +0 -31
- package/test/utilities/debounce.spec.ts +0 -56
package/src/cmi/scorm2004/adl.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class ADL extends BaseCMI {
|
|
|
22
22
|
/**
|
|
23
23
|
* Called when the API has been initialized after the CMI has been created
|
|
24
24
|
*/
|
|
25
|
-
initialize() {
|
|
25
|
+
override initialize() {
|
|
26
26
|
super.initialize();
|
|
27
27
|
this.nav?.initialize();
|
|
28
28
|
}
|
|
@@ -67,7 +67,7 @@ export class ADLNav extends BaseCMI {
|
|
|
67
67
|
/**
|
|
68
68
|
* Called when the API has been initialized after the CMI has been created
|
|
69
69
|
*/
|
|
70
|
-
initialize() {
|
|
70
|
+
override initialize() {
|
|
71
71
|
super.initialize();
|
|
72
72
|
this.request_valid?.initialize();
|
|
73
73
|
}
|
package/src/cmi/scorm2004/cmi.ts
CHANGED
|
@@ -61,7 +61,7 @@ export class CMI extends BaseRootCMI {
|
|
|
61
61
|
/**
|
|
62
62
|
* Called when the API has been initialized after the CMI has been created
|
|
63
63
|
*/
|
|
64
|
-
initialize() {
|
|
64
|
+
override initialize() {
|
|
65
65
|
super.initialize();
|
|
66
66
|
this.learner_preference?.initialize();
|
|
67
67
|
this.score?.initialize();
|
|
@@ -60,7 +60,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
60
60
|
/**
|
|
61
61
|
* Called when the API has been initialized after the CMI has been created
|
|
62
62
|
*/
|
|
63
|
-
initialize() {
|
|
63
|
+
override initialize() {
|
|
64
64
|
super.initialize();
|
|
65
65
|
this.objectives?.initialize();
|
|
66
66
|
this.correct_responses?.initialize();
|
|
@@ -20,9 +20,14 @@ export const DefaultSettings: Settings = {
|
|
|
20
20
|
strict_errors: true,
|
|
21
21
|
xhrHeaders: {},
|
|
22
22
|
xhrWithCredentials: false,
|
|
23
|
+
fetchMode: "cors",
|
|
23
24
|
responseHandler: async function (response: Response): Promise<ResultObject> {
|
|
24
25
|
if (typeof response !== "undefined") {
|
|
25
|
-
const
|
|
26
|
+
const responseText = await response.text();
|
|
27
|
+
let httpResult = null;
|
|
28
|
+
if (responseText) {
|
|
29
|
+
httpResult = JSON.parse(responseText);
|
|
30
|
+
}
|
|
26
31
|
if (
|
|
27
32
|
httpResult === null ||
|
|
28
33
|
!{}.hasOwnProperty.call(httpResult, "result")
|
package/src/types/api_types.ts
CHANGED
|
@@ -15,6 +15,7 @@ export type Settings = {
|
|
|
15
15
|
strict_errors?: boolean;
|
|
16
16
|
xhrHeaders?: RefObject;
|
|
17
17
|
xhrWithCredentials?: boolean;
|
|
18
|
+
fetchMode?: "cors" | "no-cors" | "same-origin" | "navigate";
|
|
18
19
|
responseHandler?: (response: Response) => Promise<ResultObject>;
|
|
19
20
|
requestHandler?: (commitObject: any) => any;
|
|
20
21
|
onLogMessage?: (messageLevel: number, logMessage: string) => void;
|
package/test/AICC.spec.ts
CHANGED
|
@@ -2,12 +2,12 @@ import { expect } from "expect";
|
|
|
2
2
|
import { describe } from "mocha";
|
|
3
3
|
import * as h from "./api_helpers";
|
|
4
4
|
import ErrorCodes from "../src/constants/error_codes";
|
|
5
|
-
import
|
|
5
|
+
import { AICCImpl } from "../src/AICC";
|
|
6
6
|
|
|
7
7
|
const scorm12_error_codes = ErrorCodes.scorm12;
|
|
8
8
|
|
|
9
9
|
const api = () => {
|
|
10
|
-
const API = new
|
|
10
|
+
const API = new AICCImpl();
|
|
11
11
|
API.apiLogLevel = 1;
|
|
12
12
|
return API;
|
|
13
13
|
};
|
package/test/Scorm12API.spec.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from "expect";
|
|
2
2
|
import { after, before, describe, it } from "mocha";
|
|
3
|
-
import
|
|
3
|
+
import { Scorm12Impl } from "../src/Scorm12API";
|
|
4
4
|
import * as h from "./api_helpers";
|
|
5
5
|
import ErrorCodes from "../src/constants/error_codes";
|
|
6
6
|
import { scorm12Values } from "./field_values";
|
|
@@ -13,14 +13,14 @@ const scorm12_error_codes = ErrorCodes.scorm12;
|
|
|
13
13
|
|
|
14
14
|
let clock: sinon.SinonFakeTimers;
|
|
15
15
|
const api = (settings?: Settings, startingData: RefObject = {}) => {
|
|
16
|
-
const API = new
|
|
16
|
+
const API = new Scorm12Impl(settings);
|
|
17
17
|
API.apiLogLevel = 5;
|
|
18
18
|
API.startingData = startingData;
|
|
19
19
|
return API;
|
|
20
20
|
};
|
|
21
21
|
const apiInitialized = (settings?: Settings, startingData: RefObject = {}) => {
|
|
22
22
|
const API = api(settings);
|
|
23
|
-
API.loadFromJSON(startingData ? startingData : {}
|
|
23
|
+
API.loadFromJSON(startingData ? startingData : {});
|
|
24
24
|
API.lmsInitialize();
|
|
25
25
|
return API;
|
|
26
26
|
};
|
|
@@ -51,6 +51,106 @@ describe("SCORM 1.2 API Tests", () => {
|
|
|
51
51
|
clock.restore();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
describe("loadFromJSON()", () => {
|
|
55
|
+
it("should load JSON data into the CMI object", () => {
|
|
56
|
+
const scorm12API = api();
|
|
57
|
+
const jsonData = {
|
|
58
|
+
cmi: {
|
|
59
|
+
core: {
|
|
60
|
+
student_id: "student_1",
|
|
61
|
+
student_name: "John Doe",
|
|
62
|
+
lesson_status: "incomplete",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
scorm12API.loadFromJSON(jsonData);
|
|
68
|
+
scorm12API.lmsInitialize();
|
|
69
|
+
|
|
70
|
+
expect(scorm12API.cmi.core.student_id).toEqual("student_1");
|
|
71
|
+
expect(scorm12API.cmi.core.student_name).toEqual("John Doe");
|
|
72
|
+
expect(scorm12API.cmi.core.lesson_status).toEqual("incomplete");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should load nested JSON data into the CMI object", () => {
|
|
76
|
+
const scorm12API = api();
|
|
77
|
+
const jsonData = {
|
|
78
|
+
cmi: {
|
|
79
|
+
objectives: {
|
|
80
|
+
"0": {
|
|
81
|
+
id: "obj_1",
|
|
82
|
+
score: {
|
|
83
|
+
raw: "85",
|
|
84
|
+
min: "0",
|
|
85
|
+
max: "100",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
scorm12API.loadFromJSON(jsonData);
|
|
93
|
+
|
|
94
|
+
expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
|
|
95
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
|
|
96
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
|
|
97
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should load nested cmi JSON data into the CMI object", () => {
|
|
101
|
+
const scorm12API = api();
|
|
102
|
+
const jsonData = {
|
|
103
|
+
objectives: {
|
|
104
|
+
"0": {
|
|
105
|
+
id: "obj_1",
|
|
106
|
+
score: {
|
|
107
|
+
raw: "85",
|
|
108
|
+
min: "0",
|
|
109
|
+
max: "100",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
scorm12API.loadFromJSON(jsonData, "cmi");
|
|
116
|
+
|
|
117
|
+
expect(scorm12API.cmi.objectives.childArray[0].id).toEqual("obj_1");
|
|
118
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.raw).toEqual("85");
|
|
119
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.min).toEqual("0");
|
|
120
|
+
expect(scorm12API.cmi.objectives.childArray[0].score.max).toEqual("100");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("should handle empty JSON data", () => {
|
|
124
|
+
const scorm12API = api();
|
|
125
|
+
const jsonData = {};
|
|
126
|
+
|
|
127
|
+
scorm12API.loadFromJSON(jsonData);
|
|
128
|
+
|
|
129
|
+
expect(scorm12API.cmi.core.student_id).toBeFalsy();
|
|
130
|
+
expect(scorm12API.cmi.core.student_name).toBeFalsy();
|
|
131
|
+
expect(scorm12API.cmi.core.lesson_status).toBe("not attempted");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should not load data if API is initialized", () => {
|
|
135
|
+
const scorm12API = apiInitialized();
|
|
136
|
+
const jsonData = {
|
|
137
|
+
cmi: {
|
|
138
|
+
core: {
|
|
139
|
+
student_id: "student_1",
|
|
140
|
+
student_name: "John Doe",
|
|
141
|
+
lesson_status: "incomplete",
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
scorm12API.loadFromJSON(jsonData);
|
|
147
|
+
|
|
148
|
+
expect(scorm12API.cmi.core.student_id).toBeFalsy();
|
|
149
|
+
expect(scorm12API.cmi.core.student_name).toBeFalsy();
|
|
150
|
+
expect(scorm12API.cmi.core.lesson_status).toBe("not attempted");
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
54
154
|
describe("LMSSetValue()", () => {
|
|
55
155
|
h.checkValidValues({
|
|
56
156
|
api: apiInitialized(),
|
|
@@ -537,6 +637,77 @@ describe("SCORM 1.2 API Tests", () => {
|
|
|
537
637
|
});
|
|
538
638
|
});
|
|
539
639
|
|
|
640
|
+
describe("LMSCommit Debounce Tests", () => {
|
|
641
|
+
it("should debounce LMSCommit calls when autocommit is true", async () => {
|
|
642
|
+
const scorm12API = api({
|
|
643
|
+
...DefaultSettings,
|
|
644
|
+
autocommit: true,
|
|
645
|
+
autocommitSeconds: 1,
|
|
646
|
+
});
|
|
647
|
+
scorm12API.lmsInitialize();
|
|
648
|
+
|
|
649
|
+
const commitSpy = sinon.spy(scorm12API, "commit");
|
|
650
|
+
|
|
651
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
652
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:02:00");
|
|
653
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:03:00");
|
|
654
|
+
|
|
655
|
+
clock.tick(2000);
|
|
656
|
+
await clock.runAllAsync();
|
|
657
|
+
|
|
658
|
+
expect(commitSpy.calledOnce).toBe(true);
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
it("should call LMSCommit only once within the debounce period ", async () => {
|
|
662
|
+
const scorm12API = api({
|
|
663
|
+
...DefaultSettings,
|
|
664
|
+
asyncCommit: true,
|
|
665
|
+
autocommit: true,
|
|
666
|
+
});
|
|
667
|
+
scorm12API.lmsInitialize();
|
|
668
|
+
|
|
669
|
+
const commitSpy = sinon.spy(scorm12API, "commit");
|
|
670
|
+
|
|
671
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
672
|
+
|
|
673
|
+
scorm12API.lmsCommit();
|
|
674
|
+
clock.tick(100);
|
|
675
|
+
|
|
676
|
+
scorm12API.lmsCommit();
|
|
677
|
+
clock.tick(100);
|
|
678
|
+
|
|
679
|
+
scorm12API.lmsCommit();
|
|
680
|
+
clock.tick(100);
|
|
681
|
+
|
|
682
|
+
clock.tick(1000);
|
|
683
|
+
await clock.runAllAsync();
|
|
684
|
+
|
|
685
|
+
expect(commitSpy.calledOnce).toBe(true);
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
it("should call LMSCommit multiple times if debounce period is exceeded", async () => {
|
|
689
|
+
const scorm12API = api({
|
|
690
|
+
...DefaultSettings,
|
|
691
|
+
autocommit: true,
|
|
692
|
+
autocommitSeconds: 1,
|
|
693
|
+
});
|
|
694
|
+
scorm12API.lmsInitialize();
|
|
695
|
+
|
|
696
|
+
const commitSpy = sinon.spy(scorm12API, "commit");
|
|
697
|
+
|
|
698
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:01:00");
|
|
699
|
+
clock.tick(2000);
|
|
700
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:02:00");
|
|
701
|
+
clock.tick(2000);
|
|
702
|
+
scorm12API.lmsSetValue("cmi.core.session_time", "00:03:00");
|
|
703
|
+
|
|
704
|
+
clock.tick(2000);
|
|
705
|
+
await clock.runAllAsync();
|
|
706
|
+
|
|
707
|
+
expect(commitSpy.calledThrice).toBe(true);
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
|
|
540
711
|
describe("Event Handlers", () => {
|
|
541
712
|
it("Should handle SetValue.cmi.core.student_name event", () => {
|
|
542
713
|
const scorm12API = apiInitialized();
|
|
@@ -4,7 +4,7 @@ import * as sinon from "sinon";
|
|
|
4
4
|
import * as h from "./api_helpers";
|
|
5
5
|
import Pretender from "fetch-pretender";
|
|
6
6
|
import ErrorCodes from "../src/constants/error_codes";
|
|
7
|
-
import
|
|
7
|
+
import { Scorm2004Impl } from "../src/Scorm2004API";
|
|
8
8
|
import { scorm2004Values } from "./field_values";
|
|
9
9
|
import APIConstants from "../src/constants/api_constants";
|
|
10
10
|
import { RefObject, Settings } from "../src/types/api_types";
|
|
@@ -15,7 +15,7 @@ const scorm2004_error_codes = ErrorCodes.scorm2004;
|
|
|
15
15
|
|
|
16
16
|
let clock: sinon.SinonFakeTimers;
|
|
17
17
|
const api = (settings?: Settings, startingData: RefObject = {}) => {
|
|
18
|
-
const API = new
|
|
18
|
+
const API = new Scorm2004Impl(settings);
|
|
19
19
|
API.apiLogLevel = 5;
|
|
20
20
|
if (startingData) {
|
|
21
21
|
API.startingData = startingData;
|
|
@@ -949,7 +949,7 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
949
949
|
|
|
950
950
|
describe("checkCorrectResponseValue()", () => {
|
|
951
951
|
it("should properly handle the true-false response type for unknown value", () => {
|
|
952
|
-
const scorm2004API = new
|
|
952
|
+
const scorm2004API = new Scorm2004Impl();
|
|
953
953
|
scorm2004API.checkCorrectResponseValue("true-false", ["unknown"], "true");
|
|
954
954
|
expect(scorm2004API.lmsGetLastError()).toEqual(
|
|
955
955
|
String(scorm2004_error_codes.TYPE_MISMATCH),
|
|
@@ -957,13 +957,13 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
957
957
|
});
|
|
958
958
|
|
|
959
959
|
it("should properly handle the true-false response type for correct value", () => {
|
|
960
|
-
const scorm2004API = new
|
|
960
|
+
const scorm2004API = new Scorm2004Impl();
|
|
961
961
|
scorm2004API.checkCorrectResponseValue("true-false", ["true"], "true");
|
|
962
962
|
expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
|
|
963
963
|
});
|
|
964
964
|
|
|
965
965
|
it("should properly handle the choice response type for value over 4000 characters", () => {
|
|
966
|
-
const scorm2004API = new
|
|
966
|
+
const scorm2004API = new Scorm2004Impl();
|
|
967
967
|
scorm2004API.checkCorrectResponseValue(
|
|
968
968
|
"choice",
|
|
969
969
|
["x".repeat(4001)],
|
|
@@ -975,25 +975,25 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
975
975
|
});
|
|
976
976
|
|
|
977
977
|
it("should properly handle the choice response type for correct value", () => {
|
|
978
|
-
const scorm2004API = new
|
|
978
|
+
const scorm2004API = new Scorm2004Impl();
|
|
979
979
|
scorm2004API.checkCorrectResponseValue("choice", ["true"], "true");
|
|
980
980
|
expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
|
|
981
981
|
});
|
|
982
982
|
|
|
983
983
|
it("should properly handle the fill-in response type for correct value", () => {
|
|
984
|
-
const scorm2004API = new
|
|
984
|
+
const scorm2004API = new Scorm2004Impl();
|
|
985
985
|
scorm2004API.checkCorrectResponseValue("fill-in", ["true"], "true");
|
|
986
986
|
expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
|
|
987
987
|
});
|
|
988
988
|
|
|
989
989
|
it("should properly handle the long-fill-in response type for correct value", () => {
|
|
990
|
-
const scorm2004API = new
|
|
990
|
+
const scorm2004API = new Scorm2004Impl();
|
|
991
991
|
scorm2004API.checkCorrectResponseValue("long-fill-in", ["true"], "true");
|
|
992
992
|
expect(scorm2004API.lmsGetLastError()).toEqual(String(0));
|
|
993
993
|
});
|
|
994
994
|
|
|
995
995
|
it("should properly handle the matching response type for correct value", () => {
|
|
996
|
-
const scorm2004API = new
|
|
996
|
+
const scorm2004API = new Scorm2004Impl();
|
|
997
997
|
scorm2004API.checkCorrectResponseValue(
|
|
998
998
|
"matching",
|
|
999
999
|
["{order_matters=true}0[.]1"],
|
|
@@ -1005,28 +1005,28 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
1005
1005
|
|
|
1006
1006
|
describe("removeCorrectResponsePrefixes()", () => {
|
|
1007
1007
|
it("should remove the prefix from the string", () => {
|
|
1008
|
-
const scorm2004API = new
|
|
1008
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1009
1009
|
const input = "{order_matters=true}correctResponse";
|
|
1010
1010
|
const result = scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1011
1011
|
expect(result).toBe("correctResponse");
|
|
1012
1012
|
});
|
|
1013
1013
|
|
|
1014
1014
|
it("should return the original string if no prefix is present", () => {
|
|
1015
|
-
const scorm2004API = new
|
|
1015
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1016
1016
|
const input = "correctResponse";
|
|
1017
1017
|
const result = scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1018
1018
|
expect(result).toBe("correctResponse");
|
|
1019
1019
|
});
|
|
1020
1020
|
|
|
1021
1021
|
it("should handle empty strings correctly", () => {
|
|
1022
|
-
const scorm2004API = new
|
|
1022
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1023
1023
|
const input = "";
|
|
1024
1024
|
const result = scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1025
1025
|
expect(result).toBe("");
|
|
1026
1026
|
});
|
|
1027
1027
|
|
|
1028
1028
|
it("should handle multiple prefixes correctly", () => {
|
|
1029
|
-
const scorm2004API = new
|
|
1029
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1030
1030
|
const input =
|
|
1031
1031
|
"{lang=en}{order_matters=true}{case_matters=false}correctResponse";
|
|
1032
1032
|
const result = scorm2004API.removeCorrectResponsePrefixes(input);
|
|
@@ -1034,7 +1034,7 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
1034
1034
|
});
|
|
1035
1035
|
|
|
1036
1036
|
it("should throw an error for invalid order_matters value", () => {
|
|
1037
|
-
const scorm2004API = new
|
|
1037
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1038
1038
|
const input = "{order_matters=invalid}correctResponse";
|
|
1039
1039
|
scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1040
1040
|
expect(scorm2004API.lmsGetLastError()).toEqual(
|
|
@@ -1043,7 +1043,7 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
1043
1043
|
});
|
|
1044
1044
|
|
|
1045
1045
|
it("should throw an error for invalid case_matters value", () => {
|
|
1046
|
-
const scorm2004API = new
|
|
1046
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1047
1047
|
const input = "{case_matters=invalid}correctResponse";
|
|
1048
1048
|
scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1049
1049
|
expect(scorm2004API.lmsGetLastError()).toEqual(
|
|
@@ -1052,14 +1052,14 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
1052
1052
|
});
|
|
1053
1053
|
|
|
1054
1054
|
it("should ignore an unknown prefix", () => {
|
|
1055
|
-
const scorm2004API = new
|
|
1055
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1056
1056
|
const input = "{unknown=true}correctResponse";
|
|
1057
1057
|
const result = scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1058
1058
|
expect(result).toBe("{unknown=true}correctResponse");
|
|
1059
1059
|
});
|
|
1060
1060
|
|
|
1061
1061
|
it("should throw an error with an invalid language code", () => {
|
|
1062
|
-
const scorm2004API = new
|
|
1062
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1063
1063
|
const input = "{lang=xyz}correctResponse";
|
|
1064
1064
|
scorm2004API.removeCorrectResponsePrefixes(input);
|
|
1065
1065
|
expect(scorm2004API.lmsGetLastError()).toEqual(
|
|
@@ -1089,7 +1089,7 @@ describe("SCORM 2004 API Tests", () => {
|
|
|
1089
1089
|
});
|
|
1090
1090
|
|
|
1091
1091
|
it("should call throwSCORMError with the correct arguments in createCorrectResponsesObject", () => {
|
|
1092
|
-
const scorm2004API = new
|
|
1092
|
+
const scorm2004API = new Scorm2004Impl();
|
|
1093
1093
|
const interaction = {
|
|
1094
1094
|
id: "interaction-id-1",
|
|
1095
1095
|
type: "invalid-type",
|
package/tsconfig.json
CHANGED
package/webpack.config.js
CHANGED
|
@@ -14,29 +14,23 @@ const TSLoader = {
|
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const commonConfig = {
|
|
18
18
|
mode: "production",
|
|
19
19
|
devtool: "source-map",
|
|
20
20
|
entry: {
|
|
21
|
-
aicc: "./src/
|
|
22
|
-
scorm12: "./src/
|
|
23
|
-
scorm2004: "./src/
|
|
24
|
-
"scorm-again": "./src/
|
|
25
|
-
"aicc.min": "./src/
|
|
26
|
-
"scorm12.min": "./src/
|
|
27
|
-
"scorm2004.min": "./src/
|
|
28
|
-
"scorm-again.min": "./src/
|
|
21
|
+
aicc: "./src/AICC.ts",
|
|
22
|
+
scorm12: "./src/Scorm12API.ts",
|
|
23
|
+
scorm2004: "./src/Scorm2004API.ts",
|
|
24
|
+
"scorm-again": "./src/ScormAgain.ts",
|
|
25
|
+
"aicc.min": "./src/AICC.ts",
|
|
26
|
+
"scorm12.min": "./src/Scorm12API.ts",
|
|
27
|
+
"scorm2004.min": "./src/Scorm2004API.ts",
|
|
28
|
+
"scorm-again.min": "./src/ScormAgain.ts",
|
|
29
29
|
},
|
|
30
30
|
target: ["web", "es5"],
|
|
31
31
|
module: {
|
|
32
32
|
rules: [TSLoader],
|
|
33
33
|
},
|
|
34
|
-
output: {
|
|
35
|
-
path: path.resolve(__dirname, "dist"),
|
|
36
|
-
environment: {
|
|
37
|
-
arrowFunction: false,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
34
|
optimization: {
|
|
41
35
|
minimize: true,
|
|
42
36
|
minimizer: [
|
|
@@ -63,3 +57,32 @@ export default {
|
|
|
63
57
|
}),
|
|
64
58
|
],
|
|
65
59
|
};
|
|
60
|
+
|
|
61
|
+
const cjsConfig = {
|
|
62
|
+
...commonConfig,
|
|
63
|
+
output: {
|
|
64
|
+
path: path.resolve(__dirname, "dist"),
|
|
65
|
+
filename: "[name].js",
|
|
66
|
+
libraryTarget: "this",
|
|
67
|
+
environment: {
|
|
68
|
+
arrowFunction: false,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const esmConfig = {
|
|
74
|
+
...commonConfig,
|
|
75
|
+
experiments: {
|
|
76
|
+
outputModule: true,
|
|
77
|
+
},
|
|
78
|
+
output: {
|
|
79
|
+
path: path.resolve(__dirname, "dist/esm"),
|
|
80
|
+
filename: "[name].js",
|
|
81
|
+
libraryTarget: "module",
|
|
82
|
+
environment: {
|
|
83
|
+
arrowFunction: false,
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default [cjsConfig, esmConfig];
|
package/src/exports/aicc.js
DELETED
package/src/exports/scorm12.js
DELETED
package/src/exports/scorm2004.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Debounce function to delay the execution of a given function.
|
|
3
|
-
*
|
|
4
|
-
* @param func - The function to debounce.
|
|
5
|
-
* @param wait - The number of milliseconds to delay.
|
|
6
|
-
* @param immediate - If `true`, the function will be triggered on the leading edge instead of the trailing.
|
|
7
|
-
* @returns A debounced version of the provided function.
|
|
8
|
-
*/
|
|
9
|
-
export function debounce<T extends (...args: any[]) => void>(
|
|
10
|
-
func: T,
|
|
11
|
-
wait: number,
|
|
12
|
-
immediate = false,
|
|
13
|
-
): (...args: Parameters<T>) => void {
|
|
14
|
-
let timeout: ReturnType<typeof setTimeout> | null;
|
|
15
|
-
|
|
16
|
-
return function (this: any, ...args: Parameters<T>) {
|
|
17
|
-
const context = this;
|
|
18
|
-
|
|
19
|
-
const later = () => {
|
|
20
|
-
timeout = null;
|
|
21
|
-
if (!immediate) func.apply(context, args);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const callNow = immediate && !timeout;
|
|
25
|
-
|
|
26
|
-
if (timeout) clearTimeout(timeout);
|
|
27
|
-
timeout = setTimeout(later, wait);
|
|
28
|
-
|
|
29
|
-
if (callNow) func.apply(context, args);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { expect } from "expect";
|
|
2
|
-
import * as sinon from "sinon";
|
|
3
|
-
import { debounce } from "../../src/utilities/debounce";
|
|
4
|
-
|
|
5
|
-
describe("debounce", () => {
|
|
6
|
-
it("executes the function after the specified wait time", (done) => {
|
|
7
|
-
const mockFunction = sinon.spy();
|
|
8
|
-
const debouncedFunction = debounce(mockFunction, 100);
|
|
9
|
-
|
|
10
|
-
debouncedFunction();
|
|
11
|
-
expect(mockFunction.called).toBe(false);
|
|
12
|
-
|
|
13
|
-
setTimeout(() => {
|
|
14
|
-
expect(mockFunction.called).toBe(true);
|
|
15
|
-
done();
|
|
16
|
-
}, 150);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("executes the function immediately if immediate is true", () => {
|
|
20
|
-
const mockFunction = sinon.spy();
|
|
21
|
-
const debouncedFunction = debounce(mockFunction, 100, true);
|
|
22
|
-
|
|
23
|
-
debouncedFunction();
|
|
24
|
-
expect(mockFunction.called).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("does not execute the function if called again within the wait time", (done) => {
|
|
28
|
-
const mockFunction = sinon.spy();
|
|
29
|
-
const debouncedFunction = debounce(mockFunction, 100);
|
|
30
|
-
|
|
31
|
-
debouncedFunction();
|
|
32
|
-
debouncedFunction();
|
|
33
|
-
|
|
34
|
-
setTimeout(() => {
|
|
35
|
-
expect(mockFunction.calledOnce).toBe(true);
|
|
36
|
-
done();
|
|
37
|
-
}, 150);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("executes the function again after the wait time if called again", (done) => {
|
|
41
|
-
const mockFunction = sinon.spy();
|
|
42
|
-
const debouncedFunction = debounce(mockFunction, 100);
|
|
43
|
-
|
|
44
|
-
debouncedFunction();
|
|
45
|
-
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
debouncedFunction();
|
|
48
|
-
expect(mockFunction.calledOnce).toBe(true);
|
|
49
|
-
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
expect(mockFunction.calledTwice).toBe(true);
|
|
52
|
-
done();
|
|
53
|
-
}, 150);
|
|
54
|
-
}, 150);
|
|
55
|
-
});
|
|
56
|
-
});
|