Skip to content

Commit

Permalink
resourceFactory: Add test for createCollectionsForTree with excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed May 23, 2019
1 parent 248d604 commit 8c97b14
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions test/lib/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const chai = require("chai");
const path = require("path");
chai.use(require("chai-fs"));
const assert = chai.assert;
const sinon = require("sinon");

const ui5Fs = require("../../");
const applicationBPath = path.join(__dirname, "..", "fixtures", "application.b");
Expand All @@ -21,6 +22,10 @@ test.beforeEach((t) => {
};
});

test.afterEach.always((t) => {
sinon.restore();
});

/* BEWARE:
Always make sure that every test writes to a separate file! By default, tests are running concurrent.
*/
Expand Down Expand Up @@ -56,6 +61,59 @@ test("createCollectionsForTree", (t) => {
t.true(resourceReaders.dependencies._readers.length === 8, "Eight readers for the application's dependencies");
});

// TODO: Implement proper createCollectionsForTree unit test

test.serial("createCollectionsForTree with excludes", (t) => {
const createAdapterSpy = sinon.spy(ui5Fs.resourceFactory, "createAdapter");
ui5Fs.resourceFactory.createCollectionsForTree(applicationBTreeWithExcludes, {
getProjectExcludes: (proj) => {
return proj.pony.excludes;
}
});

t.deepEqual(createAdapterSpy.callCount, 5, "createAdapter got called three times");

const firstCall = createAdapterSpy.getCall(0).args[0];
t.deepEqual(firstCall.fsBasePath, path.join(applicationBPath, "webapp"),
"First createAdapter call: Correct base path supplied");
t.deepEqual(firstCall.excludes, ["/pony-path/*"],
"First createAdapter call: Correct exclude patterns supplied");

const secondCall = createAdapterSpy.getCall(1).args[0];
t.deepEqual(secondCall.fsBasePath,
path.join(applicationBPath, "node_modules", "library.d", "main", "src"),
"Second createAdapter call: Correct base path supplied");
t.deepEqual(secondCall.excludes, [
"/unicorn-path/*",
"/duck-path/*"
],
"Second createAdapter call: Correct exclude patterns supplied");

const thirdCall = createAdapterSpy.getCall(2).args[0];
t.deepEqual(thirdCall.fsBasePath,
path.join(applicationBPath, "node_modules", "library.d", "main", "test"),
"Third createAdapter call: Correct base path supplied");
t.deepEqual(thirdCall.excludes, [
"/unicorn-path/*",
"/duck-path/*"
],
"Third createAdapter call: Correct exclude patterns supplied");

const fourthCall = createAdapterSpy.getCall(3).args[0];
t.deepEqual(fourthCall.fsBasePath,
path.join(applicationBPath, "node_modules", "collection", "library.a", "src"),
"Fourth createAdapter call: Correct base path supplied");
t.deepEqual(fourthCall.excludes, ["/duck-path/*"],
"Fourth createAdapter call: Correct exclude patterns supplied");

const fifthCall = createAdapterSpy.getCall(4).args[0];
t.deepEqual(fifthCall.fsBasePath,
path.join(applicationBPath, "node_modules", "collection", "library.a", "test"),
"Fifth createAdapter call: Correct base path supplied");
t.deepEqual(fifthCall.excludes, ["/duck-path/*"],
"Fifth createAdapter call: Correct exclude patterns supplied");
});

/* Test data */
const applicationBTree = {
"id": "application.b",
Expand Down Expand Up @@ -182,3 +240,94 @@ const applicationBTree = {
}
}
};

const applicationBTreeWithExcludes = {
"id": "application.b",
"version": "1.0.0",
"path": applicationBPath,
"dependencies": [
{
"id": "library.d",
"version": "1.0.0",
"path": path.join(applicationBPath, "node_modules", "library.d"),
"dependencies": [],
"_level": 1,
"specVersion": "0.1",
"type": "library",
"metadata": {
"name": "library.d",
"copyright": "Some fancy copyright"
},
"pony": {
"excludes": [
"/unicorn-path/*",
"/duck-path/*"
]
},
"resources": {
"configuration": {
"paths": {
"src": "main/src",
"test": "main/test"
}
},
"pathMappings": {
"/resources/": "main/src",
"/test-resources/": "main/test"
}
}
},
{
"id": "library.a",
"version": "1.0.0",
"path": path.join(applicationBPath, "node_modules", "collection", "library.a"),
"dependencies": [],
"_level": 1,
"specVersion": "0.1",
"type": "library",
"metadata": {
"name": "library.a",
"copyright": "${copyright}"
},
"pony": {
"excludes": [
"/duck-path/*"
]
},
"resources": {
"configuration": {
"paths": {
"src": "src",
"test": "test"
}
},
"pathMappings": {
"/resources/": "src",
"/test-resources/": "test"
}
}
},
],
"pony": {
"excludes": [
"/pony-path/*"
]
},
"_level": 0,
"specVersion": "0.1",
"type": "application",
"metadata": {
"name": "application.b",
"namespace": "id1"
},
"resources": {
"configuration": {
"paths": {
"webapp": "webapp"
}
},
"pathMappings": {
"/": "webapp"
}
}
};

0 comments on commit 8c97b14

Please sign in to comment.