scorm-again 2.2.0 → 2.4.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/README.md +2 -1
- package/dist/aicc.js +3161 -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 +4569 -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 +6955 -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 +3637 -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 +4631 -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 +4498 -4082
- 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 +3074 -2756
- 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 +2430 -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 +70 -0
- package/package.json +11 -8
- package/src/AICC.ts +6 -4
- package/src/BaseAPI.ts +38 -21
- package/src/Scorm12API.ts +24 -29
- package/src/Scorm2004API.ts +13 -18
- package/src/ScormAgain.ts +9 -0
- package/src/constants/default_settings.ts +1 -0
- package/src/types/api_types.ts +1 -0
- package/test/AICC.spec.ts +2 -2
- package/test/Scorm12API.spec.ts +73 -2
- package/test/Scorm2004API.spec.ts +18 -18
- 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
|
@@ -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/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
|
-
});
|