@ui5/webcomponents-tools 0.0.0-ca2fa23d3 → 0.0.0-cad512aa3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +445 -1
  2. package/README.md +5 -6
  3. package/assets-meta.js +153 -0
  4. package/bin/dev.js +12 -1
  5. package/components-package/eslint.js +34 -0
  6. package/components-package/nps.js +115 -44
  7. package/components-package/postcss.components.js +13 -13
  8. package/components-package/postcss.themes.js +19 -16
  9. package/components-package/vite.config.js +12 -0
  10. package/components-package/wdio.js +128 -62
  11. package/components-package/wdio.sync.js +360 -0
  12. package/icons-collection/nps.js +69 -28
  13. package/lib/copy-and-watch/index.js +145 -0
  14. package/lib/copy-list/index.js +28 -0
  15. package/lib/create-icons/index.js +124 -50
  16. package/lib/create-illustrations/index.js +161 -0
  17. package/lib/create-new-component/index.js +108 -99
  18. package/lib/create-new-component/jsFileContentTemplate.js +77 -0
  19. package/lib/create-new-component/tsFileContentTemplate.js +84 -0
  20. package/lib/dev-server/dev-server.js +66 -0
  21. package/lib/dev-server/virtual-index-html-plugin.js +53 -0
  22. package/lib/esm-abs-to-rel/index.js +58 -0
  23. package/lib/generate-custom-elements-manifest/index.js +327 -0
  24. package/lib/generate-js-imports/illustrations.js +72 -0
  25. package/lib/generate-json-imports/i18n.js +98 -47
  26. package/lib/generate-json-imports/themes.js +71 -16
  27. package/lib/hbs2lit/index.js +2 -4
  28. package/lib/hbs2lit/src/compiler.js +26 -8
  29. package/lib/hbs2lit/src/includesReplacer.js +23 -17
  30. package/lib/hbs2lit/src/litVisitor2.js +103 -19
  31. package/lib/hbs2lit/src/svgProcessor.js +3 -3
  32. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +5 -5
  33. package/lib/hbs2ui5/index.js +52 -30
  34. package/lib/i18n/defaults.js +77 -50
  35. package/lib/i18n/toJSON.js +25 -13
  36. package/lib/jsdoc/config.json +1 -1
  37. package/lib/jsdoc/configTypescript.json +29 -0
  38. package/lib/jsdoc/plugin.js +65 -4
  39. package/lib/jsdoc/preprocess.js +146 -0
  40. package/lib/jsdoc/template/publish.js +32 -4
  41. package/lib/postcss-combine-duplicated-selectors/index.js +178 -0
  42. package/lib/postcss-css-to-esm/index.js +74 -17
  43. package/lib/postcss-css-to-json/index.js +38 -11
  44. package/lib/postcss-new-files/index.js +36 -0
  45. package/lib/postcss-p/postcss-p.mjs +14 -0
  46. package/lib/replace-global-core/index.js +25 -0
  47. package/lib/scoping/get-all-tags.js +37 -0
  48. package/lib/scoping/lint-src.js +31 -0
  49. package/lib/scoping/missing-dependencies.js +65 -0
  50. package/lib/scoping/report-tags-usage.js +28 -0
  51. package/lib/scoping/scope-test-pages.js +40 -0
  52. package/lib/test-runner/test-runner.js +63 -0
  53. package/package.json +54 -55
  54. package/bin/init-ui5-package.js +0 -3
  55. package/components-package/rollup.js +0 -134
  56. package/components-package/serve.json +0 -3
  57. package/lib/documentation/index.js +0 -143
  58. package/lib/documentation/templates/api-component-since.js +0 -3
  59. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  60. package/lib/documentation/templates/api-events-section.js +0 -35
  61. package/lib/documentation/templates/api-methods-section.js +0 -26
  62. package/lib/documentation/templates/api-properties-section.js +0 -40
  63. package/lib/documentation/templates/api-slots-section.js +0 -28
  64. package/lib/documentation/templates/template.js +0 -38
  65. package/lib/init-package/index.js +0 -119
  66. package/lib/init-package/resources/.eslintignore +0 -3
  67. package/lib/init-package/resources/bundle.es5.js +0 -28
  68. package/lib/init-package/resources/bundle.esm.js +0 -37
  69. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  70. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  71. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  72. package/lib/init-package/resources/config/rollup.config.js +0 -1
  73. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  74. package/lib/init-package/resources/package-scripts.js +0 -11
  75. package/lib/init-package/resources/src/Assets.js +0 -6
  76. package/lib/init-package/resources/src/Demo.hbs +0 -1
  77. package/lib/init-package/resources/src/Demo.js +0 -57
  78. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  79. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  80. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  81. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  82. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  83. package/lib/init-package/resources/src/themes/Demo.css +0 -11
  84. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  85. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  86. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  87. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  88. package/lib/init-package/resources/test/pages/index.html +0 -51
  89. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  90. package/package-lock.json +0 -9994
@@ -1,3 +1,36 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const tsMode = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
4
+
5
+ /**
6
+ * Typescript Rules
7
+ */
8
+ const overrides = tsMode ? [{
9
+ files: ["*.ts"],
10
+ parser: "@typescript-eslint/parser",
11
+ plugins: ["@typescript-eslint"],
12
+ extends: [
13
+ "plugin:@typescript-eslint/recommended",
14
+ "plugin:@typescript-eslint/recommended-requiring-type-checking"
15
+ ],
16
+ parserOptions: {
17
+ "project": ["./tsconfig.json", "./packages/*/tsconfig.json"],
18
+ },
19
+ rules: {
20
+ "no-shadow": "off",
21
+ "@typescript-eslint/no-shadow": ["error"],
22
+ "@typescript-eslint/no-unsafe-member-access": "off",
23
+ "@typescript-eslint/no-floating-promises": "off",
24
+ "@typescript-eslint/no-explicit-any": "off",
25
+ "@typescript-eslint/no-unsafe-assignment": "off",
26
+ "@typescript-eslint/ban-ts-comment": "off",
27
+ "@typescript-eslint/no-unsafe-call": "off",
28
+ "@typescript-eslint/no-non-null-assertion": "off",
29
+ "@typescript-eslint/no-empty-function": "off",
30
+ "lines-between-class-members": "off",
31
+ }
32
+ }] : [];
33
+
1
34
  module.exports = {
2
35
  "env": {
3
36
  "browser": true,
@@ -5,6 +38,7 @@ module.exports = {
5
38
  },
6
39
  "root": true,
7
40
  "extends": "airbnb-base",
41
+ overrides,
8
42
  "parserOptions": {
9
43
  "ecmaVersion": 2018,
10
44
  "sourceType": "module"
@@ -1,73 +1,144 @@
1
1
  const path = require("path");
2
-
2
+ const fs = require("fs");
3
+ const resolve = require("resolve");
3
4
  const LIB = path.join(__dirname, `../lib/`);
4
- const NODE_MODULES_PATH = path.join(__dirname, `../../../node_modules/`);
5
- const serveConfig = path.join(__dirname, `serve.json`);
6
- const polyfillPath = path.join(NODE_MODULES_PATH, `/@webcomponents/webcomponentsjs/**/*.*`);
5
+ const preprocessJSDocScript = resolve.sync("@ui5/webcomponents-tools/lib/jsdoc/preprocess.js");
7
6
 
8
7
  const getScripts = (options) => {
9
8
 
10
- const port = options.port;
9
+ // The script creates all JS modules (dist/illustrations/{illustrationName}.js) out of the existing SVGs
10
+ const illustrationsData = options.illustrationsData || [];
11
+ const illustrations = illustrationsData.map(illustration => `node "${LIB}/create-illustrations/index.js" ${illustration.path} ${illustration.defaultText} ${illustration.illustrationsPrefix} ${illustration.set} ${illustration.destinationPath}`);
12
+ const createIllustrationsJSImportsScript = illustrations.join(" && ");
13
+
14
+ // The script creates the "dist/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
15
+ const illustrationDestinationPaths = illustrationsData.map(illustrations => illustrations.destinationPath);
16
+ const createIllustrationsLoadersScript = options.fioriPackage ? `node ${LIB}/generate-js-imports/illustrations.js ${illustrationDestinationPaths[0]} ${illustrationDestinationPaths[1]} dist/generated/js-imports` : "";
17
+ const tsOption = options.typescript;
18
+ const tsCommand = tsOption ? "tsc" : "";
19
+ const tsWatchCommand = tsOption ? "tsc --watch" : "";
20
+ const tsCrossEnv = tsOption ? "cross-env UI5_TS=true" : "";
21
+ const copySrcGenerated = tsOption ? "" : "copy.srcGenerated";
22
+
23
+ if (tsOption) {
24
+ try {
25
+ require("typescript");
26
+ } catch(e) {
27
+ console.error(`TypeScript is not found. Try to install it by running \`npm install --save-dev typescript\` if you are using npm or by running \`yarn add --dev typescript\` if you are using yarn.`);
28
+ process.exit(e.code);
29
+ }
30
+ }
31
+
32
+ let viteConfig;
33
+ if (fs.existsSync("config/vite.config.js")) {
34
+ // old project setup where config file is in separate folder
35
+ viteConfig = "-c config/vite.config.js";
36
+ } else if (fs.existsSync("vite.config.js")) {
37
+ // preferred way of custom configuration in root project folder
38
+ viteConfig = "";
39
+ } else {
40
+ // no custom configuration - use default from tools project
41
+ viteConfig = `-c "${require.resolve("@ui5/webcomponents-tools/components-package/vite.config.js")}"`;
42
+ }
43
+
44
+ let eslintConfig;
45
+ if (fs.existsSync("config/.eslintrc.js")) {
46
+ // old project setup where config file is in separate folder
47
+ eslintConfig = "--config config/.eslintrc.js";
48
+ } else if (fs.existsSync(".eslintrc.js")) {
49
+ // preferred way of custom configuration in root project folder
50
+ eslintConfig = "";
51
+ } else {
52
+ // no custom configuration - use default from tools project
53
+ eslintConfig = `--config "${require.resolve("@ui5/webcomponents-tools/components-package/eslint.js")}"`;
54
+ }
11
55
 
12
56
  const scripts = {
13
- clean: "rimraf dist",
14
- lint: "eslint . --config config/.eslintrc.js",
15
- prepare: "nps clean build.templates build.styles build.i18n build.jsonImports copy build.samples",
57
+ clean: 'rimraf jsdoc-dist && rimraf src/generated && rimraf dist && rimraf .port && nps "scope.testPages.clean"',
58
+ lint: `eslint . ${eslintConfig}`,
59
+ lintfix: `eslint . ${eslintConfig} --fix`,
60
+ prepare: {
61
+ default: `${tsCrossEnv} nps clean prepare.all typescript generateAPI`,
62
+ all: 'concurrently "nps build.templates" "nps build.i18n" "nps prepare.styleRelated" "nps copy" "nps build.illustrations"',
63
+ styleRelated: "nps build.styles build.jsonImports build.jsImports",
64
+ },
65
+ typescript: tsCommand,
16
66
  build: {
17
- default: "nps lint prepare build.bundle",
18
- templates: `mkdirp dist/generated/templates && node ${LIB}/hbs2ui5/index.js -d src/ -o dist/generated/templates`,
67
+ default: "nps prepare lint build.bundle",
68
+ templates: `mkdirp dist/generated/templates && node "${LIB}/hbs2ui5/index.js" -d src/ -o dist/generated/templates`,
19
69
  styles: {
20
- default: "nps build.styles.themes build.styles.components",
21
- themes: "postcss src/**/parameters-bundle.css --config config/postcss.themes --base src --dir dist/css/",
22
- components: "postcss src/themes/*.css --config config/postcss.components --base src --dir dist/css/",
70
+ default: `nps build.styles.themes build.styles.components ${copySrcGenerated}`,
71
+ themes: `node "${LIB}/postcss-p/postcss-p.mjs"`,
72
+ components: "postcss src/themes/*.css --config config/postcss.components --base src --dir dist/css/", // When updating this, also update the new files script
23
73
  },
24
74
  i18n: {
25
75
  default: "nps build.i18n.defaultsjs build.i18n.json",
26
- defaultsjs: `mkdirp dist/generated/i18n && node ${LIB}/i18n/defaults.js src/i18n dist/generated/i18n`,
27
- json: `mkdirp dist/generated/assets/i18n && node ${LIB}/i18n/toJSON.js src/i18n dist/generated/assets/i18n`,
76
+ defaultsjs: `node "${LIB}/i18n/defaults.js" src/i18n src/generated/i18n`,
77
+ json: `node "${LIB}/i18n/toJSON.js" src/i18n dist/generated/assets/i18n`,
28
78
  },
29
79
  jsonImports: {
30
80
  default: "mkdirp dist/generated/json-imports && nps build.jsonImports.themes build.jsonImports.i18n",
31
- themes: `node ${LIB}/generate-json-imports/themes.js`,
32
- i18n: `node ${LIB}/generate-json-imports/i18n.js`,
81
+ themes: `node "${LIB}/generate-json-imports/themes.js" dist/generated/assets/themes dist/generated/json-imports`,
82
+ i18n: `node "${LIB}/generate-json-imports/i18n.js" dist/generated/assets/i18n dist/generated/json-imports`,
33
83
  },
34
- bundle: "rollup --config config/rollup.config.js --environment ES5_BUILD",
35
- samples: {
36
- default: "nps build.samples.api build.samples.docs",
37
- api: `jsdoc -c ${LIB}/jsdoc/config.json`,
38
- docs: `node ${LIB}/documentation/index.js dist/api.json`,
39
- }
84
+ jsImports: {
85
+ default: "mkdirp dist/generated/js-imports && nps build.jsImports.illustrationsLoaders",
86
+ illustrationsLoaders: createIllustrationsLoadersScript,
87
+ },
88
+ bundle: `vite build ${viteConfig}`,
89
+ illustrations: createIllustrationsJSImportsScript,
40
90
  },
41
91
  copy: {
42
- default: "nps copy.src copy.test copy.webcomponents-polyfill",
43
- src: "copy-and-watch \"src/**/*.js\" dist/",
44
- test: "copy-and-watch \"test/**/*.*\" dist/test-resources",
45
- "webcomponents-polyfill": `copy-and-watch "${polyfillPath}" dist/webcomponentsjs/`,
92
+ default: "nps copy.src copy.props",
93
+ src: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.js" dist/`,
94
+ srcGenerated: `node "${LIB}/copy-and-watch/index.js" --silent "src/generated/**/*.js" dist/generated/`,
95
+ props: `node "${LIB}/copy-and-watch/index.js" --silent "src/**/*.properties" dist/`,
46
96
  },
47
97
  watch: {
48
- default: 'concurrently "nps watch.templates" "nps watch.samples" "nps watch.test" "nps watch.src" "nps watch.bundle" "nps watch.styles"',
49
- src: 'nps "copy.src --watch --skip-initial-copy"',
50
- test: 'nps "copy.test --watch --skip-initial-copy"',
51
- bundle: "rollup --config config/rollup.config.js -w --environment ES5_BUILD,DEV",
98
+ default: `${tsCrossEnv} concurrently "nps watch.templates" "nps watch.api" "nps watch.src" "nps watch.typescript" "nps watch.styles" "nps watch.i18n" "nps watch.props"`,
99
+ devServer: 'concurrently "nps watch.default" "nps watch.bundle"',
100
+ src: 'nps "copy.src --watch --safe --skip-initial-copy"',
101
+ typescript: tsWatchCommand,
102
+ props: 'nps "copy.props --watch --safe --skip-initial-copy"',
103
+ bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
52
104
  styles: {
53
105
  default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components"',
54
106
  themes: 'nps "build.styles.themes -w"',
55
- components: 'nps "build.styles.components -w"',
107
+ components: {
108
+ default: 'concurrently "nps watch.styles.components.existingFiles" "nps watch.styles.components.newFiles"',
109
+ existingFiles: `nps "build.styles.components -w"`,
110
+ newFiles: `node "${LIB}/postcss-new-files/index.js" --srcFiles="src/themes/*.css"`,
111
+ },
56
112
  },
57
- templates: "chokidar \"src/**/*.hbs\" -c \"nps build.templates\"",
58
- samples: "chokidar \"test/**/*.sample.html\" -c \"nps build.samples\"",
113
+ templates: 'chokidar "src/**/*.hbs" -c "nps build.templates"',
114
+ api: 'chokidar "test/**/*.sample.html" -c "nps generateAPI"',
115
+ i18n: 'chokidar "src/i18n/messagebundle.properties" -c "nps build.i18n.defaultsjs"'
59
116
  },
60
- dev: 'concurrently "nps serve" "nps watch"',
61
- start: "nps prepare dev",
62
- serve: {
63
- default: "nps serve.prepare serve.run",
64
- prepare: `copy-and-watch "${serveConfig}" dist/`,
65
- run: `serve --no-clipboard -l ${port} dist`,
117
+ start: "nps prepare watch.devServer",
118
+ test: `node "${LIB}/test-runner/test-runner.js"`,
119
+ "test-suite-1": `node "${LIB}/test-runner/test-runner.js" --suite suite1`,
120
+ "test-suite-2": `node "${LIB}/test-runner/test-runner.js" --suite suite2`,
121
+ startWithScope: "nps scope.prepare scope.watchWithBundle",
122
+ scope: {
123
+ prepare: "nps scope.lint prepare scope.testPages",
124
+ lint: `node "${LIB}/scoping/lint-src.js"`,
125
+ testPages: {
126
+ default: "nps scope.testPages.clean scope.testPages.copy scope.testPages.replace",
127
+ clean: "rimraf test/pages/scoped",
128
+ copy: `node "${LIB}/copy-and-watch/index.js" --silent "test/pages/**/*" test/pages/scoped`,
129
+ replace: `node "${LIB}/scoping/scope-test-pages.js" test/pages/scoped demo`,
130
+ },
131
+ watchWithBundle: 'concurrently "nps scope.watch" "nps scope.bundle" ',
132
+ watch: 'concurrently "nps watch.templates" "nps watch.api" "nps watch.src" "nps watch.props" "nps watch.styles"',
133
+ bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
66
134
  },
67
- test: {
68
- // --success first - report the exit code of the test run (first command to finish), as serve is always terminated and has a non-0 exit code
69
- default: 'concurrently "nps serve" "nps test.run" --kill-others --success first',
70
- run: "cross-env WDIO_LOG_LEVEL=error FORCE_COLOR=0 wdio config/wdio.conf.js",
135
+ generateAPI: {
136
+ default: "nps generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup generateAPI.prepareManifest",
137
+ prepare: `node "${LIB}/copy-and-watch/index.js" --silent "dist/**/*.js" jsdoc-dist/`,
138
+ prepareManifest: `node "${LIB}/generate-custom-elements-manifest/index.js" dist dist`,
139
+ preprocess: `node "${preprocessJSDocScript}" jsdoc-dist/ src`,
140
+ jsdoc: `jsdoc -c "${LIB}/jsdoc/configTypescript.json"`,
141
+ cleanup: "rimraf jsdoc-dist/"
71
142
  },
72
143
  };
73
144
 
@@ -6,16 +6,16 @@ const fs = require("fs");
6
6
  const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
7
7
 
8
8
  module.exports = {
9
- plugins: [
10
- postcssImport(),
11
- cssnano({
12
- preset: [
13
- 'default', {
14
- mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
15
- mergeRules: false, // https://github.com/cssnano/cssnano/issues/730
16
- },
17
- ]
18
- }),
19
- postcssCSStoESM({toReplace: 'src', includeDefaultTheme: true, packageName}),
20
- ]
21
- };
9
+ plugins: [
10
+ postcssImport(),
11
+ cssnano({
12
+ preset: [
13
+ 'default', {
14
+ mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
15
+ mergeRules: false, // https://github.com/cssnano/cssnano/issues/730
16
+ },
17
+ ]
18
+ }),
19
+ postcssCSStoESM({ toReplace: 'src', includeDefaultTheme: true, packageName }),
20
+ ]
21
+ }
@@ -1,23 +1,26 @@
1
1
  const postcssImport = require('postcss-import');
2
- const combineSelectors = require('postcss-combine-duplicated-selectors');
2
+ const combineSelectors = require('../lib/postcss-combine-duplicated-selectors/index.js');
3
3
  const postcssCSStoJSON = require('../lib/postcss-css-to-json/index.js');
4
4
  const postcssCSStoESM = require('../lib/postcss-css-to-esm/index.js');
5
5
  const cssnano = require('cssnano');
6
+ const fs = require("fs");
7
+
8
+ const packageName = JSON.parse(fs.readFileSync("./package.json")).name;
6
9
 
7
10
  module.exports = {
8
- plugins: [
9
- postcssImport(),
10
- combineSelectors({
11
- removeDuplicatedProperties: true
12
- }),
13
- cssnano({
14
- preset: [
15
- 'default', {
16
- mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
17
- },
18
- ]
19
- },),
20
- postcssCSStoJSON({toReplace: 'src'}),
21
- postcssCSStoESM({toReplace: 'src'}),
22
- ]
11
+ plugins: [
12
+ postcssImport(),
13
+ combineSelectors({
14
+ removeDuplicatedProperties: true
15
+ }),
16
+ cssnano({
17
+ preset: [
18
+ 'default', {
19
+ mergeLonghand: false, // https://github.com/cssnano/cssnano/issues/675
20
+ },
21
+ ]
22
+ },),
23
+ postcssCSStoJSON({ toReplace: 'src', packageName }),
24
+ postcssCSStoESM({ toReplace: 'src', packageName }),
25
+ ]
23
26
  };
@@ -0,0 +1,12 @@
1
+ // vite.config.js
2
+ const { defineConfig } = require('vite');
3
+ const virtualIndex = require("../lib/dev-server/virtual-index-html-plugin.js");
4
+
5
+ module.exports = defineConfig(async () => {
6
+ return {
7
+ build: {
8
+ emptyOutDir: false,
9
+ },
10
+ plugins: [await virtualIndex()],
11
+ }
12
+ });
@@ -50,7 +50,7 @@ exports.config = {
50
50
  // maxInstances can get overwritten per capability. So if you have an in-house Selenium
51
51
  // grid with only 5 firefox instances available you can make sure that not more than
52
52
  // 5 instances get started at a time.
53
- maxInstances: process.env.TRAVIS ? 1 : 5,
53
+ maxInstances: 5,
54
54
  //
55
55
  browserName: 'chrome',
56
56
  'goog:chromeOptions': {
@@ -82,7 +82,7 @@ exports.config = {
82
82
  // with `/`, the base url gets prepended, not including the path portion of your baseUrl.
83
83
  // If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
84
84
  // gets prepended directly.
85
- baseUrl: '',
85
+ baseUrl: 'http://localhost:4567', // This is important since WDIO 7+ does not accept an empty string for baseUrl
86
86
  path: '',
87
87
  //
88
88
  // Default timeout for all waitFor* commands.
@@ -99,7 +99,14 @@ exports.config = {
99
99
  // Services take over a specific job you don't want to take care of. They enhance
100
100
  // your test setup with almost no effort. Unlike plugins, they don't add new
101
101
  // commands. Instead, they hook themselves up into the test process.
102
- services: ['chromedriver'],
102
+ services: ['chromedriver', 'devtools',
103
+ ['static-server', {
104
+ folders: [
105
+ { mount: '/', path: './dist' },
106
+ ],
107
+ port: '4567',
108
+ }],
109
+ ],
103
110
  // options
104
111
  chromeDriverArgs: ['--port=9515'], // default
105
112
  // Framework you want to run your specs with.
@@ -152,46 +159,24 @@ exports.config = {
152
159
  * @param {Array.<Object>} capabilities list of capabilities details
153
160
  * @param {Array.<String>} specs List of spec file paths that are to be run
154
161
  */
155
- before: function (capabilities, specs) {
156
- browser.addCommand("findElementDeep", function (selector) {
157
- const selectors = selector.split(">>>");
162
+ before: async function (capabilities, specs) {
163
+ await browser.addCommand("isFocusedDeep", async function () {
164
+ return browser.executeAsync(function (elem, done) {
165
+ let activeElement = document.activeElement;
158
166
 
159
- for (var i = 0; i < selectors.length; i++) {
160
- if (i === 0) {
161
- curElement = browser.$(selectors[i]);
162
- continue;
167
+ while (activeElement.shadowRoot) {
168
+ if (activeElement.shadowRoot.activeElement) {
169
+ activeElement = activeElement.shadowRoot.activeElement;
170
+ } else {
171
+ break;
172
+ }
163
173
  }
174
+ done(elem === activeElement);
175
+ }, this);
176
+ }, true);
164
177
 
165
- // wait for the shadowDom to be filled before executing the selector
166
- browser.executeAsync(function (elem, done) {
167
- elem._waitForDomRef().then(done);
168
- }, curElement);
169
-
170
- // find the next element from the selector
171
- curElement = curElement.$(new Function (`
172
- return this.shadowRoot.querySelector("${selectors[i]}");
173
- `));
174
- }
175
-
176
- return curElement;
177
-
178
- });
179
-
180
- browser.addCommand("findElementDeep", function (selector) {
181
- const selectors = selector.split(">>>");
182
- let curElement = this;
183
-
184
- for (var i = 0; i < selectors.length; i++) {
185
- curElement = curElement.$(new Function (`
186
- return this.shadowRoot.querySelector("${selectors[i]}");
187
- `));
188
- }
189
-
190
- return curElement;
191
- }, this);
192
-
193
- browser.addCommand("isFocusedDeep", function () {
194
- return browser.execute(function (elem) {
178
+ await browser.addCommand("isFocusedDeepElement", async function (element) {
179
+ return browser.executeAsync(function (elem, element, done) {
195
180
  let activeElement = document.activeElement;
196
181
 
197
182
  while (activeElement.shadowRoot) {
@@ -201,41 +186,89 @@ exports.config = {
201
186
  break;
202
187
  }
203
188
  }
204
- return elem === activeElement;
205
- }, this);
189
+ done(element === activeElement);
190
+ }, this, element);
206
191
  }, true);
207
192
 
208
- browser.addCommand("setProperty", function(property, value) {
209
- return browser.execute((elem, property, value) => {
210
- return elem[property] = value;
193
+ await browser.addCommand("setProperty", async function(property, value) {
194
+ return browser.executeAsync((elem, property, value, done) => {
195
+ elem[property] = value;
196
+ done();
211
197
  }, this, property, value);
212
198
  }, true);
213
199
 
214
- browser.addCommand("setAttribute", function(attribute, value) {
215
- return browser.execute((elem, attribute, value) => {
216
- return elem.setAttribute(attribute, value);
200
+ await browser.addCommand("setAttribute", async function(attribute, value) {
201
+ return browser.executeAsync((elem, attribute, value, done) => {
202
+ elem.setAttribute(attribute, value);
203
+ done();
217
204
  }, this, attribute, value);
218
205
  }, true);
219
206
 
220
- browser.addCommand("removeAttribute", function(attribute) {
221
- return browser.execute((elem, attribute) => {
222
- return elem.removeAttribute(attribute);
207
+ await browser.addCommand("removeAttribute", async function(attribute) {
208
+ return browser.executeAsync((elem, attribute, done) => {
209
+ elem.removeAttribute(attribute);
210
+ done();
223
211
  }, this, attribute);
224
212
  }, true);
225
213
 
226
- browser.addCommand("hasClass", function(className) {
227
- return browser.execute((elem, className) => {
228
- return elem.classList.contains(className);
214
+ await browser.addCommand("hasClass", async function(className) {
215
+ return browser.executeAsync((elem, className, done) => {
216
+ done(elem.classList.contains(className));
229
217
  }, this, className);
230
218
  }, true);
219
+
220
+ await browser.addCommand("hasAttribute", async function(attrName) {
221
+ return browser.executeAsync((elem, attrName, done) => {
222
+ done(elem.hasAttribute(attrName));
223
+ }, this, attrName);
224
+ }, true);
225
+
226
+ await browser.addCommand("getStaticAreaItemClassName", async function(selector) {
227
+ return browser.executeAsync(async (selector, done) => {
228
+ const staticAreaItem = await document.querySelector(selector).getStaticAreaItemDomRef();
229
+ done(staticAreaItem.host.classList[0]);
230
+ }, selector);
231
+ }, false);
232
+
233
+ await browser.addLocatorStrategy('activeElement', (selector) => {
234
+ return document.querySelector(selector).shadowRoot.activeElement;
235
+ });
231
236
  },
232
237
  /**
233
238
  * Runs before a WebdriverIO command gets executed.
234
239
  * @param {String} commandName hook command name
235
240
  * @param {Array} args arguments that command would receive
236
241
  */
237
- // beforeCommand: function (commandName, args) {
238
- // },
242
+ beforeCommand: async function (commandName, args) {
243
+ const waitFor = [
244
+ "$",
245
+ "$$",
246
+ "getAttribute",
247
+ "hasAttribute", // custom
248
+ "getCSSProperty",
249
+ "getHTML",
250
+ "getProperty",
251
+ "getSize",
252
+ "getStaticAreaItemClassName", // custom
253
+ "getText",
254
+ "getValue",
255
+ "hasClass", // custom
256
+ "isDisplayed",
257
+ "isDisplayedInViewport",
258
+ "isEnabled",
259
+ "isExisting",
260
+ "isFocused",
261
+ "isFocusedDeep", // custom
262
+ "isFocusedDeepElement", // custom
263
+ "shadow$",
264
+ "shadow$$",
265
+ ];
266
+ if (waitFor.includes(commandName)) {
267
+ await browser.executeAsync(function (done) {
268
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
269
+ });
270
+ }
271
+ },
239
272
 
240
273
  /**
241
274
  * Hook that gets executed before the suite starts
@@ -281,13 +314,46 @@ exports.config = {
281
314
  * @param {Number} result 0 - command success, 1 - command error
282
315
  * @param {Object} error error object if any
283
316
  */
284
- afterCommand: function (commandName, args, result, error) {
285
- const waitFor = ["$", "$$", "shadow$", "click", "performActions", "elementClick", "keys", "sendKeys", "findElement", "elementClear", "elementSendKeys", "setValue", "addValue", "getHTML", "getProperty", "setAttribute", "removeAttribute", "getElementProperty"];
286
- if (waitFor.includes(commandName)) {
287
- browser.executeAsync(function (done) {
288
- // run all the tests in no conflict mode
317
+ afterCommand: async function (commandName, args, result, error) {
318
+
319
+ // url -> set configuration first
320
+ if (commandName === "url" && !args[0].includes("do-not-change-configuration")) {
321
+ await browser.executeAsync(function(done) {
289
322
  window["sap-ui-webcomponents-bundle"].configuration.setNoConflict(true);
290
- window.RenderScheduler.whenFinished().then(done);
323
+ done();
324
+ });
325
+ }
326
+
327
+ const waitFor = [
328
+ "addValue",
329
+ "clearValue",
330
+ "click",
331
+ "doubleClick",
332
+ "dragAndDrop",
333
+ "pause",
334
+ "removeAttribute", // custom
335
+ "scrollIntoView",
336
+ "setAttribute", // custom
337
+ "setProperty", // custom
338
+ "setValue",
339
+ "setWindowSize",
340
+ "touchAction",
341
+ "url",
342
+ ];
343
+
344
+ const waitForWithDelay = [
345
+ "keys",
346
+ ];
347
+
348
+ if (waitFor.includes(commandName)) {
349
+ await browser.executeAsync(function (done) {
350
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
351
+ });
352
+ } else if (waitForWithDelay.includes(commandName)) {
353
+ await browser.executeAsync(function (done) {
354
+ setTimeout(() => {
355
+ window["sap-ui-webcomponents-bundle"].renderFinished().then(done);
356
+ }, 10);
291
357
  });
292
358
  }
293
359
  },