Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test #40

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ test
test-output
npm-debug.log
node_modules
coverage
.idea
29 changes: 19 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@
"bin": {
"jeff": "./bin/jeff"
},
"scripts": {
"test": "NODE_ENV=test mocha './**/*.test.js'",
"istanbul": "istanbul cover _mocha $(find ./ -name \"*.test.js\" -not -path \"./node_modules/*\")"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we are putting all the test files inside a test/ folder

in that case you can simplify the npm scripts:

  • mocha should look into the test folder and should be recursive
  • istanbul do not have to find all the test files

Copy link
Author

@Solinca Solinca Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right!
I already put all my tests into an "unit-tests" folder.
My unit test setup file was located on root before I removed it, this is the reason why I wrote those line.
I will apply these changes

},
"main": "./src/index.js",
"dependencies": {
"async": "0.2.10",
"buffer-crc32": "^0.2.5",
"canvas": "1.1.6",
"commander": "2.2.0",
"fs-extra": "0.8.1",
"glob": "4.3.1",
"image-optim": "0.3.0",
"js-beautify": "1.4.2",
"node-pngquant-native": "0.0.12"
"async": "0.2.10",
"buffer-crc32": "^0.2.5",
"canvas": "1.6.11",
"commander": "2.2.0",
"fs-extra": "0.8.1",
"glob": "4.3.1",
"image-optim": "0.3.0",
"js-beautify": "1.4.2",
"node-pngquant-native": "1.0.5"
},
"devDependencies" : {
"chai": "4.1.2",
"mocha": "5.2.0",
"istanbul": "0.4.5"
},
"repository": {
"type": "git",
Expand All @@ -32,4 +41,4 @@
"url": "https://github.com/Wizcorp/jeff/blob/master/LICENSE"
}
]
}
}
18 changes: 8 additions & 10 deletions src/SwfObjectProcessor/createSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var processShape = require('./processShape');

function createSymbol(swfObject) {
var symbol = { id: swfObject.id, swfObject: swfObject, parents: {} };

switch(swfObject.type) {

case 'main':
Expand All @@ -28,18 +28,16 @@ function createSymbol(swfObject) {

case 'shape':
var shapes = swfObject.edges;
var nbShapes = shapes.length;
var imagesArray = [];
for (var s = 0; s < shapes.length; s += 1) {
for (var s = 0; s < nbShapes; s++) {
var shape = shapes[s];

var fill = shape.leftFill;
var containsImage = fill ? (fill.type ? (fill.type === 'pattern') : false) : false;
if (!containsImage) {
fill = shape.rightFill;
containsImage = fill ? (fill.type ? (fill.type === 'pattern') : false) : false;
}
var isLeftFill = shape && shape.leftFill && shape.leftFill.type === 'pattern';
var isRightFill = shape && shape.rightFill && shape.rightFill.type === 'pattern';

if (containsImage) {
if (isLeftFill || isRightFill) {
var fill = isLeftFill ? shape.leftFill : shape.rightFill;
var m = fill.matrix;

// In case of an image all the components of the matrix have to be divided by 20
Expand Down Expand Up @@ -115,7 +113,7 @@ function createSymbol(swfObject) {
function createSymbols(swfObjects) {
var symbols = [];
var nbSymbols = swfObjects.length;
for (var s = 0; s < nbSymbols; s += 1) {
for (var s = 0; s < nbSymbols; s++) {
var swfObject = swfObjects[s];
symbols[swfObject.id] = createSymbol(swfObject);
}
Expand Down
60 changes: 35 additions & 25 deletions src/SwfObjectProcessor/removeSymbols.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
'use strict';

function removeSymbols(symbols, classSymbols, removeList){
var nbClassSymbols = classSymbols.length;
for (var s = 0; s < nbClassSymbols; s += 1) {

var classSymbol = classSymbols[s];
if (!classSymbol || !classSymbol.children) {
continue;
}

var children = classSymbol.children;
for (var c = 0; c < children.length; c += 1) {

var child = children[c];
var symbol = symbols[child.id];
if (!symbol.className){
continue;
}

var idx = removeList.indexOf(symbol.className);
if (idx !== -1) {
children.splice(c, 1);
c -= 1;
}
}
}
function removeSymbols(symbols, classSymbols, removeList) {
var nbClassSymbols = classSymbols.length;

for (var s = 0; s < nbClassSymbols; s++) {
var classSymbol = classSymbols[s];

if (!classSymbol || !classSymbol.children) {
continue;
}

var children = classSymbol.children;

for (var c = 0; c < children.length; c++) {
var child = children[c];

if (!child || typeof child.id === "undefined") {
continue;
}

var symbol = symbols[child.id];

if (!symbol || !symbol.className) {
continue;
}

if (removeList && removeList.length > 0) {
var idx = removeList.indexOf(symbol.className);

if (idx !== -1) {
children.splice(c, 1);
c -= 1;
}
}
}
}
}

module.exports = removeSymbols;
Loading