Skip to content

Commit 7382378

Browse files
flovogtmatz3
authored andcommitted
[INTERNAL] add tests for async functions and logical operators
1 parent 57bec2c commit 7382378

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// async function with await
2+
sap.ui.define([], async () => {
3+
return await sap.ui.require(["static/module1"], async () => {});
4+
// await and sap.ui.require, makes so sense because it does NOT return a promise but it should still be analyzed
5+
});

test/fixtures/lbt/modules/es6-syntax.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ sap.ui.define([
4040
};
4141

4242
// chain expression
43-
if (m1?.foo?.bar) {
44-
sap.ui.require(["conditional/module4"]);
45-
}
43+
4644
// TODO: This is not detected as conditional dependency
47-
// sap?.ui?.require(["conditional/module5"]);
45+
// sap?.ui?.require(["conditional/module4"]);
4846

47+
// iterator pattern
4948
const iterator = {
5049
[Symbol.iterator]() {
5150
return {
@@ -57,6 +56,7 @@ sap.ui.define([
5756
}
5857
}
5958

59+
// generator pattern
6060
let generator = {
6161
*[Symbol.iterator]() {
6262
for (;;) {
@@ -66,6 +66,7 @@ sap.ui.define([
6666
}
6767
}
6868

69+
// class declaration
6970
class Clz {
7071

7172
* bar () {
@@ -80,8 +81,10 @@ sap.ui.define([
8081

8182
};
8283

83-
// TODO: This is not detected as conditional dependency
84+
// TODO: This is not detected as a conditional dependency -> Currently, these kind of logical operators are not analyzed
8485
// m1 ?? sap.ui.require(['conditional/module11']);
86+
// m1 && sap.ui.require(['conditional/module11']);
87+
// m1 || sap.ui.require(['conditional/module11']);
8588

8689
// ObjectPattern as Id
8790
const {module11, module12} = {

test/lib/lbt/analyzer/JSModuleAnalyzer.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,10 @@ test("ES6 Syntax", (t) => {
492492
const expected = [
493493
"conditional/module1.js",
494494
"conditional/module10.js",
495-
// "conditional/module11.js", // TODO: see es6-syntax.js
495+
"conditional/module11.js", // TODO: see es6-syntax.js
496496
"conditional/module2.js",
497497
"conditional/module3.js",
498-
"conditional/module4.js",
499-
// "conditional/module5.js", // TODO: see es6-syntax.js
498+
// "conditional/module4.js", // TODO: see es6-syntax.js
500499
"conditional/module6.js",
501500
"conditional/module7.js",
502501
"conditional/module8.js",
@@ -553,6 +552,27 @@ test("ES6 Syntax (with dynamic dependencies)", (t) => {
553552
});
554553
});
555554

555+
test("ES6 Async Module", (t) => {
556+
return analyze("modules/es6-async-module.js").then( (info) => {
557+
const expected = [
558+
"static/module1.js",
559+
"ui5loader-autoconfig.js"
560+
];
561+
const actual = info.dependencies.sort();
562+
t.deepEqual(actual, expected, "module dependencies should match");
563+
expected.forEach((dep) => {
564+
t.is(info.isConditionalDependency(dep), /^conditional\//.test(dep),
565+
`only dependencies to 'conditional/*' modules should be conditional (${dep})`);
566+
t.is(info.isImplicitDependency(dep), !/^(?:conditional|static)\//.test(dep),
567+
`all dependencies other than 'conditional/*' and 'static/*' should be implicit (${dep})`);
568+
t.false(info.dynamicDependencies,
569+
`no use of dynamic dependencies should have been detected (${dep})`);
570+
t.false(info.rawModule,
571+
`ui5 module (${dep})`);
572+
});
573+
});
574+
});
575+
556576
test("Dynamic import (declare/require)", (t) => {
557577
return analyze("modules/declare_dynamic_require.js").then((info) => {
558578
t.true(info.dynamicDependencies,

0 commit comments

Comments
 (0)