Skip to content

Commit cc22b68

Browse files
karimnaajirreusser
andauthored
Release testing fixes (#10651)
* Fix release testing links * Testing * Fixup * Replace API Key * Update test/release/index.js Co-authored-by: Ricky Reusser <[email protected]> * Update test/release/index.js Co-authored-by: Ricky Reusser <[email protected]> * Testing * Testing * Fixup * Fixup Co-authored-by: Ricky Reusser <[email protected]>
1 parent 2df9f37 commit cc22b68

File tree

1 file changed

+28
-96
lines changed

1 file changed

+28
-96
lines changed

test/release/index.js

Lines changed: 28 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ const pages = [
1818
"key": "queryrenderedfeatures",
1919
"title": "Get features under the mouse pointer"
2020
},
21-
{
22-
"key": "queryrenderedfeatures",
23-
"title": "Get features under the mouse pointer (3d)",
24-
"inject3d": true
25-
},
2621
{
2722
"key": "scroll-fly-to",
2823
"title": "Fly to a location based on scroll position"
@@ -39,11 +34,6 @@ const pages = [
3934
"key": "satellite-map",
4035
"title": "Display a satellite map"
4136
},
42-
{
43-
"key": "satellite-map",
44-
"title": "Display a satellite map (3d)",
45-
"inject3d": true
46-
},
4737
{
4838
"key": "custom-marker-icons",
4939
"title": "Add custom icons with Markers"
@@ -56,20 +46,10 @@ const pages = [
5646
"key": "video-on-a-map",
5747
"title": "Add a video"
5848
},
59-
{
60-
"key": "video-on-a-map",
61-
"title": "Add a video (3d)",
62-
"inject3d": true
63-
},
6449
{
6550
"key": "custom-style-layer",
6651
"title": "Add a custom style layer"
6752
},
68-
{
69-
"key": "custom-style-layer",
70-
"title": "Add a custom style layer (3d)",
71-
"inject3d": true
72-
},
7353
{
7454
"key": "adjust-layer-opacity",
7555
"title": "Adjust a layer's opacity"
@@ -86,20 +66,10 @@ const pages = [
8666
"key": "mapbox-gl-directions",
8767
"title": "Display driving directions"
8868
},
89-
{
90-
"key": "mapbox-gl-directions",
91-
"title": "Display driving directions (3d)",
92-
"inject3d": true
93-
},
9469
{
9570
"key": "mapbox-gl-draw",
9671
"title": "Show drawn polygon area"
9772
},
98-
{
99-
"key": "mapbox-gl-draw",
100-
"title": "Show drawn polygon area (3d)",
101-
"inject3d": true
102-
},
10373
{
10474
"key": "mapbox-gl-compare",
10575
"title": "Swipe between maps"
@@ -112,11 +82,6 @@ const pages = [
11282
"key": "heatmap-layer",
11383
"title": "Add a heatmap layer"
11484
},
115-
{
116-
"key": "heatmap-layer",
117-
"title": "Add a heatmap layer (3d)",
118-
"inject3d": true
119-
},
12085
{
12186
"key": "add-terrain",
12287
"title": "Add Terrain"
@@ -142,11 +107,6 @@ const pages = [
142107
"key": "image-on-a-map",
143108
"title": "Image Source"
144109
},
145-
{
146-
"key": "image-on-a-map",
147-
"title": "Image Source (3d)",
148-
"inject3d": true
149-
},
150110
{
151111
"key": "extrusion-query",
152112
"url": "./extrusion-query.html",
@@ -298,7 +258,8 @@ document.addEventListener('DOMContentLoaded', function() {
298258

299259
req = new XMLHttpRequest();
300260
req.addEventListener("load", loadedHTML);
301-
url = page.url ? page.url : 'https://raw.githubusercontent.com/mapbox/mapbox-gl-js-docs/publisher-production/docs/pages/example/' + page.key + '.html';
261+
262+
url = page.url ? page.url : 'https://docs.mapbox.com/mapbox-gl-js/assets/' + page.key + '-demo.html';
302263
req.open("GET", url);
303264
req.send();
304265

@@ -315,62 +276,33 @@ document.addEventListener('DOMContentLoaded', function() {
315276
const css = version === 'latest' ? cssLatest.href : 'https://api.mapbox.com/mapbox-gl-js/' + version + '/mapbox-gl.css';
316277

317278
let doc = req.response;
318-
// Only inject 3d code in version > v1
319-
if (page.inject3d && params.version.substr(0, 2) !== 'v1' && params.version.substr(0, 2) !== 'v0') {
320-
const regex0 = /new mapboxgl\.Map((.|\n)*?)}\)\);/g;
321-
const regex1 = /new mapboxgl\.Map((.|\n)*?)}\);/g;
322-
const match = req.response.match(regex0);
323-
const regex = match && match.length > 0 ? regex0 : regex1;
324-
doc = req.response.replace(regex, '$&' +
325-
`map.on('style.load', function () {
326-
map.addSource('mapbox_dem', {
327-
"type": "raster-dem",
328-
"url": "mapbox://mapbox.mapbox-terrain-dem-v1",
329-
"tileSize": 512,
330-
"maxzoom": 14
331-
});
332-
333-
map.addLayer({
334-
'id': 'sky_layer',
335-
'type': 'sky',
336-
'paint': {
337-
'sky-type': 'atmosphere',
338-
'sky-atmosphere-sun': [0, 0],
339-
'sky-opacity': [
340-
'interpolate',
341-
['exponential', 0.1],
342-
['zoom'],
343-
5,
344-
0,
345-
22,
346-
1
347-
]
348-
}
349-
});
350-
351-
map.setTerrain({"source": "mapbox_dem", "exaggeration": 1.2});
352-
});`
353-
);
279+
280+
if (!page.url) { // Perform cleanups for pages hosted on docs.mapbox.com, otherwise directly use demo code
281+
const versionLibRegex = /https:\/\/api\.mapbox\.com\/mapbox-gl-js\/v[0-9]+\.[0-9]+\.[0-9]+\/mapbox-gl\.js/g;
282+
const versionCSSRegex = /https:\/\/api\.mapbox\.com\/mapbox-gl-js\/v[0-9]+\.[0-9]+\.[0-9]+\/mapbox-gl\.css/g;
283+
const sentryRegex = /<script src="https:\/\/js\.sentry-cdn\.com\/[0-9a-f]*\.min\.js"\s*crossorigin="anonymous"><\/script>/g;
284+
const instrumentileRegex = /<script>if\(window\.map instanceof mapboxgl\.Map\)var i=new instrumentile.*<\/script>/g;
285+
const apiKeyRegex = /pk\..*?"/g;
286+
287+
// Update versions + api key
288+
doc = doc.replace(versionLibRegex, js);
289+
doc = doc.replace(versionCSSRegex, css);
290+
doc = doc.replace(apiKeyRegex, params.access_token + '"');
291+
292+
// Remove extraneous analytics
293+
doc = doc.replace(instrumentileRegex, '');
294+
doc = doc.replace(sentryRegex, '');
295+
} else { // Perform cleanups of pages locally referenced
296+
const versionLibRegex = /<script src='(.*)mapbox-gl(.*)\.js'><\/script>/g;
297+
const versionCSSRegex = /<link rel='stylesheet'(.*)mapbox-gl\.css'(.*)\/>/g;
298+
const apiKeyRegex = /<script(.*)access_token_generated\.js(.*)\/script>/g;
299+
300+
doc = doc.replace(versionLibRegex, '<script src="' + js + '"></script>');
301+
doc = doc.replace(versionCSSRegex, '<link rel="stylesheet" href="' + css + '" />');
302+
doc = doc.replace(apiKeyRegex, '<script>mapboxgl.accessToken="' + params.access_token + '"</script>');
354303
}
355-
iframeDoc.write([
356-
'<!DOCTYPE html>',
357-
'<html>',
358-
'<head>',
359-
' <title>Mapbox GL JS debug page</title>',
360-
' <meta charset="utf-8">',
361-
' <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">',
362-
' <script src="' + js + '"><\/script>',
363-
' <script>mapboxgl.accessToken = "' + params.access_token + '";<\/script>',
364-
' <link rel="stylesheet" href="' + css + '" />',
365-
' <style>',
366-
' body { margin: 0; padding: 0; }',
367-
' html, body, #map { height: 100%; }',
368-
' </style>',
369-
'</head>',
370-
'<body>',
371-
doc,
372-
'</body>',
373-
'</html>' ].join(''));
304+
305+
iframeDoc.write([doc].join(''));
374306
iframeDoc.close();
375307
}
376308

0 commit comments

Comments
 (0)