Skip to content

Commit 9b9b7d7

Browse files
authored
[INTERNAL] Specification#getRootReader: Use .gitignore excludes by default (#535)
1 parent 6640f63 commit 9b9b7d7

File tree

2 files changed

+95
-7
lines changed

2 files changed

+95
-7
lines changed

lib/specifications/Specification.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,21 @@ class Specification {
216216

217217
/* === Resource Access === */
218218
/**
219-
* Get a [ReaderCollection]{@link @ui5/fs/ReaderCollection} for the root directory of the specification.
220-
* Resource readers always use POSIX-style
221-
*
222-
* @public
223-
* @returns {@ui5/fs/ReaderCollection} Reader collection
219+
* Get a [ReaderCollection]{@link @ui5/fs/ReaderCollection} for the root directory of the specification.
220+
* Resource readers always use POSIX-style
221+
*
222+
* @public
223+
* @param {object} [parameters] Parameters
224+
* @param {object} [parameters.useGitignore=true]
225+
* Whether to apply any excludes defined in an optional .gitignore in the root directory
226+
* @returns {@ui5/fs/ReaderCollection} Reader collection
224227
*/
225-
getRootReader() {
228+
getRootReader({useGitignore=true} = {}) {
226229
return createReader({
227230
fsBasePath: this.getPath(),
228231
virBasePath: "/",
229-
name: `Root reader for ${this.getType()} ${this.getKind()} ${this.getName()}`
232+
name: `Root reader for ${this.getType()} ${this.getKind()} ${this.getName()}`,
233+
useGitignore
230234
});
231235
}
232236

test/lib/specifications/Specification.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import test from "ava";
2+
import esmock from "esmock";
23
import path from "node:path";
34
import {fileURLToPath} from "node:url";
45
import sinon from "sinon";
@@ -19,6 +20,24 @@ const themeLibraryEPath = path.join(__dirname, "..", "..", "fixtures", "theme.li
1920
const genericExtensionPath = path.join(__dirname, "..", "..", "fixtures", "extension.a");
2021
const moduleAPath = path.join(__dirname, "..", "..", "fixtures", "module.a");
2122

23+
function createSubclass(Specification) {
24+
class DummySpecification extends Specification {
25+
getPath() {
26+
return "path";
27+
}
28+
getType() {
29+
return "type";
30+
}
31+
getKind() {
32+
return "kind";
33+
}
34+
getName() {
35+
return "name";
36+
}
37+
}
38+
return DummySpecification;
39+
}
40+
2241
test.beforeEach((t) => {
2342
t.context.basicProjectInput = {
2443
id: "application.a.id",
@@ -37,6 +56,14 @@ test.afterEach.always((t) => {
3756
sinon.restore();
3857
});
3958

59+
test("Specification can't be instantiated", (t) => {
60+
t.throws(() => {
61+
new Specification();
62+
}, {
63+
message: "Class 'Specification' is abstract. Please use one of the 'types' subclasses"
64+
});
65+
});
66+
4067
test("Instantiate a basic project", async (t) => {
4168
const project = await Specification.create(t.context.basicProjectInput);
4269
t.is(project.getName(), "application.a", "Returned correct name");
@@ -299,3 +326,60 @@ test("Invalid specVersion", async (t) => {
299326
"For details, see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions"
300327
}, "Threw with expected error message");
301328
});
329+
330+
test("getRootReader: Default parameters", async (t) => {
331+
// Since Specification#create instantiates a far-away subclass, it would be a mess to mock
332+
// every class up to "Specification.js" just to stub the resourceFactory's createReader method
333+
// Therefore we just come up with our own subclass that can be instantiated right away:
334+
335+
const createReaderStub = sinon.stub();
336+
const Specification = await esmock("../../../lib/specifications/Specification.js", {
337+
"@ui5/fs/resourceFactory": {
338+
createReader: createReaderStub
339+
}
340+
});
341+
342+
const DummySpecification = createSubclass(Specification);
343+
const spec = new DummySpecification();
344+
await spec.getRootReader();
345+
346+
t.is(createReaderStub.callCount, 1, "createReader got called once");
347+
t.deepEqual(createReaderStub.getCall(0).args[0], {
348+
fsBasePath: "path",
349+
name: "Root reader for type kind name",
350+
useGitignore: true,
351+
virBasePath: "/",
352+
}, "createReader got called with expected arguments");
353+
});
354+
355+
test("getRootReader: Custom parameters", async (t) => {
356+
const createReaderStub = sinon.stub();
357+
const Specification = await esmock("../../../lib/specifications/Specification.js", {
358+
"@ui5/fs/resourceFactory": {
359+
createReader: createReaderStub
360+
}
361+
});
362+
363+
const DummySpecification = createSubclass(Specification);
364+
const spec = new DummySpecification();
365+
await spec.getRootReader({});
366+
await spec.getRootReader({
367+
useGitignore: false
368+
});
369+
370+
371+
t.is(createReaderStub.callCount, 2, "createReader got called twice");
372+
t.deepEqual(createReaderStub.getCall(0).args[0], {
373+
fsBasePath: "path",
374+
name: "Root reader for type kind name",
375+
useGitignore: true,
376+
virBasePath: "/",
377+
}, "createReader got called with expected arguments on first call");
378+
379+
t.deepEqual(createReaderStub.getCall(1).args[0], {
380+
fsBasePath: "path",
381+
name: "Root reader for type kind name",
382+
useGitignore: false,
383+
virBasePath: "/",
384+
}, "createReader got called with expected arguments on second call");
385+
});

0 commit comments

Comments
 (0)