From ac0078b046d9a19a197fdbaf282d840833b3c744 Mon Sep 17 00:00:00 2001 From: Peter Muessig Date: Sat, 13 Jul 2024 12:34:06 +0200 Subject: [PATCH] feat: support sap.ui.require for QUnit testsuites or annotated modules QUnit testsuites using `QUnit.config.autostart = false` and `QUnit.start()` are automatically detected to use `sap.ui.require` instead of `sap.ui.define`. Modules can be also marked to use `sap.ui.require` by using the annotation `/* @sapUiRequire */` in the program. --- README.md | 56 ++++++- .../__test__/__snapshots__/test.js.snap | 149 ++++++++++++++++++ .../fixtures/sap-ui-require/othermodule.js | 5 + .../testsuite-annotation.qunit.js | 9 ++ .../testsuite-autodetect.qunit.js | 7 + .../testsuite-defect-1.qunit.js | 7 + .../testsuite-defect-2.qunit.js | 7 + .../sap-ui-require/testsuite.qunit.js | 9 ++ .../plugin/src/modules/helpers/wrapper.js | 90 +++++++++-- packages/plugin/src/utils/templates.js | 6 + 10 files changed, 333 insertions(+), 12 deletions(-) create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/othermodule.js create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/testsuite-annotation.qunit.js create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/testsuite-autodetect.qunit.js create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/testsuite-defect-1.qunit.js create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/testsuite-defect-2.qunit.js create mode 100644 packages/plugin/__test__/fixtures/sap-ui-require/testsuite.qunit.js diff --git a/README.md b/README.md index ea4b3b2..3786533 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ A more detailed feature list includes: ### Converting ES modules (import/export) into sap.ui.define or sap.ui.require -The plugin will wrap any code having import/export statements in an sap.ui.define. If there is no import/export, it won't be wrapped. +The plugin will wrap any code having import/export statements in `sap.ui.define`. If there is no import/export, it won't be wrapped. #### Static Import @@ -341,6 +341,60 @@ sap.ui.define(["./a"], A => { Also refer to the `neverUseStrict` option below. +### Top-Level Scripts (e.g. QUnit Testsuites) + +By default, modules are converted to UI5 AMD-like modules using `sap.ui.define`. In some cases, it is needed to include modules via script tags, such as for QUnit testsuites. Therefore, the Babel plugin supports converting modules into scripts using `sap.ui.require` instead of AMD-like modules using `sap.ui.define`. These modules then can be used as *top-level* scripts which can be included via `