scorm-again 1.7.1 → 2.0.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/.babelrc +18 -7
- package/.github/dependabot.yml +5 -0
- package/.github/workflows/main.yml +79 -0
- package/.jsdoc.json +4 -5
- package/.mocharc.json +8 -0
- package/.run/Mocha Unit Tests.run.xml +5 -2
- package/CONTRIBUTING.md +1 -1
- package/README.md +14 -1
- package/dist/aicc.js +3661 -7170
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +2 -40
- package/dist/aicc.min.js.map +1 -0
- package/dist/scorm-again.js +5671 -10695
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +2 -52
- package/dist/scorm-again.min.js.map +1 -0
- package/dist/scorm12.js +2871 -5433
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +2 -34
- package/dist/scorm12.min.js.map +1 -0
- package/dist/scorm2004.js +3868 -6797
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +2 -40
- package/dist/scorm2004.min.js.map +1 -0
- package/eslint.config.js +21 -0
- package/package.json +72 -34
- package/results.json +34254 -0
- package/src/{AICC.js → AICC.ts} +27 -21
- package/src/BaseAPI.ts +1449 -0
- package/src/Scorm12API.ts +360 -0
- package/src/{Scorm2004API.js → Scorm2004API.ts} +245 -163
- package/src/cmi/aicc_cmi.ts +1248 -0
- package/src/cmi/common.ts +411 -0
- package/src/cmi/scorm12_cmi.ts +1426 -0
- package/src/cmi/scorm2004_cmi.ts +1874 -0
- package/src/constants/api_constants.ts +318 -0
- package/src/constants/error_codes.ts +88 -0
- package/src/constants/language_constants.ts +394 -0
- package/src/constants/regex.ts +97 -0
- package/src/constants/{response_constants.js → response_constants.ts} +67 -62
- package/src/exceptions.ts +133 -0
- package/src/exports/aicc.js +1 -1
- package/src/exports/scorm-again.js +3 -3
- package/src/exports/scorm12.js +1 -1
- package/src/exports/scorm2004.js +1 -1
- package/src/{utilities.js → utilities.ts} +114 -74
- package/tea.yaml +6 -0
- package/test/{AICC.spec.js → AICC.spec.ts} +70 -72
- package/test/Scorm12API.spec.ts +580 -0
- package/test/Scorm2004API.spec.ts +812 -0
- package/test/api_helpers.ts +176 -0
- package/test/cmi/{aicc_cmi.spec.js → aicc_cmi.spec.ts} +193 -209
- package/test/cmi/{scorm12_cmi.spec.js → scorm12_cmi.spec.ts} +251 -269
- package/test/cmi/scorm2004_cmi.spec.ts +1031 -0
- package/test/cmi_helpers.ts +207 -0
- package/test/exceptions.spec.ts +79 -0
- package/test/field_values.ts +202 -0
- package/test/utilities.spec.ts +322 -0
- package/tsconfig.json +18 -0
- package/webpack.config.js +65 -0
- package/.circleci/config.yml +0 -99
- package/.codeclimate.yml +0 -7
- package/.eslintrc.js +0 -36
- package/src/.flowconfig +0 -11
- package/src/BaseAPI.js +0 -1275
- package/src/Scorm12API.js +0 -308
- package/src/cmi/aicc_cmi.js +0 -1141
- package/src/cmi/common.js +0 -328
- package/src/cmi/scorm12_cmi.js +0 -1312
- package/src/cmi/scorm2004_cmi.js +0 -1692
- package/src/constants/api_constants.js +0 -218
- package/src/constants/error_codes.js +0 -87
- package/src/constants/language_constants.js +0 -76
- package/src/constants/regex.js +0 -84
- package/src/exceptions.js +0 -104
- package/test/Scorm12API.spec.js +0 -528
- package/test/Scorm2004API.spec.js +0 -775
- package/test/abstract_classes.spec.js +0 -17
- package/test/api_helpers.js +0 -128
- package/test/cmi/scorm2004_cmi.spec.js +0 -1066
- package/test/cmi_helpers.js +0 -161
- package/test/exceptions.spec.js +0 -71
- package/test/field_values.js +0 -353
- package/test/utilities.spec.js +0 -339
- package/webpack.js +0 -78
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, it } from "mocha";
|
|
2
|
+
import { expect } from "expect";
|
|
3
|
+
import BaseAPI from "../src/BaseAPI";
|
|
4
|
+
|
|
5
|
+
class NoErrorThrownError extends Error {}
|
|
6
|
+
|
|
7
|
+
export const getError = async <TError>(
|
|
8
|
+
call: () => unknown,
|
|
9
|
+
): Promise<TError> => {
|
|
10
|
+
try {
|
|
11
|
+
await call();
|
|
12
|
+
|
|
13
|
+
throw new NoErrorThrownError();
|
|
14
|
+
} catch (error: unknown) {
|
|
15
|
+
return error as TError;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type CheckValidValues = {
|
|
20
|
+
api: BaseAPI;
|
|
21
|
+
fieldName: string;
|
|
22
|
+
validValues: (string | number)[];
|
|
23
|
+
invalidValues: string[];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type CheckLMSSetValue = {
|
|
27
|
+
api: BaseAPI;
|
|
28
|
+
fieldName: string;
|
|
29
|
+
valueToTest?: string | number;
|
|
30
|
+
expectedError?: number;
|
|
31
|
+
errorThrown?: boolean;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type CheckLMSGetValue = {
|
|
35
|
+
api: BaseAPI;
|
|
36
|
+
fieldName: string;
|
|
37
|
+
expectedValue?: string;
|
|
38
|
+
initializeFirst?: boolean;
|
|
39
|
+
initializationValue?: string;
|
|
40
|
+
expectedError?: number;
|
|
41
|
+
errorThrown?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type CheckSetCMIValue = {
|
|
45
|
+
api: BaseAPI;
|
|
46
|
+
fieldName: string;
|
|
47
|
+
valueToTest?: string;
|
|
48
|
+
expectedError?: number;
|
|
49
|
+
errorThrown?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const checkValidValues = ({
|
|
53
|
+
api,
|
|
54
|
+
fieldName,
|
|
55
|
+
validValues,
|
|
56
|
+
invalidValues,
|
|
57
|
+
}: CheckValidValues) => {
|
|
58
|
+
describe(`Field: ${fieldName}`, () => {
|
|
59
|
+
for (const idx in validValues) {
|
|
60
|
+
if ({}.hasOwnProperty.call(validValues, idx)) {
|
|
61
|
+
it(`Should successfully write '${validValues[idx]}' to ${fieldName}`, () => {
|
|
62
|
+
expect(api.lmsSetValue(fieldName, validValues[idx])).toEqual("true");
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (const idx in invalidValues) {
|
|
68
|
+
if ({}.hasOwnProperty.call(invalidValues, idx)) {
|
|
69
|
+
it(`Should fail to write '${invalidValues[idx]}' to ${fieldName}`, () => {
|
|
70
|
+
expect(api.lmsSetValue(fieldName, invalidValues[idx])).toEqual(
|
|
71
|
+
"false",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const checkLMSSetValue = ({
|
|
80
|
+
api,
|
|
81
|
+
fieldName,
|
|
82
|
+
valueToTest = "xxx",
|
|
83
|
+
expectedError = 0,
|
|
84
|
+
errorThrown = false,
|
|
85
|
+
}: CheckLMSSetValue) => {
|
|
86
|
+
describe(`Field: ${fieldName}`, () => {
|
|
87
|
+
const status = expectedError > 0 ? "fail to" : "successfully";
|
|
88
|
+
it(`Should ${status} set value for ${fieldName}`, async () => {
|
|
89
|
+
if (expectedError > 0) {
|
|
90
|
+
if (errorThrown) {
|
|
91
|
+
const error = await getError(async () =>
|
|
92
|
+
api.lmsSetValue(fieldName, valueToTest),
|
|
93
|
+
);
|
|
94
|
+
expect(error).toHaveProperty("errorCode", expectedError);
|
|
95
|
+
} else {
|
|
96
|
+
api.lmsSetValue(fieldName, valueToTest);
|
|
97
|
+
expect(String(api.lmsGetLastError())).toEqual(String(expectedError));
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
if (errorThrown) {
|
|
101
|
+
const error = await getError(async () =>
|
|
102
|
+
api.lmsSetValue(fieldName, valueToTest),
|
|
103
|
+
);
|
|
104
|
+
expect(error).toHaveProperty("errorCode", expectedError);
|
|
105
|
+
} else {
|
|
106
|
+
api.lmsSetValue(fieldName, valueToTest);
|
|
107
|
+
expect(String(api.lmsGetLastError())).toEqual(String(0));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const checkLMSGetValue = ({
|
|
115
|
+
api,
|
|
116
|
+
fieldName,
|
|
117
|
+
expectedValue = "",
|
|
118
|
+
initializeFirst = false,
|
|
119
|
+
initializationValue = "",
|
|
120
|
+
expectedError = 0,
|
|
121
|
+
errorThrown = false,
|
|
122
|
+
}: CheckLMSGetValue) => {
|
|
123
|
+
describe(`Field: ${fieldName}`, () => {
|
|
124
|
+
const status = expectedError > 0 ? "fail to" : "successfully";
|
|
125
|
+
|
|
126
|
+
if (initializeFirst) {
|
|
127
|
+
api.setCMIValue(fieldName, initializationValue);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
it(`Should ${status} get value for ${fieldName}`, async () => {
|
|
131
|
+
if (expectedError > 0) {
|
|
132
|
+
if (errorThrown) {
|
|
133
|
+
const error = await getError(async () => api.lmsGetValue(fieldName));
|
|
134
|
+
expect(error).toHaveProperty("errorCode", expectedError);
|
|
135
|
+
} else {
|
|
136
|
+
api.lmsGetValue(fieldName);
|
|
137
|
+
expect(String(api.lmsGetLastError())).toEqual(String(expectedError));
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
expect(api.lmsGetValue(fieldName)).toEqual(expectedValue);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const checkSetCMIValue = ({
|
|
147
|
+
api,
|
|
148
|
+
fieldName,
|
|
149
|
+
valueToTest = "xxx",
|
|
150
|
+
expectedError = 0,
|
|
151
|
+
errorThrown = true,
|
|
152
|
+
}: CheckSetCMIValue) => {
|
|
153
|
+
describe(`Field: ${fieldName}`, () => {
|
|
154
|
+
const status = expectedError > 0 ? "fail to" : "successfully";
|
|
155
|
+
it(`Should ${status} set CMI value for ${fieldName}`, async () => {
|
|
156
|
+
if (expectedError > 0) {
|
|
157
|
+
if (errorThrown) {
|
|
158
|
+
const error = await getError(async () =>
|
|
159
|
+
api.setCMIValue(fieldName, valueToTest),
|
|
160
|
+
);
|
|
161
|
+
expect(error).toHaveProperty("errorCode", expectedError);
|
|
162
|
+
} else {
|
|
163
|
+
api.setCMIValue(fieldName, valueToTest);
|
|
164
|
+
expect(String(api.lmsGetLastError())).toEqual(String(expectedError));
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
if (errorThrown) {
|
|
168
|
+
expect(() => api.setCMIValue(fieldName, valueToTest)).not.toThrow();
|
|
169
|
+
} else {
|
|
170
|
+
api.setCMIValue(fieldName, valueToTest);
|
|
171
|
+
expect(String(api.lmsGetLastError())).toEqual(String(0));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|