scratch-analysis
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -80,3 +80,3 @@ const utility = require('./utility'); | ||
for (let i in input.children) { | ||
if (input.children[i].hasOwnProperty('spriteInfo')) result++; | ||
if (Object.prototype.hasOwnProperty.call(input.children[i], 'spriteInfo')) result++; | ||
} | ||
@@ -83,0 +83,0 @@ |
@@ -123,4 +123,4 @@ const utility = require('./utility'); | ||
return { | ||
count: list.length, | ||
id: list | ||
count: (typeof list === 'object' ? list.length : 0), | ||
id: (typeof list === 'object' ? list : []) | ||
}; | ||
@@ -127,0 +127,0 @@ }; |
{ | ||
"name": "scratch-analysis", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Analysis tool for summarizing the structure, composition, and complexity of Scratch programs.", | ||
@@ -11,7 +11,5 @@ "main": "lib/index.js", | ||
"scripts": { | ||
"test": "npm run test:lint && npm run test:unit && npm run test:integration", | ||
"test": "npm run test:lint && npm run test:unit", | ||
"test:lint": "eslint .", | ||
"test:unit": "tap test/unit/*.js", | ||
"test:integration": "tap test/integration/*.js", | ||
"test:coverage": "tap test/{unit,integration}/*.js --coverage --coverage-report=lcov" | ||
"test:unit": "tap --reporter nyan test/unit/*.js --statements=97 --branches=97" | ||
}, | ||
@@ -24,7 +22,7 @@ "author": "Scratch Foundation", | ||
"devDependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint": "^5.10.0", | ||
"eslint-config-scratch": "^5.0.0", | ||
"tap": "^12.1.1" | ||
"@babel/eslint-parser": "^7.5.4", | ||
"eslint": "^8.16.0", | ||
"eslint-config-scratch": "^7.0.0", | ||
"tap": "^16.2.0" | ||
} | ||
} |
@@ -15,7 +15,7 @@ const fs = require('fs'); | ||
analysis(sb2, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.blocks, 'object'); | ||
t.type(result.blocks.id, 'object'); | ||
t.deepEquals(result.blocks.id, [ | ||
t.same(result.blocks.id, [ | ||
'whenGreenFlag', | ||
@@ -40,7 +40,7 @@ 'doForever', | ||
analysis(sb3, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.blocks, 'object'); | ||
t.type(result.blocks.id, 'object'); | ||
t.deepEquals(result.blocks.id, [ | ||
t.same(result.blocks.id, [ | ||
'event_whenflagclicked', | ||
@@ -47,0 +47,0 @@ 'control_forever', |
@@ -21,7 +21,7 @@ const fs = require('fs'); | ||
analysis(sb2, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.cloud, 'object'); | ||
t.equals(result.cloud.count, 1); | ||
t.deepEquals(result.cloud.id, ['☁ baz']); | ||
t.equal(result.cloud.count, 1); | ||
t.same(result.cloud.id, ['☁ baz']); | ||
t.end(); | ||
@@ -33,7 +33,7 @@ }); | ||
analysis(sb3, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.cloud, 'object'); | ||
t.equals(result.cloud.count, 1); | ||
t.deepEquals(result.cloud.id, ['☁ baz']); | ||
t.equal(result.cloud.count, 1); | ||
t.same(result.cloud.id, ['☁ baz']); | ||
t.end(); | ||
@@ -45,7 +45,7 @@ }); | ||
analysis(sb2Complex, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.cloud, 'object'); | ||
t.equals(result.cloud.count, 8); | ||
t.deepEquals(result.cloud.id, [ | ||
t.equal(result.cloud.count, 8); | ||
t.same(result.cloud.id, [ | ||
'☁ Player_1', | ||
@@ -66,7 +66,7 @@ '☁ Player_2', | ||
analysis(sb3Complex, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.cloud, 'object'); | ||
t.equals(result.cloud.count, 8); | ||
t.deepEquals(result.cloud.id, [ | ||
t.equal(result.cloud.count, 8); | ||
t.same(result.cloud.id, [ | ||
'☁ Player_1', | ||
@@ -73,0 +73,0 @@ '☁ Player_2', |
@@ -16,5 +16,5 @@ const fs = require('fs'); | ||
test('defalt (object)', t => { | ||
test('default (object)', t => { | ||
analysis(defaultObject, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -27,7 +27,7 @@ | ||
t.equal(result.variables.count, 0); | ||
t.deepEqual(result.variables.id, []); | ||
t.same(result.variables.id, []); | ||
t.type(result.lists, 'object'); | ||
t.equal(result.lists.count, 0); | ||
t.deepEqual(result.lists.id, []); | ||
t.same(result.lists.id, []); | ||
@@ -39,7 +39,7 @@ t.type(result.comments, 'object'); | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -51,3 +51,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -57,3 +57,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'739b5e2a2435f6e1ec2993791b423146.png', | ||
@@ -70,11 +70,11 @@ '09dc888b0b7df19f70d81588ae73420e.svg', | ||
t.equal(result.blocks.unique, 0); | ||
t.deepEqual(result.blocks.id, []); | ||
t.deepEqual(result.blocks.frequency, {}); | ||
t.same(result.blocks.id, []); | ||
t.same(result.blocks.frequency, {}); | ||
t.type(result.extensions, 'object'); | ||
t.equal(result.extensions.count, 0); | ||
t.deepEqual(result.extensions.id, []); | ||
t.same(result.extensions.id, []); | ||
t.type(result.meta, 'object'); | ||
t.deepEqual(result.meta, {}); | ||
t.same(result.meta, {}); | ||
@@ -85,5 +85,5 @@ t.end(); | ||
test('defalt (binary)', t => { | ||
test('default (binary)', t => { | ||
analysis(defaultBinary, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -96,7 +96,7 @@ | ||
t.equal(result.variables.count, 0); | ||
t.deepEqual(result.variables.id, []); | ||
t.same(result.variables.id, []); | ||
t.type(result.lists, 'object'); | ||
t.equal(result.lists.count, 0); | ||
t.deepEqual(result.lists.id, []); | ||
t.same(result.lists.id, []); | ||
@@ -108,7 +108,7 @@ t.type(result.comments, 'object'); | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -120,3 +120,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -126,3 +126,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'739b5e2a2435f6e1ec2993791b423146.png', | ||
@@ -139,8 +139,8 @@ 'f9a1c175dbe2e5dee472858dd30d16bb.svg', | ||
t.equal(result.blocks.unique, 0); | ||
t.deepEqual(result.blocks.id, []); | ||
t.deepEqual(result.blocks.frequency, {}); | ||
t.same(result.blocks.id, []); | ||
t.same(result.blocks.frequency, {}); | ||
t.type(result.extensions, 'object'); | ||
t.equal(result.extensions.count, 0); | ||
t.deepEqual(result.extensions.id, []); | ||
t.same(result.extensions.id, []); | ||
@@ -153,3 +153,3 @@ t.end(); | ||
analysis(complexBinary, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -162,3 +162,3 @@ | ||
t.equal(result.variables.count, 2); | ||
t.deepEqual(result.variables.id, [ | ||
t.same(result.variables.id, [ | ||
'global', | ||
@@ -170,3 +170,3 @@ 'local' | ||
t.equal(result.lists.count, 2); | ||
t.deepEqual(result.lists.id, [ | ||
t.same(result.lists.id, [ | ||
'globallist', | ||
@@ -181,7 +181,7 @@ 'locallist' | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -193,3 +193,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -199,3 +199,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'5b465b3b07d39019109d8dc6d6ee6593.svg', | ||
@@ -212,3 +212,3 @@ 'f9a1c175dbe2e5dee472858dd30d16bb.svg', | ||
t.equal(result.blocks.unique, 18); | ||
t.deepEqual(result.blocks.id, [ | ||
t.same(result.blocks.id, [ | ||
'whenGreenFlag', | ||
@@ -249,3 +249,3 @@ 'doForever', | ||
]); | ||
t.deepEqual(result.blocks.frequency, { | ||
t.same(result.blocks.frequency, { | ||
'LEGO WeDo 2.0\u001FsetLED': 1, | ||
@@ -273,3 +273,3 @@ 'LEGO WeDo 2.0\u001FwhenTilted': 1, | ||
t.equal(result.extensions.count, 1); | ||
t.deepEqual(result.extensions.id, [ | ||
t.same(result.extensions.id, [ | ||
'LEGO WeDo 2.0' | ||
@@ -276,0 +276,0 @@ ]); |
@@ -20,5 +20,9 @@ const fs = require('fs'); | ||
test('defalt (object)', t => { | ||
const badExtensions = fs.readFileSync( | ||
path.resolve(__dirname, '../fixtures/sb3/badExtensions.json') | ||
); | ||
test('default (object)', t => { | ||
analysis(defaultObject, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -31,3 +35,3 @@ | ||
t.equal(result.variables.count, 1); | ||
t.deepEqual(result.variables.id, [ | ||
t.same(result.variables.id, [ | ||
'my variable' | ||
@@ -38,3 +42,3 @@ ]); | ||
t.equal(result.lists.count, 0); | ||
t.deepEqual(result.lists.id, []); | ||
t.same(result.lists.id, []); | ||
@@ -46,7 +50,7 @@ t.type(result.comments, 'object'); | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'Meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -58,3 +62,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -64,3 +68,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'cd21514d0531fdffb22204e0ec5ed84a.svg', | ||
@@ -77,8 +81,8 @@ 'b7853f557e4426412e64bb3da6531a99.svg', | ||
t.equal(result.blocks.unique, 0); | ||
t.deepEqual(result.blocks.id, []); | ||
t.deepEqual(result.blocks.frequency, {}); | ||
t.same(result.blocks.id, []); | ||
t.same(result.blocks.frequency, {}); | ||
t.type(result.extensions, 'object'); | ||
t.equal(result.extensions.count, 0); | ||
t.deepEqual(result.extensions.id, []); | ||
t.same(result.extensions.id, []); | ||
@@ -91,5 +95,5 @@ t.type(result.meta, 'object'); | ||
test('defalt (binary)', t => { | ||
test('default (binary)', t => { | ||
analysis(defaultBinary, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -102,3 +106,3 @@ | ||
t.equal(result.variables.count, 1); | ||
t.deepEqual(result.variables.id, [ | ||
t.same(result.variables.id, [ | ||
'my variable' | ||
@@ -109,3 +113,3 @@ ]); | ||
t.equal(result.lists.count, 0); | ||
t.deepEqual(result.lists.id, []); | ||
t.same(result.lists.id, []); | ||
@@ -117,7 +121,7 @@ t.type(result.comments, 'object'); | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'Meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -129,3 +133,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -135,3 +139,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'cd21514d0531fdffb22204e0ec5ed84a.svg', | ||
@@ -148,11 +152,11 @@ 'b7853f557e4426412e64bb3da6531a99.svg', | ||
t.equal(result.blocks.unique, 0); | ||
t.deepEqual(result.blocks.id, []); | ||
t.deepEqual(result.blocks.frequency, {}); | ||
t.same(result.blocks.id, []); | ||
t.same(result.blocks.frequency, {}); | ||
t.type(result.extensions, 'object'); | ||
t.equal(result.extensions.count, 0); | ||
t.deepEqual(result.extensions.id, []); | ||
t.same(result.extensions.id, []); | ||
t.type(result.meta, 'object'); | ||
t.deepEqual({}, result.meta); | ||
t.same({}, result.meta); | ||
@@ -165,3 +169,3 @@ t.end(); | ||
analysis(complexBinary, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -174,3 +178,3 @@ | ||
t.equal(result.variables.count, 2); | ||
t.deepEqual(result.variables.id, [ | ||
t.same(result.variables.id, [ | ||
'global', | ||
@@ -182,3 +186,3 @@ 'local' | ||
t.equal(result.lists.count, 2); | ||
t.deepEqual(result.lists.id, [ | ||
t.same(result.lists.id, [ | ||
'globallist', | ||
@@ -193,7 +197,7 @@ 'locallist' | ||
t.equal(result.sounds.count, 2); | ||
t.deepEqual(result.sounds.id, [ | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'meow' | ||
]); | ||
t.deepEqual(result.sounds.hash, [ | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
@@ -205,3 +209,3 @@ '83c36d806dc92327b9e7049a565c6bff.wav' | ||
t.equal(result.costumes.count, 3); | ||
t.deepEqual(result.costumes.id, [ | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
@@ -211,3 +215,3 @@ 'costume1', | ||
]); | ||
t.deepEqual(result.costumes.hash, [ | ||
t.same(result.costumes.hash, [ | ||
'7633d36de03d1df75808f581bbccc742.svg', | ||
@@ -224,3 +228,3 @@ 'e6bcb4046c157f60c9f5c3bb5f299fce.svg', | ||
t.equal(result.blocks.unique, 18); | ||
t.deepEqual(result.blocks.id, [ | ||
t.same(result.blocks.id, [ | ||
'event_whenflagclicked', | ||
@@ -261,3 +265,3 @@ 'control_forever', | ||
]); | ||
t.deepEqual(result.blocks.frequency, { | ||
t.same(result.blocks.frequency, { | ||
argument_reporter_string_number: 4, | ||
@@ -285,3 +289,3 @@ control_forever: 4, | ||
t.equal(result.extensions.count, 1); | ||
t.deepEqual(result.extensions.id, [ | ||
t.same(result.extensions.id, [ | ||
'wedo2' | ||
@@ -296,3 +300,3 @@ ]); | ||
analysis(extensionsBinary, (err, result) => { | ||
t.true(typeof err === 'undefined' || err === null); | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
@@ -302,3 +306,3 @@ | ||
t.equal(result.extensions.count, 2); | ||
t.deepEqual(result.extensions.id, [ | ||
t.same(result.extensions.id, [ | ||
'translate', | ||
@@ -311,1 +315,65 @@ 'text2speech' | ||
}); | ||
test('regression test IBE-198, a bad list does not break library', t => { | ||
analysis(badExtensions, (err, result) => { | ||
t.ok(typeof err === 'undefined' || err === null); | ||
t.type(result, 'object'); | ||
t.type(result.scripts, 'object'); | ||
t.equal(result.scripts.count, 0); | ||
t.type(result.variables, 'object'); | ||
t.equal(result.variables.count, 1); | ||
t.same(result.variables.id, [ | ||
'my variable' | ||
]); | ||
t.type(result.lists, 'object'); | ||
t.equal(result.lists.count, 0); | ||
t.same(result.lists.id, []); | ||
t.type(result.comments, 'object'); | ||
t.equal(result.comments.count, 0); | ||
t.type(result.sounds, 'object'); | ||
t.equal(result.sounds.count, 2); | ||
t.same(result.sounds.id, [ | ||
'pop', | ||
'Meow' | ||
]); | ||
t.same(result.sounds.hash, [ | ||
'83a9787d4cb6f3b7632b4ddfebf74367.wav', | ||
'83c36d806dc92327b9e7049a565c6bff.wav' | ||
]); | ||
t.type(result.costumes, 'object'); | ||
t.equal(result.costumes.count, 3); | ||
t.same(result.costumes.id, [ | ||
'backdrop1', | ||
'costume1', | ||
'costume2' | ||
]); | ||
t.same(result.costumes.hash, [ | ||
'cd21514d0531fdffb22204e0ec5ed84a.svg', | ||
'b7853f557e4426412e64bb3da6531a99.svg', | ||
'e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg' | ||
]); | ||
t.type(result.sprites, 'object'); | ||
t.equal(result.sprites.count, 1); | ||
t.type(result.blocks, 'object'); | ||
t.equal(result.blocks.count, 0); | ||
t.equal(result.blocks.unique, 0); | ||
t.same(result.blocks.id, []); | ||
t.same(result.blocks.frequency, {}); | ||
t.type(result.extensions, 'object'); | ||
t.equal(result.extensions.count, 0); | ||
t.same(result.extensions.id, []); | ||
t.type(result.meta, 'object'); | ||
t.equal(result.meta.origin, 'test.scratch.mit.edu'); | ||
t.end(); | ||
}); | ||
}); |
@@ -13,3 +13,3 @@ const test = require('tap').test; | ||
const result = utility.frequency(input); | ||
t.deepEqual(result, { | ||
t.same(result, { | ||
foo: 3, | ||
@@ -16,0 +16,0 @@ bar: 2, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4291502
36
1353