@geolonia/embed 5.1.0 → 5.2.1
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/dist/embed +1 -1
- package/dist/embed-chunks/12cbd0d1cb4cf744c32f.js +2 -0
- package/dist/embed-chunks/8a521e8312a5b4da123d.js +2 -0
- package/dist/embed-core.js +1 -1
- package/dist/embed-core.js.LICENSE.txt +1 -1
- package/dist/embed.js +1 -1
- package/dist/embed.js.LICENSE.txt +1 -1
- package/dist/version.d.ts +1 -0
- package/package.json +4 -7
- package/src/lib/keyring.test.ts +34 -46
- package/src/lib/parse-atts.test.ts +2 -2
- package/src/lib/simplestyle.test.ts +94 -56
- package/src/lib/util.test.ts +88 -122
- package/src/testability.test.ts +13 -10
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -0
- package/vitest.config.ts +8 -0
- package/webpack.config.js +6 -1
- package/.mocharc.js +0 -9
- package/dist/e2e/basic.spec.d.ts +0 -8
- package/dist/e2e/external-style.spec.d.ts +0 -1
- package/dist/e2e/helper.d.ts +0 -4
- package/dist/e2e/map.spec.d.ts +0 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +0 -2
- package/dist/embed-chunks/8983d465846d11f2859f.js +0 -2
- package/dist/playwright.config.d.ts +0 -9
- package/dist/src/lib/keyring.test.d.ts +0 -1
- package/dist/src/lib/parse-atts.test.d.ts +0 -1
- package/dist/src/lib/simplestyle.test.d.ts +0 -1
- package/dist/src/lib/util.test.d.ts +0 -1
- package/dist/src/testability.test.d.ts +0 -1
- package/dist/src/version.d.ts +0 -1
- /package/dist/embed-chunks/{2489af4328c51b71e92d.js.LICENSE.txt → 12cbd0d1cb4cf744c32f.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{8983d465846d11f2859f.js.LICENSE.txt → 8a521e8312a5b4da123d.js.LICENSE.txt} +0 -0
- /package/dist/{src/embed-core.d.ts → embed-core.d.ts} +0 -0
- /package/dist/{src/embed.d.ts → embed.d.ts} +0 -0
- /package/dist/{src/lib → lib}/CustomAttributionControl.d.ts +0 -0
- /package/dist/{src/lib → lib}/controls/geolonia-control.d.ts +0 -0
- /package/dist/{src/lib → lib}/geolonia-map.d.ts +0 -0
- /package/dist/{src/lib → lib}/geolonia-marker.d.ts +0 -0
- /package/dist/{src/lib → lib}/keyring.d.ts +0 -0
- /package/dist/{src/lib → lib}/maplibre-util.d.ts +0 -0
- /package/dist/{src/lib → lib}/parse-atts.d.ts +0 -0
- /package/dist/{src/lib → lib}/render.d.ts +0 -0
- /package/dist/{src/lib → lib}/simplestyle-vector.d.ts +0 -0
- /package/dist/{src/lib → lib}/simplestyle.d.ts +0 -0
- /package/dist/{src/lib → lib}/util.d.ts +0 -0
- /package/dist/{src/types-internal.d.ts → types-internal.d.ts} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
package/src/lib/util.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { JSDOM } from 'jsdom';
|
|
3
4
|
import {
|
|
4
5
|
getContainer,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
|
|
18
19
|
const base = 'https://base.example.com/parent/';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
beforeAll(() => {
|
|
21
22
|
global.location = {
|
|
22
23
|
...global.location,
|
|
23
24
|
href: base,
|
|
@@ -26,58 +27,52 @@ before(() => {
|
|
|
26
27
|
|
|
27
28
|
describe('Tests for util.js', () => {
|
|
28
29
|
it('URL should be detected', () => {
|
|
29
|
-
|
|
30
|
+
expect(true).toEqual(!!isURL('http://example.com'));
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
it('URL with SSL should be detected', () => {
|
|
33
|
-
|
|
34
|
+
expect(true).toEqual(!!isURL('https://example.com'));
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it('Path should be detected', () => {
|
|
37
|
-
|
|
38
|
-
'https://base.example.com/parent/example-path',
|
|
39
|
-
isURL('./example-path'),
|
|
38
|
+
expect('https://base.example.com/parent/example-path').toEqual(isURL('./example-path'),
|
|
40
39
|
);
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
it('Parent path should be detected', () => {
|
|
44
|
-
|
|
45
|
-
'https://base.example.com/example-path',
|
|
46
|
-
isURL('../example-path'),
|
|
43
|
+
expect('https://base.example.com/example-path').toEqual(isURL('../example-path'),
|
|
47
44
|
);
|
|
48
45
|
});
|
|
49
46
|
|
|
50
47
|
it('Absolute path should be detected', () => {
|
|
51
|
-
|
|
52
|
-
'https://base.example.com/example-path',
|
|
53
|
-
isURL('/example-path'),
|
|
48
|
+
expect('https://base.example.com/example-path').toEqual(isURL('/example-path'),
|
|
54
49
|
);
|
|
55
50
|
});
|
|
56
51
|
|
|
57
52
|
it('Name should not be detected', () => {
|
|
58
|
-
|
|
53
|
+
expect(false).toEqual(isURL('example.com/hello'));
|
|
59
54
|
});
|
|
60
55
|
|
|
61
56
|
describe('isGeoloniaTilesHost', () => {
|
|
62
57
|
it('detects primary tileserver hostname', () => {
|
|
63
58
|
const url =
|
|
64
59
|
'https://tileserver.geolonia.com/v3/tiles.json?key=YOUR-API-KEY';
|
|
65
|
-
|
|
60
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
66
61
|
});
|
|
67
62
|
|
|
68
63
|
it('detects tiles.geolonia.com subdomains', () => {
|
|
69
64
|
const url = new URL('https://osm.v2.tiles.geolonia.com/tiles.json');
|
|
70
|
-
|
|
65
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
71
66
|
});
|
|
72
67
|
|
|
73
68
|
it('detects tiles.geolonia.com subdomains', () => {
|
|
74
69
|
const url = new URL('https://osm.v3.tiles.geolonia.com/tiles.json');
|
|
75
|
-
|
|
70
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
76
71
|
});
|
|
77
72
|
|
|
78
73
|
it('returns false for other hosts or invalid urls', () => {
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
expect(isGeoloniaTilesHost('https://example.com/tiles')).toBe(false);
|
|
75
|
+
expect(isGeoloniaTilesHost('not-a-url')).toBe(false);
|
|
81
76
|
});
|
|
82
77
|
});
|
|
83
78
|
|
|
@@ -86,12 +81,10 @@ describe('Tests for util.js', () => {
|
|
|
86
81
|
<div class="test-class"></div>
|
|
87
82
|
</body></html>`).window;
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
true,
|
|
91
|
-
isDomElement(mocDocument.querySelector('.test-class')),
|
|
84
|
+
expect(true).toEqual(isDomElement(mocDocument.querySelector('.test-class')),
|
|
92
85
|
);
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
expect(false).toEqual(isDomElement('hello world'));
|
|
87
|
+
expect(false).toEqual(isDomElement({ hello: 'world' }));
|
|
95
88
|
});
|
|
96
89
|
|
|
97
90
|
it('should be able to get dom', () => {
|
|
@@ -104,23 +97,23 @@ describe('Tests for util.js', () => {
|
|
|
104
97
|
global.document = dom.window.document;
|
|
105
98
|
|
|
106
99
|
const el = document.querySelector('#test-element') as HTMLElement;
|
|
107
|
-
|
|
100
|
+
expect(el).toEqual(getContainer(el));
|
|
108
101
|
const params = { container: el };
|
|
109
|
-
|
|
102
|
+
expect(el).toEqual(getContainer(params));
|
|
110
103
|
|
|
111
104
|
// specify as a selector
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
expect(el).toEqual(getContainer('#test-element'));
|
|
106
|
+
expect(el).toEqual(getContainer({ container: '#test-element' }));
|
|
114
107
|
|
|
115
108
|
// specify as an id attribute value
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
expect(el).toEqual(getContainer('test-element'));
|
|
110
|
+
expect(el).toEqual(getContainer({ container: 'test-element' }));
|
|
118
111
|
|
|
119
112
|
// negative cases
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
expect(false).toEqual(getContainer('#fail-element'));
|
|
114
|
+
expect(false).toEqual(getContainer({ container: '#fail-element' }));
|
|
115
|
+
expect(false).toEqual(getContainer('fail-element'));
|
|
116
|
+
expect(false).toEqual(getContainer({ container: 'fail-element' }));
|
|
124
117
|
});
|
|
125
118
|
|
|
126
119
|
it('should merge legacy options into options as expected.', () => {
|
|
@@ -136,14 +129,14 @@ describe('Tests for util.js', () => {
|
|
|
136
129
|
document.getElementById('test-element'),
|
|
137
130
|
{ color: '#FF1122' },
|
|
138
131
|
);
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
expect(document.getElementById('test-element')).toEqual(options1.element);
|
|
133
|
+
expect(options1.color).toEqual('#FF1122');
|
|
141
134
|
|
|
142
135
|
const options2 = handleMarkerOptions(false, { color: '#FF1122' });
|
|
143
|
-
|
|
136
|
+
expect(options2.color).toEqual('#FF1122');
|
|
144
137
|
|
|
145
138
|
const options3 = handleMarkerOptions({ scale: 2 }, { color: '#FF1122' });
|
|
146
|
-
|
|
139
|
+
expect(options3.scale).toEqual(2);
|
|
147
140
|
});
|
|
148
141
|
|
|
149
142
|
describe('language detection', () => {
|
|
@@ -155,7 +148,7 @@ describe('Tests for util.js', () => {
|
|
|
155
148
|
languages: ['ja', 'en', 'en-US', 'ar'],
|
|
156
149
|
},
|
|
157
150
|
};
|
|
158
|
-
|
|
151
|
+
expect(getLang()).toEqual('ja');
|
|
159
152
|
});
|
|
160
153
|
|
|
161
154
|
it('should work with iOS safari', () => {
|
|
@@ -166,7 +159,7 @@ describe('Tests for util.js', () => {
|
|
|
166
159
|
languages: ['ja-JP'],
|
|
167
160
|
},
|
|
168
161
|
};
|
|
169
|
-
|
|
162
|
+
expect(getLang()).toEqual('ja');
|
|
170
163
|
});
|
|
171
164
|
});
|
|
172
165
|
|
|
@@ -178,58 +171,40 @@ describe('Tests for util.js', () => {
|
|
|
178
171
|
};
|
|
179
172
|
|
|
180
173
|
// 従来モード: 論理名(API キー必須)
|
|
181
|
-
|
|
182
|
-
'https://cdn.geolonia.com/style/hello/world/en.json',
|
|
183
|
-
getStyle('hello/world', atts),
|
|
174
|
+
expect('https://cdn.geolonia.com/style/hello/world/en.json').toEqual(getStyle('hello/world', atts),
|
|
184
175
|
);
|
|
185
176
|
|
|
186
177
|
// URL モード: https://(外部 URL、API キー不要)
|
|
187
|
-
|
|
188
|
-
'https://example.com/style.json',
|
|
189
|
-
getStyle('https://example.com/style.json', atts),
|
|
178
|
+
expect('https://example.com/style.json').toEqual(getStyle('https://example.com/style.json', atts),
|
|
190
179
|
);
|
|
191
180
|
|
|
192
181
|
// URL モード: 相対パス ./(外部 URL、API キー不要)
|
|
193
|
-
|
|
194
|
-
'https://base.example.com/parent/style.json',
|
|
195
|
-
getStyle('./style.json', atts),
|
|
182
|
+
expect('https://base.example.com/parent/style.json').toEqual(getStyle('./style.json', atts),
|
|
196
183
|
);
|
|
197
184
|
|
|
198
185
|
// URL モード: 絶対パス /(外部 URL、API キー不要)
|
|
199
|
-
|
|
200
|
-
'https://base.example.com/style.json',
|
|
201
|
-
getStyle('/style.json', atts),
|
|
186
|
+
expect('https://base.example.com/style.json').toEqual(getStyle('/style.json', atts),
|
|
202
187
|
);
|
|
203
188
|
|
|
204
189
|
// URL モード: .json で終わる(外部 URL として解決)
|
|
205
|
-
|
|
206
|
-
'https://base.example.com/parent/custom.json',
|
|
207
|
-
getStyle('custom.json', atts),
|
|
190
|
+
expect('https://base.example.com/parent/custom.json').toEqual(getStyle('custom.json', atts),
|
|
208
191
|
);
|
|
209
192
|
|
|
210
193
|
// デフォルト: 空文字列(API キー必須)
|
|
211
|
-
|
|
212
|
-
'https://cdn.geolonia.com/style/geolonia/basic-v2/en.json',
|
|
213
|
-
getStyle('', atts),
|
|
194
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/en.json').toEqual(getStyle('', atts),
|
|
214
195
|
);
|
|
215
196
|
|
|
216
197
|
// デフォルト: null/undefined(API キー必須)
|
|
217
|
-
|
|
218
|
-
'https://cdn.geolonia.com/style/geolonia/basic-v2/en.json',
|
|
219
|
-
getStyle(null, atts),
|
|
198
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/en.json').toEqual(getStyle(null, atts),
|
|
220
199
|
);
|
|
221
200
|
|
|
222
201
|
// 日本語環境でのデフォルト
|
|
223
202
|
const attsJa = { ...atts, lang: 'ja' };
|
|
224
|
-
|
|
225
|
-
'https://cdn.geolonia.com/style/geolonia/basic-v2/ja.json',
|
|
226
|
-
getStyle('', attsJa),
|
|
203
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/ja.json').toEqual(getStyle('', attsJa),
|
|
227
204
|
);
|
|
228
205
|
|
|
229
206
|
// 日本語環境での論理名
|
|
230
|
-
|
|
231
|
-
'https://cdn.geolonia.com/style/geolonia/basic/ja.json',
|
|
232
|
-
getStyle('geolonia/basic', attsJa),
|
|
207
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic/ja.json').toEqual(getStyle('geolonia/basic', attsJa),
|
|
233
208
|
);
|
|
234
209
|
});
|
|
235
210
|
|
|
@@ -241,93 +216,88 @@ describe('Tests for util.js', () => {
|
|
|
241
216
|
};
|
|
242
217
|
|
|
243
218
|
// 論理名: API キー無しでエラー
|
|
244
|
-
|
|
219
|
+
expect(
|
|
245
220
|
() => getStyle('geolonia/basic', attsNoKey),
|
|
246
|
-
|
|
247
|
-
);
|
|
221
|
+
).toThrow(/API key is required/);
|
|
248
222
|
|
|
249
223
|
// デフォルト: API キー無しでエラー
|
|
250
|
-
|
|
224
|
+
expect(
|
|
251
225
|
() => getStyle('', attsNoKey),
|
|
252
|
-
|
|
253
|
-
);
|
|
226
|
+
).toThrow(/API key is required/);
|
|
254
227
|
|
|
255
228
|
// Geolonia CDN の URL: API キー無しでエラー
|
|
256
|
-
|
|
229
|
+
expect(
|
|
257
230
|
() => getStyle('https://cdn.geolonia.com/style/geolonia/basic/en.json', attsNoKey),
|
|
258
|
-
|
|
259
|
-
);
|
|
231
|
+
).toThrow(/API key is required/);
|
|
260
232
|
|
|
261
233
|
// 外部 URL: API キー無しでも OK
|
|
262
|
-
|
|
234
|
+
expect(() => {
|
|
263
235
|
getStyle('https://tile.openstreetmap.jp/styles/osm-bright/style.json', attsNoKey);
|
|
264
|
-
});
|
|
236
|
+
}).not.toThrow();
|
|
265
237
|
|
|
266
|
-
|
|
238
|
+
expect(() => {
|
|
267
239
|
getStyle('./my-style.json', attsNoKey);
|
|
268
|
-
});
|
|
240
|
+
}).not.toThrow();
|
|
269
241
|
});
|
|
270
242
|
|
|
271
243
|
it('should handle maplibregl options `minZoom` and `maxZoom` well', () => {
|
|
272
244
|
{
|
|
273
245
|
const atts = { minZoom: '', maxZoom: '10' };
|
|
274
246
|
const options = getOptions({}, {}, atts);
|
|
275
|
-
|
|
276
|
-
|
|
247
|
+
expect('undefined').toEqual(typeof options.minZoom);
|
|
248
|
+
expect(10).toEqual(options.maxZoom);
|
|
277
249
|
}
|
|
278
250
|
|
|
279
251
|
{
|
|
280
252
|
const atts = { minZoom: '0', maxZoom: '' };
|
|
281
253
|
const options = getOptions({}, {}, atts);
|
|
282
|
-
|
|
283
|
-
|
|
254
|
+
expect(0).toEqual(options.minZoom);
|
|
255
|
+
expect('undefined').toEqual(typeof options.maxZoom);
|
|
284
256
|
}
|
|
285
257
|
|
|
286
258
|
{
|
|
287
259
|
const atts = { minZoom: '0', maxZoom: '' };
|
|
288
260
|
const params = { minZoom: 7 };
|
|
289
261
|
const options = getOptions({}, params, atts);
|
|
290
|
-
|
|
291
|
-
|
|
262
|
+
expect(7).toEqual(options.minZoom);
|
|
263
|
+
expect('undefined').toEqual(typeof options.maxZoom);
|
|
292
264
|
}
|
|
293
265
|
});
|
|
294
266
|
|
|
295
267
|
it('should handle control position options.', () => {
|
|
296
268
|
const att = 'top-left';
|
|
297
269
|
const { enabled, position } = parseControlOption(att);
|
|
298
|
-
|
|
299
|
-
|
|
270
|
+
expect(true).toBe(enabled);
|
|
271
|
+
expect('top-left').toBe(position);
|
|
300
272
|
});
|
|
301
273
|
|
|
302
274
|
it('should handle control position on.', () => {
|
|
303
275
|
const att = 'on';
|
|
304
276
|
const { enabled, position } = parseControlOption(att);
|
|
305
|
-
|
|
306
|
-
|
|
277
|
+
expect(true).toBe(enabled);
|
|
278
|
+
expect(void 0).toBe(position);
|
|
307
279
|
});
|
|
308
280
|
|
|
309
281
|
it('should handle control position off.', () => {
|
|
310
282
|
const att = 'off';
|
|
311
283
|
const { enabled, position } = parseControlOption(att);
|
|
312
|
-
|
|
313
|
-
|
|
284
|
+
expect(false).toBe(enabled);
|
|
285
|
+
expect(void 0).toBe(position);
|
|
314
286
|
});
|
|
315
287
|
|
|
316
288
|
it('should parse simple vector value with http.', () => {
|
|
317
289
|
const attributeValue = 'https://example.com/path/to/tile.json';
|
|
318
|
-
|
|
290
|
+
expect(attributeValue).toBe(parseSimpleVector(attributeValue));
|
|
319
291
|
});
|
|
320
292
|
|
|
321
293
|
it('should parse simple vector value with geolonia schema.', () => {
|
|
322
294
|
const attributeValue = 'geolonia://tiles/username/ct_123';
|
|
323
|
-
|
|
295
|
+
expect(attributeValue).toBe(parseSimpleVector(attributeValue));
|
|
324
296
|
});
|
|
325
297
|
|
|
326
298
|
it('should parse simple vector value with custom tile ID', () => {
|
|
327
299
|
const attributeValue = 'ct_123';
|
|
328
|
-
|
|
329
|
-
'geolonia://tiles/custom/ct_123',
|
|
330
|
-
parseSimpleVector(attributeValue),
|
|
300
|
+
expect('geolonia://tiles/custom/ct_123').toBe(parseSimpleVector(attributeValue),
|
|
331
301
|
);
|
|
332
302
|
});
|
|
333
303
|
|
|
@@ -335,9 +305,7 @@ describe('Tests for util.js', () => {
|
|
|
335
305
|
it('should sanitize description', async () => {
|
|
336
306
|
const description =
|
|
337
307
|
'<script>alert("hello");</script>ここが集合場所です。13時までに集合してください。';
|
|
338
|
-
|
|
339
|
-
'ここが集合場所です。13時までに集合してください。',
|
|
340
|
-
await sanitizeDescription(description),
|
|
308
|
+
expect('ここが集合場所です。13時までに集合してください。').toBe(await sanitizeDescription(description),
|
|
341
309
|
);
|
|
342
310
|
});
|
|
343
311
|
|
|
@@ -345,26 +313,21 @@ describe('Tests for util.js', () => {
|
|
|
345
313
|
// Ref. https://www.npmjs.com/package/sanitize-html
|
|
346
314
|
const description =
|
|
347
315
|
'<img decoding="auto" src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。';
|
|
348
|
-
|
|
349
|
-
'<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。',
|
|
350
|
-
await sanitizeDescription(description),
|
|
316
|
+
expect('<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。').toBe(await sanitizeDescription(description),
|
|
351
317
|
);
|
|
352
318
|
});
|
|
353
319
|
|
|
354
320
|
it('should not sanitize "class" attribute', async () => {
|
|
355
321
|
const description =
|
|
356
322
|
'<span class="red">ここが集合場所です。13時までに集合してください。</span>';
|
|
357
|
-
|
|
358
|
-
'<span class="red">ここが集合場所です。13時までに集合してください。</span>',
|
|
359
|
-
await sanitizeDescription(description),
|
|
323
|
+
expect('<span class="red">ここが集合場所です。13時までに集合してください。</span>').toBe(await sanitizeDescription(description),
|
|
360
324
|
);
|
|
361
325
|
});
|
|
362
326
|
});
|
|
363
327
|
});
|
|
364
328
|
|
|
365
329
|
describe('loadImageCompatibility', () => {
|
|
366
|
-
it('should call the callback with response data when the promise resolves', (
|
|
367
|
-
// モックされた成功した promise
|
|
330
|
+
it('should call the callback with response data when the promise resolves', async () => {
|
|
368
331
|
const mockResponse = {
|
|
369
332
|
data: new Image(),
|
|
370
333
|
cacheControl: 'public, max-age=3600',
|
|
@@ -372,27 +335,30 @@ describe('loadImageCompatibility', () => {
|
|
|
372
335
|
};
|
|
373
336
|
const promise = Promise.resolve(mockResponse);
|
|
374
337
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
338
|
+
await new Promise<void>((resolve) => {
|
|
339
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
340
|
+
expect(error).toEqual(null);
|
|
341
|
+
expect(data).toEqual(mockResponse.data);
|
|
342
|
+
expect(expiry).toEqual({
|
|
343
|
+
cacheControl: mockResponse.cacheControl,
|
|
344
|
+
expires: mockResponse.expires,
|
|
345
|
+
});
|
|
346
|
+
resolve();
|
|
381
347
|
});
|
|
382
|
-
done();
|
|
383
348
|
});
|
|
384
349
|
});
|
|
385
350
|
|
|
386
|
-
it('should call the callback with error when the promise rejects', (
|
|
387
|
-
// モックされた失敗した promise
|
|
351
|
+
it('should call the callback with error when the promise rejects', async () => {
|
|
388
352
|
const mockError = new Error('Failed to load image');
|
|
389
353
|
const promise = Promise.reject(mockError);
|
|
390
354
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
355
|
+
await new Promise<void>((resolve) => {
|
|
356
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
357
|
+
expect(error).toEqual(mockError);
|
|
358
|
+
expect(data).toBe(undefined);
|
|
359
|
+
expect(expiry).toBe(undefined);
|
|
360
|
+
resolve();
|
|
361
|
+
});
|
|
396
362
|
});
|
|
397
363
|
});
|
|
398
364
|
});
|
package/src/testability.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
1
2
|
import { JSDOM } from 'jsdom';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import maplibregl from 'maplibre-gl';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -10,11 +11,14 @@ import maplibregl from 'maplibre-gl';
|
|
|
10
11
|
|
|
11
12
|
describe('maplibre-gl jsdom limitation', () => {
|
|
12
13
|
it('jsdom上ではMaplibre Mapインスタンス生成時にエラー(WebGL未対応のため)', () => {
|
|
14
|
+
// jsdom の "Not implemented" メッセージを抑制
|
|
15
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
16
|
+
|
|
13
17
|
const dom = new JSDOM(
|
|
14
18
|
'<!DOCTYPE html><html><body><div id="map"></div></body></html>',
|
|
15
19
|
{
|
|
16
20
|
url: 'http://localhost',
|
|
17
|
-
pretendToBeVisual: true,
|
|
21
|
+
pretendToBeVisual: true,
|
|
18
22
|
},
|
|
19
23
|
);
|
|
20
24
|
// @ts-ignore
|
|
@@ -31,16 +35,15 @@ describe('maplibre-gl jsdom limitation', () => {
|
|
|
31
35
|
} catch (err) {
|
|
32
36
|
errorCaught = err;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
38
|
+
expect(errorCaught).toBeInstanceOf(Error);
|
|
39
|
+
expect(
|
|
40
|
+
/webgl|WebGL|context|device|Not implemented/i.test(errorCaught.message),
|
|
41
|
+
).toBe(true);
|
|
42
|
+
|
|
43
|
+
consoleSpy.mockRestore();
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
it('【NOTE】描画テストが必要な場合はE2E(ブラウザ実行)で行うこと', () => {
|
|
43
|
-
|
|
44
|
-
assert.strictEqual(true, true);
|
|
47
|
+
expect(true).toBe(true);
|
|
45
48
|
});
|
|
46
49
|
});
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
ADDED
package/webpack.config.js
CHANGED
package/.mocharc.js
DELETED
package/dist/e2e/basic.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/e2e/helper.d.ts
DELETED
package/dist/e2e/map.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|