From e619b32b7d178da5f2f71f65ec7c0a85514408e4 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Mon, 16 Mar 2020 14:30:34 +0100 Subject: [PATCH 1/9] [BREAKING] Make namespace mandatory for application and library projects BREAKING CHANGE: UI5 Project must be able to determine the project's namespace, otherwise an error is thrown. --- lib/types/application/ApplicationFormatter.js | 8 +------- lib/types/library/LibraryFormatter.js | 8 +------- .../types/application/ApplicationFormatter.js | 18 ++++++++---------- test/lib/types/library/LibraryFormatter.js | 13 +++++-------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/lib/types/application/ApplicationFormatter.js b/lib/types/application/ApplicationFormatter.js index 2a3fb0b3e..448089d54 100644 --- a/lib/types/application/ApplicationFormatter.js +++ b/lib/types/application/ApplicationFormatter.js @@ -20,13 +20,7 @@ class ApplicationFormatter extends AbstractUi5Formatter { "/": project.resources.configuration.paths.webapp }; - try { - project.metadata.namespace = await this.getNamespace(); - } catch (err) { - // Catch error because namespace is optional - // TODO 2.0: Make namespace mandatory and just let the error throw - log.warn(err.message); - } + project.metadata.namespace = await this.getNamespace(); } /** diff --git a/lib/types/library/LibraryFormatter.js b/lib/types/library/LibraryFormatter.js index ce78819dd..8916169ec 100644 --- a/lib/types/library/LibraryFormatter.js +++ b/lib/types/library/LibraryFormatter.js @@ -31,13 +31,7 @@ class LibraryFormatter extends AbstractUi5Formatter { "Either no setting was provided or the path not found."); } - try { - project.metadata.namespace = await this.getNamespace(); - } catch (err) { - // Catch error because namespace is optional - // TODO 2.0: Make namespace mandatory and just let the error throw - log.warn(err.message); - } + project.metadata.namespace = await this.getNamespace(); try { project.metadata.copyright = await this.getCopyright(); diff --git a/test/lib/types/application/ApplicationFormatter.js b/test/lib/types/application/ApplicationFormatter.js index 67919da95..a7a2e4938 100644 --- a/test/lib/types/application/ApplicationFormatter.js +++ b/test/lib/types/application/ApplicationFormatter.js @@ -136,10 +136,9 @@ test("format: No 'sap.app' configuration found", async (t) => { sinon.stub(applicationFormatter, "validate").resolves(); sinon.stub(applicationFormatter, "getManifest").resolves({content: {}, fsPath: {}}); - await applicationFormatter.format(); - t.deepEqual(project.resources.pathMappings["/"], "webapp", "path mappings is set"); - t.falsy(project.metadata.namespace, - "namespace is falsy since getManifest resolves with an empty object"); + const error = await t.throwsAsync(applicationFormatter.format()); + t.deepEqual(error.message,"No \"sap.app\" ID configuration found in manifest.json of project projectName", + "Rejected with correct error message"); }); test("format: No application id in 'sap.app' configuration found", async (t) => { @@ -148,10 +147,9 @@ test("format: No application id in 'sap.app' configuration found", async (t) => sinon.stub(applicationFormatter, "validate").resolves(); sinon.stub(applicationFormatter, "getManifest").resolves({content: {"sap.app": {}}}); - await applicationFormatter.format(); + const error = await t.throwsAsync(applicationFormatter.format()); + t.deepEqual(error.message, "No \"sap.app\" ID configuration found in manifest.json of project projectName"); t.deepEqual(project.resources.pathMappings["/"], "webapp", "path mappings is set"); - t.falsy(project.metadata.namespace, - "namespace is falsy since getManifest resolves with an empty object"); }); test("format: set namespace to id", async (t) => { @@ -278,7 +276,7 @@ test("namespace: detect namespace from pom.xml via ${appId} from properties", as myProject.resources.configuration.paths.webapp = "webapp-properties.appId"; const applicationFormatter = new ApplicationFormatter({project: myProject}); - await applicationFormatter.format(); - t.falsy(myProject.metadata.namespace, - "namespace is falsy since getManifest resolves with an empty object"); + const error = await t.throwsAsync(applicationFormatter.format()); + t.deepEqual(error.message, "Failed to resolve namespace of project application.h: \"${appId}\"" + + " couldn't be resolved from maven property \"appId\" of pom.xml of project application.h"); }); diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index 5d13f6ebc..ccda20cb7 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -202,12 +202,15 @@ test.serial("format: namespace resolution fails", async (t) => { sinon.stub(libraryFormatter, "validate").resolves(); - await libraryFormatter.format(); + const error = await t.throwsAsync(libraryFormatter.format()); + t.deepEqual(error.message, "Failed to detect namespace or namespace is empty for project library.e." + + " Check verbose log for details."); + t.deepEqual(globbyStub.callCount, 3, "globby got called three times"); t.deepEqual(globbyStub.getCall(0).args[0], "**/manifest.json", "First glob is for manifest.json files"); t.deepEqual(globbyStub.getCall(1).args[0], "**/.library", "Second glob is for .library files"); t.deepEqual(globbyStub.getCall(2).args[0], "**/library.js", "Third glob for library.js files"); - t.deepEqual(loggerVerboseSpy.callCount, 7, "7 calls to log.verbose should be done"); + t.deepEqual(loggerVerboseSpy.callCount, 6, "7 calls to log.verbose should be done"); const logVerboseCalls = loggerVerboseSpy.getCalls().map((call) => call.args[0]); t.true(logVerboseCalls.includes( @@ -225,12 +228,6 @@ test.serial("format: namespace resolution fails", async (t) => { "Could not find library.js file for project library.e"), "should contain message for missing library.js"); - t.deepEqual(loggerWarnSpy.callCount, 1, "1 calls to log.warn should be done"); - const logWarnCalls = loggerWarnSpy.getCalls().map((call) => call.args[0]); - t.true(logWarnCalls.includes( - "Failed to detect namespace or namespace is empty for project library.e. Check verbose log for details."), - "should contain message for .library"); - mock.stop("globby"); mock.stop("@ui5/logger"); }); From 9901f91f7ca7dbee3a03f381b6f18ed931586042 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Tue, 17 Mar 2020 10:35:04 +0100 Subject: [PATCH 2/9] [BREAKING] Make namespace mandatory for application and library projects BREAKING CHANGE: UI5 Project must be able to determine the project's namespace, otherwise an error is thrown. --- test/lib/types/application/ApplicationFormatter.js | 2 +- test/lib/types/library/LibraryFormatter.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/lib/types/application/ApplicationFormatter.js b/test/lib/types/application/ApplicationFormatter.js index a7a2e4938..c8da91225 100644 --- a/test/lib/types/application/ApplicationFormatter.js +++ b/test/lib/types/application/ApplicationFormatter.js @@ -137,7 +137,7 @@ test("format: No 'sap.app' configuration found", async (t) => { sinon.stub(applicationFormatter, "getManifest").resolves({content: {}, fsPath: {}}); const error = await t.throwsAsync(applicationFormatter.format()); - t.deepEqual(error.message,"No \"sap.app\" ID configuration found in manifest.json of project projectName", + t.deepEqual(error.message, "No \"sap.app\" ID configuration found in manifest.json of project projectName", "Rejected with correct error message"); }); diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index ccda20cb7..8433108e8 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -194,7 +194,6 @@ test.serial("format: namespace resolution fails", async (t) => { }); mock.reRequire("@ui5/logger"); const loggerVerboseSpy = sinon.spy(loggerInstance, "verbose"); - const loggerWarnSpy = sinon.spy(loggerInstance, "warn"); const LibraryFormatter = mock.reRequire("../../../../lib/types/library/LibraryFormatter"); From bb1bc7626e4a4238f87291ebc1846d3c579f0405 Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Tue, 17 Mar 2020 12:45:16 +0100 Subject: [PATCH 3/9] Add Test for getNamespace call To increase the test coverage again --- test/lib/types/library/LibraryFormatter.js | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index 8433108e8..5138826fc 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -477,24 +477,38 @@ test("getNamespace: from manifest.json", async (t) => { t.deepEqual(res, "mani-pony", "Returned correct namespace"); }); -test("getNamespace: from manifest.json with not matching file path", async (t) => { +test.serial("getNamespace: from manifest.json without sap.app id", async (t) => { const myProject = clone(libraryETree); + const log = require("@ui5/logger"); + const loggerInstance = log.getLogger("types:library:LibraryFormatter"); + + mock("@ui5/logger", { + getLogger: () => loggerInstance + }); + mock.reRequire("@ui5/logger"); + + const LibraryFormatter = mock.reRequire("../../../../lib/types/library/LibraryFormatter"); + const libraryFormatter = new LibraryFormatter({project: myProject}); sinon.stub(libraryFormatter, "getManifest").resolves({ content: { "sap.app": { - id: "mani-pony" } }, fsPath: path.normalize("/some/path/different/namespace/manifest.json") // normalize for windows }); sinon.stub(libraryFormatter, "getSourceBasePath").returns("/some/path/"); + + const loggerSpy = sinon.spy(loggerInstance, "verbose"); const err = await t.throwsAsync(libraryFormatter.getNamespace()); - t.deepEqual(err.message, `Detected namespace "mani-pony" does not match detected directory structure ` + - `"different/namespace" for project library.e`, - "Rejected with correct error message"); + t.deepEqual(err.message, `Failed to detect namespace or namespace is empty for project library.e. Check verbose log for details.`, "Rejected with correct error message"); + t.is(loggerSpy.callCount, 4, "call to verbose"); + + + t.is(loggerSpy.getCall(0).args[0], "No \"sap.app\" ID configuration found in manifest.json of project library.e", "correct verbose message"); + mock.stop("@ui5/logger"); }); test("getNamespace: from .library", async (t) => { From 3c2f3a14a8765d285410c0729a4ea33c45297cd0 Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Tue, 17 Mar 2020 13:01:13 +0100 Subject: [PATCH 4/9] Add Test for getCopyright call To increase the test coverage again --- test/lib/types/library/LibraryFormatter.js | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index 5138826fc..b943eb928 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -140,6 +140,34 @@ test("format: copyright already configured", async (t) => { t.deepEqual(myProject.metadata.copyright, libraryETree.metadata.copyright, "Copyright was not altered"); }); +test.serial("format: copyright retrieval fails", async (t) => { + const myProject = clone(libraryETree); + + const log = require("@ui5/logger"); + const loggerInstance = log.getLogger("types:library:LibraryFormatter"); + + mock("@ui5/logger", { + getLogger: () => loggerInstance + }); + mock.reRequire("@ui5/logger"); + const loggerVerboseSpy = sinon.spy(loggerInstance, "verbose"); + + const LibraryFormatter = mock.reRequire("../../../../lib/types/library/LibraryFormatter"); + + const libraryFormatter = new LibraryFormatter({project: myProject}); + sinon.stub(libraryFormatter, "validate").resolves(); + sinon.stub(libraryFormatter, "getCopyright").rejects(Error("my-pony")); + + await libraryFormatter.format(); + t.deepEqual(myProject.metadata.copyright, libraryETree.metadata.copyright, "Copyright was not altered"); + + + t.is(loggerVerboseSpy.callCount, 4, "calls to verbose"); + t.is(loggerVerboseSpy.getCall(3).args[0], "my-pony", "message from rejection"); + + mock.stop("@ui5/logger"); +}); + test("format: formats correctly", async (t) => { const myProject = clone(libraryETree); myProject.metadata.copyright = undefined; @@ -504,7 +532,7 @@ test.serial("getNamespace: from manifest.json without sap.app id", async (t) => const err = await t.throwsAsync(libraryFormatter.getNamespace()); t.deepEqual(err.message, `Failed to detect namespace or namespace is empty for project library.e. Check verbose log for details.`, "Rejected with correct error message"); - t.is(loggerSpy.callCount, 4, "call to verbose"); + t.is(loggerSpy.callCount, 4, "calls to verbose"); t.is(loggerSpy.getCall(0).args[0], "No \"sap.app\" ID configuration found in manifest.json of project library.e", "correct verbose message"); From d7c7ebf195bd8652f5bae23d3ef06e2317ce939a Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Tue, 17 Mar 2020 13:05:34 +0100 Subject: [PATCH 5/9] re-added test for getNamespace getNamespace: from manifest.json with not matching file path --- test/lib/types/library/LibraryFormatter.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index b943eb928..cb075aa6c 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -505,6 +505,25 @@ test("getNamespace: from manifest.json", async (t) => { t.deepEqual(res, "mani-pony", "Returned correct namespace"); }); +test("getNamespace: from manifest.json with not matching file path", async (t) => { + const myProject = clone(libraryETree); + + const libraryFormatter = new LibraryFormatter({project: myProject}); + sinon.stub(libraryFormatter, "getManifest").resolves({ + content: { + "sap.app": { + id: "mani-pony" + } + }, + fsPath: path.normalize("/some/path/different/namespace/manifest.json") // normalize for windows + }); + sinon.stub(libraryFormatter, "getSourceBasePath").returns("/some/path/"); + const err = await t.throwsAsync(libraryFormatter.getNamespace()); + + t.deepEqual(err.message, `Detected namespace "mani-pony" does not match detected directory structure ` + + `"different/namespace" for project library.e`, "Rejected with correct error message"); +}); + test.serial("getNamespace: from manifest.json without sap.app id", async (t) => { const myProject = clone(libraryETree); From 7b8fc99f4db3f6fd7a1053975cb796ec9743066c Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Tue, 17 Mar 2020 13:22:43 +0100 Subject: [PATCH 6/9] add test for ApplicationFormatter#getSourceBasePath --- test/lib/types/application/ApplicationFormatter.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/lib/types/application/ApplicationFormatter.js b/test/lib/types/application/ApplicationFormatter.js index c8da91225..103df88e3 100644 --- a/test/lib/types/application/ApplicationFormatter.js +++ b/test/lib/types/application/ApplicationFormatter.js @@ -130,6 +130,15 @@ function createMockProject() { }; } +test("getSourceBasePath: posix", async (t) => { + const myProject = clone(applicationBTree); + myProject.path = "my/pony"; + const applicationFormatter = new ApplicationFormatter({project: myProject}); + + const sourceBasePath = applicationFormatter.getSourceBasePath(true); + t.is(sourceBasePath, "my/pony/webapp", "correct path"); +}); + test("format: No 'sap.app' configuration found", async (t) => { const project = createMockProject(); const applicationFormatter = new ApplicationFormatter({project}); From 7773b4e8c6154330a16e6c7a5aff79ecc5579c63 Mon Sep 17 00:00:00 2001 From: Tobias Sorn Date: Tue, 17 Mar 2020 13:38:27 +0100 Subject: [PATCH 7/9] add test for LibraryFormatter#getLibraryJsPath and getDotLibrary --- test/lib/types/library/LibraryFormatter.js | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index cb075aa6c..3389c6e50 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -284,6 +284,21 @@ test("getDotLibrary: reads correctly", async (t) => { t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); }); +test("getDotLibrary: reads correctly call again", async (t) => { + const myProject = clone(libraryETree); + myProject.resources.pathMappings = { + "/resources/": myProject.resources.configuration.paths.src + }; + + const libraryFormatter = new LibraryFormatter({project: myProject}); + + const {content} = await libraryFormatter.getDotLibrary(); + t.deepEqual(content.library.name, "library.e", ".library content has been read"); + + const {content: contentSecondCall} = await libraryFormatter.getDotLibrary(); + t.deepEqual(contentSecondCall.library.name, "library.e", ".library content has been read second time"); +}); + test.serial("getDotLibrary: multiple dot library files", async (t) => { const myProject = clone(libraryETree); myProject.resources.pathMappings = { @@ -365,6 +380,25 @@ test("getLibraryJsPath: reads correctly", async (t) => { t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); }); +test("getLibraryJsPath: reads correctly call again", async (t) => { + const myProject = clone(libraryETree); + myProject.resources.pathMappings = { + "/resources/": myProject.resources.configuration.paths.src + }; + + const libraryFormatter = new LibraryFormatter({project: myProject}); + + const fsPath = await libraryFormatter.getLibraryJsPath(); + const expectedPath = path.join(myProject.path, + myProject.resources.configuration.paths.src, "library", "e", "library.js"); + t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); + + const fsPathSecondCall = await libraryFormatter.getLibraryJsPath(); + const expectedPathSecondCall = path.join(myProject.path, + myProject.resources.configuration.paths.src, "library", "e", "library.js"); + t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); +}); + test.serial("getLibraryJsPath: multiple dot library files", async (t) => { const myProject = clone(libraryETree); myProject.resources.pathMappings = { From 680dcd12691d1b29907e1fc8f3af85ca7a1c1453 Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Tue, 17 Mar 2020 14:45:19 +0100 Subject: [PATCH 8/9] Updating unit test to check if getDotLibrary works when loading from cache. --- test/lib/types/library/LibraryFormatter.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index 3389c6e50..eb0761867 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -282,21 +282,13 @@ test("getDotLibrary: reads correctly", async (t) => { const expectedPath = path.join(myProject.path, myProject.resources.configuration.paths.src, "library", "e", ".library"); t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); -}); -test("getDotLibrary: reads correctly call again", async (t) => { - const myProject = clone(libraryETree); - myProject.resources.pathMappings = { - "/resources/": myProject.resources.configuration.paths.src - }; - - const libraryFormatter = new LibraryFormatter({project: myProject}); - - const {content} = await libraryFormatter.getDotLibrary(); - t.deepEqual(content.library.name, "library.e", ".library content has been read"); - - const {content: contentSecondCall} = await libraryFormatter.getDotLibrary(); - t.deepEqual(contentSecondCall.library.name, "library.e", ".library content has been read second time"); + const {content: contentSecondCall, fsPath: fsPathSecondCall} = await libraryFormatter.getDotLibrary(); + t.deepEqual(contentSecondCall.library.name, "library.e", ".library content has been read," + + "but should be cached now."); + const expectedPathSecondCall = path.join(myProject.path, + myProject.resources.configuration.paths.src, "library", "e", ".library"); + t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); }); test.serial("getDotLibrary: multiple dot library files", async (t) => { From cc69b7938f91c03691894f5077ad6fe38921180f Mon Sep 17 00:00:00 2001 From: Sven Bender Date: Wed, 18 Mar 2020 09:30:58 +0100 Subject: [PATCH 9/9] Updating unit test to check if getDotLibrary works when loading from cache. --- .../types/application/ApplicationFormatter.js | 3 +- test/lib/types/library/LibraryFormatter.js | 39 ++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/test/lib/types/application/ApplicationFormatter.js b/test/lib/types/application/ApplicationFormatter.js index 103df88e3..402f83223 100644 --- a/test/lib/types/application/ApplicationFormatter.js +++ b/test/lib/types/application/ApplicationFormatter.js @@ -227,11 +227,12 @@ test.serial("getManifest: result is cached", async (t) => { const ApplicationFormatter = mock.reRequire("../../../../lib/types/application/ApplicationFormatter"); const libraryFormatter = new ApplicationFormatter({project: myProject}); - const expectedPath = path.join(applicationBPath, "webapp", "manifest.json"); + const {content, fsPath} = await libraryFormatter.getManifest(); t.deepEqual(content, {pony: "no unicorn"}, "Correct result on first call"); t.deepEqual(fsPath, expectedPath, "Correct manifest.json path returned on first call"); + const {content: content2, fsPath: fsPath2} = await libraryFormatter.getManifest(); t.deepEqual(content2, {pony: "no unicorn"}, "Correct result on second call"); t.deepEqual(fsPath2, expectedPath, "Correct manifest.json path returned on second call"); diff --git a/test/lib/types/library/LibraryFormatter.js b/test/lib/types/library/LibraryFormatter.js index eb0761867..9d63bc858 100644 --- a/test/lib/types/library/LibraryFormatter.js +++ b/test/lib/types/library/LibraryFormatter.js @@ -282,13 +282,6 @@ test("getDotLibrary: reads correctly", async (t) => { const expectedPath = path.join(myProject.path, myProject.resources.configuration.paths.src, "library", "e", ".library"); t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); - - const {content: contentSecondCall, fsPath: fsPathSecondCall} = await libraryFormatter.getDotLibrary(); - t.deepEqual(contentSecondCall.library.name, "library.e", ".library content has been read," + - "but should be cached now."); - const expectedPathSecondCall = path.join(myProject.path, - myProject.resources.configuration.paths.src, "library", "e", ".library"); - t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); }); test.serial("getDotLibrary: multiple dot library files", async (t) => { @@ -344,7 +337,6 @@ test.serial("getDotLibrary: result is cached", async (t) => { mock.reRequire("globby"); const LibraryFormatter = mock.reRequire("../../../../lib/types/library/LibraryFormatter"); - const libraryFormatter = new LibraryFormatter({project: myProject}); const {content, fsPath} = await libraryFormatter.getDotLibrary(); @@ -353,6 +345,13 @@ test.serial("getDotLibrary: result is cached", async (t) => { myProject.resources.configuration.paths.src, "library", "e", ".library"); t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); + const {content: contentSecondCall, fsPath: fsPathSecondCall} = await libraryFormatter.getDotLibrary(); + t.deepEqual(contentSecondCall.library.name, "library.e", ".library content has been read," + + "but should be cached now."); + const expectedPathSecondCall = path.join(myProject.path, + myProject.resources.configuration.paths.src, "library", "e", ".library"); + t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); + t.deepEqual(globbySpy.callCount, 1, "globby got called exactly once (and then cached)"); mock.stop("globby"); @@ -372,25 +371,6 @@ test("getLibraryJsPath: reads correctly", async (t) => { t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); }); -test("getLibraryJsPath: reads correctly call again", async (t) => { - const myProject = clone(libraryETree); - myProject.resources.pathMappings = { - "/resources/": myProject.resources.configuration.paths.src - }; - - const libraryFormatter = new LibraryFormatter({project: myProject}); - - const fsPath = await libraryFormatter.getLibraryJsPath(); - const expectedPath = path.join(myProject.path, - myProject.resources.configuration.paths.src, "library", "e", "library.js"); - t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); - - const fsPathSecondCall = await libraryFormatter.getLibraryJsPath(); - const expectedPathSecondCall = path.join(myProject.path, - myProject.resources.configuration.paths.src, "library", "e", "library.js"); - t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); -}); - test.serial("getLibraryJsPath: multiple dot library files", async (t) => { const myProject = clone(libraryETree); myProject.resources.pathMappings = { @@ -452,6 +432,11 @@ test.serial("getLibraryJsPath: result is cached", async (t) => { myProject.resources.configuration.paths.src, "library", "e", "library.js"); t.deepEqual(fsPath, expectedPath, ".library fsPath is correct"); + const fsPathSecondCall = await libraryFormatter.getLibraryJsPath(); + const expectedPathSecondCall = path.join(myProject.path, + myProject.resources.configuration.paths.src, "library", "e", "library.js"); + t.deepEqual(fsPathSecondCall, expectedPathSecondCall, ".library fsPath is correct"); + t.deepEqual(globbySpy.callCount, 1, "globby got called exactly once (and then cached)"); mock.stop("globby");