leaflet-rotate 0.2.6 → 0.2.7

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.
@@ -0,0 +1,86 @@
1
+ import { suite as uvu_suite } from 'uvu';
2
+ import { exec } from 'child_process';
3
+ import { chromium } from 'playwright';
4
+
5
+ /**
6
+ * Start HTTP server
7
+ */
8
+ export async function setup(ctx) {
9
+ ctx.server = new AbortController();
10
+ exec('http-server', { signal: ctx.server.signal });
11
+ ctx.localhost = 'http://localhost:8080';
12
+ ctx.browser = await chromium.launch();
13
+ ctx.context = await ctx.browser.newContext();
14
+ ctx.context.route(/.html$/, mock_cdn_urls);
15
+ ctx.page = await ctx.context.newPage();
16
+ }
17
+
18
+ /**
19
+ * Stop HTTP server
20
+ */
21
+ export async function reset(ctx) {
22
+ await ctx.context.close();
23
+ await ctx.browser.close();
24
+ try { ctx.server.abort(); } catch(e) { }
25
+ }
26
+
27
+ /**
28
+ * Sample wrapper for uvu `suite`
29
+ *
30
+ * @example start a new test session at: http://localhost:8080/examples/leaflet-rotate.html
31
+ *
32
+ * ```js
33
+ * const test = suite('examples/leaflet-rotate.html');
34
+ *
35
+ * test('rotatePane', async ({ page }) => {
36
+ * const rotatePane = await page.evaluate(() => new Promise(resolve => {
37
+ * resolve(map._rotatePane)
38
+ * }));
39
+ * assert.not.type(rotatePane, 'undefined');
40
+ * });
41
+ * ```
42
+ *
43
+ * @see https://github.com/lukeed/uvu
44
+ */
45
+ export function suite() {
46
+ const test = uvu_suite(...arguments);
47
+ test.before(setup);
48
+ test.after(reset);
49
+ test.before.each(async ({ localhost, page }) => {
50
+ await page.goto((new URL(arguments[0], localhost)).toString());
51
+ });
52
+ // augment uvu `test` function with a third parameter `timeout`
53
+ return new Proxy(test, {
54
+ apply: (object, _, argsList) => {
55
+ return object(argsList[0], timeout(argsList[1], argsList[2]));
56
+ }
57
+ });
58
+ }
59
+
60
+ /**
61
+ * Sets maximum execution time for a function
62
+ *
63
+ * @see https://github.com/lukeed/uvu/issues/33#issuecomment-879870292
64
+ */
65
+ function timeout(handler, ms=10000) {
66
+ return (ctx) => {
67
+ let timer
68
+ return Promise.race([
69
+ handler(ctx),
70
+ new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('[TIMEOUT] Maximum execution time exceeded: ' + ms + 'ms')), ms) })
71
+ ]).finally(() => { clearTimeout(timer) })
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Replace CDN URLs with locally developed files within Network response.
77
+ *
78
+ * @requires playwright
79
+ */
80
+ async function mock_cdn_urls(route) {
81
+ const response = await route.fetch();
82
+ let body = await response.text();
83
+ body = body.replace(new RegExp('https://unpkg.com/leaflet-rotate@(.*?)/', 'g'), '../');
84
+ body = body.replace(new RegExp('leaflet-rotate@(.*?)/', 'g'), '../');
85
+ route.fulfill({ response, body, headers: response.headers() });
86
+ }