@adobe/helix-importer 2.7.0 → 2.8.0
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.
- package/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/index.js +2 -0
- package/src/utils/DOMUtils.js +15 -0
- package/src/utils/Loader.js +28 -0
- package/test/utils/Loader.spec.js +53 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [2.8.0](https://github.com/adobe/helix-importer/compare/v2.7.0...v2.8.0) (2023-02-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add waitForElement DOMUtils ([#94](https://github.com/adobe/helix-importer/issues/94)) ([ca041f3](https://github.com/adobe/helix-importer/commit/ca041f30f39b0d511fbbe30a1410b2c013826a0d))
|
|
7
|
+
|
|
1
8
|
# [2.7.0](https://github.com/adobe/helix-importer/compare/v2.6.0...v2.7.0) (2023-02-06)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-importer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Helix Importer tool: create md / docx from html",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"mocha": "10.2.0",
|
|
40
40
|
"mocha-multi-reporters": "1.5.1",
|
|
41
41
|
"mock-fs": "5.2.0",
|
|
42
|
-
"semantic-release": "
|
|
42
|
+
"semantic-release": "20.1.0"
|
|
43
43
|
},
|
|
44
44
|
"license": "Apache-2.0",
|
|
45
45
|
"dependencies": {
|
package/src/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import Blocks from './utils/Blocks.js';
|
|
|
23
23
|
import CSV from './utils/CSV.js';
|
|
24
24
|
import DOMUtils from './utils/DOMUtils.js';
|
|
25
25
|
import FileUtils from './utils/FileUtils.js';
|
|
26
|
+
import Loader from './utils/Loader.js';
|
|
26
27
|
import Utils from './utils/Utils.js';
|
|
27
28
|
|
|
28
29
|
import WPUtils from './wp/WPUtils.js';
|
|
@@ -44,6 +45,7 @@ export {
|
|
|
44
45
|
CSV,
|
|
45
46
|
DOMUtils,
|
|
46
47
|
FileUtils,
|
|
48
|
+
Loader,
|
|
47
49
|
Utils,
|
|
48
50
|
WPUtils,
|
|
49
51
|
WPAdminAjaxPager,
|
package/src/utils/DOMUtils.js
CHANGED
|
@@ -263,4 +263,19 @@ export default class DOMUtils {
|
|
|
263
263
|
}
|
|
264
264
|
return null;
|
|
265
265
|
}
|
|
266
|
+
|
|
267
|
+
static async waitForElement(selector, document, timeout = 5000, interval = 250) {
|
|
268
|
+
return new Promise((resolve, reject) => {
|
|
269
|
+
const timeWas = new Date();
|
|
270
|
+
const wait = setInterval(() => {
|
|
271
|
+
if (document.querySelector(selector)) {
|
|
272
|
+
clearInterval(wait);
|
|
273
|
+
resolve();
|
|
274
|
+
} else if (new Date() - timeWas > timeout) { // Timeout
|
|
275
|
+
clearInterval(wait);
|
|
276
|
+
reject();
|
|
277
|
+
}
|
|
278
|
+
}, interval);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
266
281
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2021 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default class Loader {
|
|
14
|
+
static async waitForElement(selector, document, timeout = 5000, interval = 250) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const timeWas = new Date();
|
|
17
|
+
const wait = setInterval(() => {
|
|
18
|
+
if (document.querySelector(selector)) {
|
|
19
|
+
clearInterval(wait);
|
|
20
|
+
resolve();
|
|
21
|
+
} else if (new Date() - timeWas > timeout) { // Timeout
|
|
22
|
+
clearInterval(wait);
|
|
23
|
+
reject();
|
|
24
|
+
}
|
|
25
|
+
}, interval);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/* eslint-disable no-shadow */
|
|
14
|
+
|
|
15
|
+
import { rejects, doesNotReject } from 'assert';
|
|
16
|
+
import { describe, it } from 'mocha';
|
|
17
|
+
|
|
18
|
+
import { JSDOM } from 'jsdom';
|
|
19
|
+
|
|
20
|
+
import Loader from '../../src/utils/Loader.js';
|
|
21
|
+
|
|
22
|
+
describe('Loader#waitForElement', () => {
|
|
23
|
+
it('should fail for non existing element', async () => {
|
|
24
|
+
const { document } = (new JSDOM()).window;
|
|
25
|
+
const div = document.createElement('div');
|
|
26
|
+
document.body.appendChild(div);
|
|
27
|
+
await rejects(async () => {
|
|
28
|
+
await Loader.waitForElement('.dummy', document, 25, 20);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should find existing element', async () => {
|
|
33
|
+
const { document } = (new JSDOM()).window;
|
|
34
|
+
const div = document.createElement('div');
|
|
35
|
+
div.classList.add('dummy');
|
|
36
|
+
document.body.appendChild(div);
|
|
37
|
+
await doesNotReject(async () => {
|
|
38
|
+
await Loader.waitForElement('.dummy', document, 100, 20);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should wait for element to appear in the DOM', async () => {
|
|
43
|
+
const { document } = (new JSDOM()).window;
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
const div = document.createElement('div');
|
|
46
|
+
div.classList.add('dummy');
|
|
47
|
+
document.body.appendChild(div);
|
|
48
|
+
}, 50);
|
|
49
|
+
await doesNotReject(async () => {
|
|
50
|
+
await Loader.waitForElement('.dummy', document, 100, 20);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|