Fix for IBE-198, scratch-analysis should be able to deal with a JSON project file that does not contain extensions data

This commit is contained in:
Colby Gutierrez-Kraybill 2022-05-26 16:55:45 -04:00
parent 37727fdbce
commit f37f2d2790
5 changed files with 213 additions and 4 deletions

8
Dockerfile Normal file
View file

@ -0,0 +1,8 @@
FROM node:16
RUN mkdir -p /var/app/current
WORKDIR /var/app/current
COPY . ./
RUN rm -rf ./node_modules
RUN npm install
RUN npm install -g nodemon tap

30
docker-compose.yml Normal file
View file

@ -0,0 +1,30 @@
version: '3.4'
volumes:
npm_data:
runtime_data:
networks:
default:
external:
name: scratchapi_scratch_network
services:
app:
container_name: scratch-analysis-lib
hostname: scratch-analysis
build:
context: ./
dockerfile: Dockerfile
image: scratch-analysis:latest
command: node -e "require('http').createServer((req, res) => { res.end('OK'); }).listen(8080, () => {console.log('Listening on 8080'); } );"
volumes:
- type: bind
source: ./
target: /var/app/current
consistency: cached
volume:
nocopy: true
- npm_data:/var/app/current/node_modules
- runtime_data:/runtime
ports:
- "9999:8080"

View file

@ -120,8 +120,8 @@ const blocks = function (targets) {
const extensions = function (list) {
return {
count: list.length,
id: list
count: (typeof list === 'object' ? list.length : 0),
id: (typeof list === 'object' ? list : [])
};
};

103
test/fixtures/sb3/badExtensions.json vendored Normal file
View file

@ -0,0 +1,103 @@
{
"targets": [
{
"isStage": true,
"name": "Stage",
"variables": {
"`jEk@4|i[#Fk?(8x)AV.-my variable": [
"my variable",
0
]
},
"lists": {},
"broadcasts": {},
"blocks": {},
"comments": {},
"currentCostume": 0,
"costumes": [
{
"assetId": "cd21514d0531fdffb22204e0ec5ed84a",
"name": "backdrop1",
"md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg",
"dataFormat": "svg",
"rotationCenterX": 240,
"rotationCenterY": 180
}
],
"sounds": [
{
"assetId": "83a9787d4cb6f3b7632b4ddfebf74367",
"name": "pop",
"dataFormat": "wav",
"format": "",
"rate": 44100,
"sampleCount": 1032,
"md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav"
}
],
"volume": 100,
"layerOrder": 0,
"tempo": 60,
"videoTransparency": 50,
"videoState": "on",
"textToSpeechLanguage": null
},
{
"isStage": false,
"name": "Sprite1",
"variables": {},
"lists": {},
"broadcasts": {},
"blocks": {},
"comments": {},
"currentCostume": 0,
"costumes": [
{
"assetId": "b7853f557e4426412e64bb3da6531a99",
"name": "costume1",
"bitmapResolution": 1,
"md5ext": "b7853f557e4426412e64bb3da6531a99.svg",
"dataFormat": "svg",
"rotationCenterX": 48,
"rotationCenterY": 50
},
{
"assetId": "e6ddc55a6ddd9cc9d84fe0b4c21e016f",
"name": "costume2",
"bitmapResolution": 1,
"md5ext": "e6ddc55a6ddd9cc9d84fe0b4c21e016f.svg",
"dataFormat": "svg",
"rotationCenterX": 46,
"rotationCenterY": 53
}
],
"sounds": [
{
"assetId": "83c36d806dc92327b9e7049a565c6bff",
"name": "Meow",
"dataFormat": "wav",
"format": "",
"rate": 44100,
"sampleCount": 37376,
"md5ext": "83c36d806dc92327b9e7049a565c6bff.wav"
}
],
"volume": 100,
"layerOrder": 1,
"visible": true,
"x": 0,
"y": 0,
"size": 100,
"direction": 90,
"draggable": false,
"rotationStyle": "all around"
}
],
"monitors": [],
"meta": {
"semver": "3.0.0",
"vm": "0.2.0-prerelease.20181217191056",
"agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36",
"origin": "test.scratch.mit.edu"
}
}

View file

@ -17,7 +17,11 @@ const extensionsBinary = fs.readFileSync(
path.resolve(__dirname, '../fixtures/sb3/extensions.sb3')
);
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.type(result, 'object');
@ -81,7 +85,7 @@ test('defalt (object)', t => {
});
});
test('defalt (binary)', t => {
test('default (binary)', t => {
analysis(defaultBinary, (err, result) => {
t.true(typeof err === 'undefined' || err === null);
t.type(result, 'object');
@ -283,3 +287,67 @@ test('extensions', t => {
t.end();
});
});
test('regression test IBE-198', t => {
analysis(badExtensions, (err, result) => {
t.true(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.deepEqual(result.variables.id, [
'my variable'
]);
t.type(result.lists, 'object');
t.equal(result.lists.count, 0);
t.deepEqual(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.deepEqual(result.sounds.id, [
'pop',
'Meow'
]);
t.deepEqual(result.sounds.hash, [
'83a9787d4cb6f3b7632b4ddfebf74367.wav',
'83c36d806dc92327b9e7049a565c6bff.wav'
]);
t.type(result.costumes, 'object');
t.equal(result.costumes.count, 3);
t.deepEqual(result.costumes.id, [
'backdrop1',
'costume1',
'costume2'
]);
t.deepEqual(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.deepEqual(result.blocks.id, []);
t.deepEqual(result.blocks.frequency, {});
t.type(result.extensions, 'object');
t.equal(result.extensions.count, 0);
t.deepEqual(result.extensions.id, []);
t.type(result.meta, 'object');
t.equal(result.meta.origin, 'test.scratch.mit.edu');
t.end();
});
});