Skip to content

Commit

Permalink
[FIX] projectPreprocessor: Do not remove already removed dependencies (
Browse files Browse the repository at this point in the history
…#189)

This lead to the wrong dependency being removed in some cases.

Credits to @nlunets for reporting this issue.
  • Loading branch information
RandomByte authored Jun 25, 2019
1 parent af87d98 commit 4600d63
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class ProjectPreprocessor {
if (processedProject) {
if (processedProject.ignored) {
log.verbose(`Dependency of project ${parent.id}, "${project.id}" is flagged as ignored.`);
parent.dependencies.splice(parent.dependencies.indexOf(project), 1);
if (parent.dependencies.includes(project)) {
parent.dependencies.splice(parent.dependencies.indexOf(project), 1);
}
return true;
}
log.verbose(`Dependency of project ${parent.id}, "${project.id}": Distance to root of ${parent._level + 1}. Will be `+
Expand Down
121 changes: 121 additions & 0 deletions test/lib/projectPreprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1598,3 +1598,124 @@ test("specVersion: Project with valid version 1.0", async (t) => {
const res = await projectPreprocessor.processTree(tree);
t.deepEqual(res.specVersion, "1.0", "Correct spec version");
});

test("isBeingProcessed: Is not being processed", (t) => {
const preprocessor = new projectPreprocessor.ProjectPreprocessor();

preprocessor.processedProjects = {};

const project = {
id: "some.id",
_level: 1337
};
const parent = {
dependencies: [project]
};
const res = preprocessor.isBeingProcessed(parent, project);
t.deepEqual(res, false, "Project is not processed");
t.deepEqual(parent.dependencies.length, 1, "Parent still has one dependency");
});

test("isBeingProcessed: Is being processed", (t) => {
const preprocessor = new projectPreprocessor.ProjectPreprocessor();

const alreadyProcessedProject = {
project: {
id: "some.id",
_level: 42
},
parents: []
};
preprocessor.processedProjects = {
"some.id": alreadyProcessedProject
};

const project = {
id: "some.id",
_level: 1337
};
const parent = {
dependencies: [project]
};
const res = preprocessor.isBeingProcessed(parent, project);
t.deepEqual(res, true, "Project is already processed");
t.deepEqual(parent.dependencies.length, 1, "parent still has one dependency");
t.deepEqual(parent.dependencies[0]._level, 42, "Parent dependency got replaced with already processed project");
t.deepEqual(alreadyProcessedProject.parents.length, 1, "Already processed project now has one parent");
t.is(alreadyProcessedProject.parents[0], parent, "Parent got added as parent of already processed project");
});

test("isBeingProcessed: Processed project is ignored", (t) => {
const preprocessor = new projectPreprocessor.ProjectPreprocessor();

const alreadyProcessedProject = {
project: {
id: "some.id",
_level: 42
},
parents: [],
ignored: true
};
preprocessor.processedProjects = {
"some.id": alreadyProcessedProject
};

const project = {
id: "some.id",
_level: 1337
};
const parent = {
dependencies: [project]
};
const res = preprocessor.isBeingProcessed(parent, project);
t.deepEqual(res, true, "Project is already processed");
t.deepEqual(parent.dependencies.length, 0, "Project got removed from parent dependencies");
t.deepEqual(alreadyProcessedProject.parents.length, 0, "Already processed project still has no parents");
});

test("isBeingProcessed: Processed project is ignored but already removed from parent", (t) => {
const preprocessor = new projectPreprocessor.ProjectPreprocessor();

const alreadyProcessedProject = {
project: {
id: "some.id",
_level: 42
},
parents: [],
ignored: true
};
preprocessor.processedProjects = {
"some.id": alreadyProcessedProject
};

const project = {
id: "some.id",
_level: 1337
};
const otherProject = {
id: "some.other.id"
};
const parent = {
dependencies: [otherProject]
};
const res = preprocessor.isBeingProcessed(parent, project);
t.deepEqual(res, true, "Project is already processed");
t.deepEqual(parent.dependencies.length, 1, "Parent still has one dependency");
t.deepEqual(parent.dependencies[0].id, "some.other.id",
"Parent dependency to another project has not been removed");
t.deepEqual(alreadyProcessedProject.parents.length, 0, "Already processed project still has no parents");
});

test("isBeingProcessed: Deduped project is being ignored", (t) => {
const preprocessor = new projectPreprocessor.ProjectPreprocessor();

preprocessor.processedProjects = {};

const project = {
deduped: true
};
const parent = {};

const res = preprocessor.isBeingProcessed(parent, project);
t.deepEqual(res, true, "Project is being ignored");
});

0 comments on commit 4600d63

Please sign in to comment.