Skip to content

Commit

Permalink
[docs] token refactor in docs-page-shell (#8174) (#8181)
Browse files Browse the repository at this point in the history
* Update page-shell-script.js

* do not force production page shell

* remove hardcoded token from example, add unit test to look for access token in example html files
  • Loading branch information
mourner authored Apr 24, 2019
1 parent 428480a commit 38e555e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 0 additions & 1 deletion docs/components/application-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';

if (typeof window !== 'undefined') {
window.MapboxPageShellProduction = true;
import(/* webpackChunkName: "assembly-js" */ '@mapbox/mbx-assembly/dist/assembly.js');
}

Expand Down
1 change: 0 additions & 1 deletion docs/pages/example/jump-to.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
]
};

mapboxgl.accessToken = 'pk.eyJ1IjoibWFsLXdvb2QiLCJhIjoiY2oyZ2t2em50MDAyMzJ3cnltMDFhb2NzdiJ9.X-D4Wvo5E5QxeP7K_I3O8w';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
Expand Down
25 changes: 23 additions & 2 deletions test/unit/docs/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const readPost = filename => {
}
};

const listExamples = dir => {

const listExamplesJs = dir => {
const files = fs.readdirSync(`${dir}`);
return files.reduce((arr, file) => {
if (path.extname(file) === '.js') {
Expand All @@ -37,7 +38,18 @@ const listExamples = dir => {
}, []);
};

listExamples('./docs/pages/example/').forEach((example) => {
const listExamplesHtml = dir => {
const files = fs.readdirSync(`${dir}`);
return files.reduce((arr, file) => {
if (path.extname(file) === '.html') {
arr.push(`${dir}${file}`);
}
return arr;
}, []);
};

// Test .js files
listExamplesJs('./docs/pages/example/').forEach((example) => {
const file = readPost(example);
const metadata = file.metadata;

Expand Down Expand Up @@ -65,3 +77,12 @@ listExamples('./docs/pages/example/').forEach((example) => {
});
}
});

// Test .html files
listExamplesHtml('./docs/pages/example/').forEach((example) => {
const file = readPost(example);
test(`Example: ${example}`, (t) => {
t.ok(!file.file.includes('pk.ey'), 'do not hardcode access tokens, an access token will be appended automatically');
t.end();
});
});
2 changes: 1 addition & 1 deletion vendor/docs-page-shell/page-shell-script.js

Large diffs are not rendered by default.

0 comments on commit 38e555e

Please sign in to comment.