mirror of
https://github.com/scratchfoundation/scratch-analysis.git
synced 2025-04-19 08:14:26 -04:00
fix: extraction of extensions
This commit is contained in:
parent
ff49ebc9b4
commit
344cf878dc
6 changed files with 50 additions and 5 deletions
|
@ -188,7 +188,7 @@ const blocks = function (project) {
|
|||
*/
|
||||
const extensions = function (project) {
|
||||
const result = {count: 0, id: []};
|
||||
const ext = project.info.savedExtensions;
|
||||
const ext = project.info?.savedExtensions;
|
||||
|
||||
// Check to ensure project includes any extensions
|
||||
if (typeof ext === 'undefined') return result;
|
||||
|
|
|
@ -156,10 +156,11 @@ const blocks = function (targets) {
|
|||
};
|
||||
|
||||
const extensions = function (list) {
|
||||
return {
|
||||
count: (typeof list === 'object' ? list.length : 0),
|
||||
id: (typeof list === 'object' ? list : [])
|
||||
};
|
||||
if (Array.isArray(list)) {
|
||||
return {count: list.length, id: list};
|
||||
}
|
||||
|
||||
return {count: 0, id: []};
|
||||
};
|
||||
|
||||
const metadata = function (meta) {
|
||||
|
|
8
test/fixtures/sb2/infoMissing.json
vendored
Normal file
8
test/fixtures/sb2/infoMissing.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"objName": "Stage",
|
||||
"costumes": [],
|
||||
"currentCostumeIndex": 0,
|
||||
"penLayerMD5": "l.png",
|
||||
"tempoBPM": 60,
|
||||
"children": []
|
||||
}
|
8
test/fixtures/sb3/extensionsObject.json
vendored
Normal file
8
test/fixtures/sb3/extensionsObject.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"targets": [],
|
||||
"monitors": [],
|
||||
"extensions": {},
|
||||
"meta": {
|
||||
"semver": "3.0.0"
|
||||
}
|
||||
}
|
|
@ -20,6 +20,10 @@ const invalidCostumes = fs.readFileSync(
|
|||
path.resolve(__dirname, '../fixtures/sb2/invalid-costumes.json')
|
||||
);
|
||||
|
||||
const missingInfo = fs.readFileSync(
|
||||
path.resolve(__dirname, '../fixtures/sb2/infoMissing.json')
|
||||
);
|
||||
|
||||
test('default (object)', t => {
|
||||
analysis(defaultObject, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
|
@ -324,3 +328,11 @@ test('stage with invalid costumes', t => {
|
|||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('works with a project where the "info" field is missing', t => {
|
||||
analysis(missingInfo, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
t.type(result, 'object');
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -29,6 +29,10 @@ const missingVariableField = fs.readFileSync(
|
|||
path.resolve(__dirname, '../fixtures/sb3/missingVariableField.json')
|
||||
);
|
||||
|
||||
const extensionsObject = fs.readFileSync(
|
||||
path.resolve(__dirname, '../fixtures/sb3/extensionsObject.json')
|
||||
);
|
||||
|
||||
test('default (object)', t => {
|
||||
analysis(defaultObject, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
|
@ -485,3 +489,15 @@ test('missing VARIABLE field in a block does not break the library', t => {
|
|||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
test('works with a project where "extensions" is an object', t => {
|
||||
analysis(extensionsObject, (err, result) => {
|
||||
t.ok(typeof err === 'undefined' || err === null);
|
||||
t.type(result, 'object');
|
||||
|
||||
t.type(result.extensions, 'object');
|
||||
t.equal(result.extensions.count, 0);
|
||||
t.same(result.extensions.id, []);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue