Skip to content

Commit 4c443d9

Browse files
authored
chore: more robust test execution from different root dir (#73)
When tests are executed from a different root dir, e.g in a parent monorepo, they still need to resolve paths reliably, i.e. using `__dirname`. Also write config file path in case of errors.
1 parent 97d7518 commit 4c443d9

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lib/compile/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function toOpenApiOptions(csdl, csn, options = {}) {
104104
}
105105
});
106106
} else {
107-
throw new Error("Error while parsing the openapi configuration file");
107+
throw new Error("Error while parsing the openapi configuration file " + result["config-file"]);
108108
}
109109
}
110110

test/lib/compile/openapi.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ service CatalogService {
286286
const csn = cds.compile.to.csn(`
287287
service A {entity E { key ID : UUID; };};`
288288
);
289-
const openapi = toOpenApi(csn, { 'openapi:config-file': path.resolve("./test/lib/compile/data/configFile.json") });
289+
const openapi = toOpenApi(csn, { 'openapi:config-file': path.resolve(__dirname, "data/configFile.json") });
290290
expect(openapi.servers).toBeTruthy();
291291
expect(openapi).toMatchObject({ servers: [{ url: 'http://foo.bar:8080' }, { url: "http://foo.bar:8080/a/foo" }] });
292292
expect(openapi.info.description).toMatch(/yuml.*diagram/i);
@@ -298,7 +298,7 @@ service CatalogService {
298298
@title:'It is located at http://example.com:8080' service A {entity E { key ID : UUID;};};`
299299
);
300300
const options = {
301-
'openapi:config-file': path.resolve("./test/lib/compile/data/configFile.json"),
301+
'openapi:config-file': path.resolve(__dirname, "data/configFile.json"),
302302
'openapi:url': "http://example.com:8080",
303303
'odata-version': '4.0',
304304
'openapi:diagram': "false"
@@ -398,9 +398,9 @@ service CatalogService {
398398
const csn = cds.compile.to.csn(`
399399
namespace sap.odm.test;
400400
service A {
401-
entity E1 {
402-
key id: String(4);
403-
oid: String(128);
401+
entity E1 {
402+
key id: String(4);
403+
oid: String(128);
404404
@ODM.oidReference.entityName: 'ReferencedEntityName'
405405
ref: Association to one E2;
406406
}
@@ -505,9 +505,9 @@ service CatalogService {
505505
url: 'https://help.sap.com/docs/product/123.html'
506506
}
507507
service A {
508-
entity E1 {
509-
key id: String(4);
510-
oid: String(128);
508+
entity E1 {
509+
key id: String(4);
510+
oid: String(128);
511511
}
512512
}`);
513513
const openAPI = toOpenApi(csn);
@@ -534,17 +534,17 @@ service CatalogService {
534534
@OpenAPI.Extensions: {
535535
![dpp-is-potentially-sensitive]: 'true'
536536
}
537-
entity E1 {
538-
key id: String(4);
539-
oid: String(128);
537+
entity E1 {
538+
key id: String(4);
539+
oid: String(128);
540540
}
541-
541+
542542
@OpenAPI.Extensions: {
543543
![x-sap-operation-intent]: 'read-collection for function',
544544
![sap-deprecated-operation] : {
545545
deprecationDate: '2022-12-31',
546546
successorOperationId: 'successorOperation',
547-
notValidKey: 'notValidValue'
547+
notValidKey: 'notValidValue'
548548
}
549549
}
550550
function F1(param: String) returns String;
@@ -553,7 +553,7 @@ service CatalogService {
553553
![x-sap-operation-intent]: 'read-collection for action'
554554
}
555555
action A1(param: String) returns String;
556-
556+
557557
}`);
558558
const openAPI = toOpenApi(csn);
559559
expect(openAPI).toBeDefined();

0 commit comments

Comments
 (0)