leaflet-rotate 0.2.6 → 0.2.8

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