Skip to content

Commit 3e79f0d

Browse files
committed
add 'pretest' tasks,
- that setups build files containing mapbox crendentials so that test runners can load them seamlessly.
1 parent 6a73378 commit 3e79f0d

File tree

5 files changed

+56
-1
lines changed

5 files changed

+56
-1
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ which shows the baseline image, the generated image, the diff and the json mocks
157157

158158
To view the results of a run on CircleCI, download the `build/test_images/` and `build/test_images_diff/` artifacts into your local repo and then run `npm run start-image_viewer`.
159159

160+
### Note on testing our `mapbox-gl` integration
161+
162+
Creating `mapbox-gl` graphs requires an
163+
[`accessToken`](https://www.mapbox.com/help/define-access-token/). To make sure
164+
that mapbox image and jasmine tests run properly, locate your Mapbox access
165+
token and run:
166+
167+
168+
```bash
169+
export MAPBOX_ACCESS_TOKEN="<your access token>" && npm run pretest
170+
```
171+
160172

161173
## Repo organization
162174

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"watch": "node tasks/watch_plotly.js",
3030
"lint": "eslint . || true",
3131
"lint-fix": "eslint . --fix",
32+
"pretest": "node tasks/pretest.js",
3233
"test-jasmine": "karma start test/jasmine/karma.conf.js",
3334
"citest-jasmine": "karma start test/jasmine/karma.ciconf.js",
3435
"test-image": "./tasks/test_image.sh",

tasks/pretest.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var fs = require('fs');
2+
var constants = require('./util/constants');
3+
var mapboxAccessToken = process.env.MAPBOX_ACCESS_TOKEN;
4+
5+
6+
if(!mapboxAccessToken) {
7+
throw new Error([
8+
'MAPBOX_ACCESS_TOKEN not found!!!',
9+
'Please export your mapbox access token into and try again.'
10+
].join('\n'));
11+
}
12+
13+
// Create a credentials json file,
14+
// to be required in jasmine test suites and test dashboard
15+
var credentials = JSON.stringify({
16+
MAPBOX_ACCESS_TOKEN: mapboxAccessToken
17+
}, null, 2);
18+
19+
fs.writeFile(constants.pathToCredentials, credentials, function(err) {
20+
if(err) throw err;
21+
});
22+
23+
// Create a 'set plot config' file,
24+
// to be included in the image test index
25+
var setPlotConfig = [
26+
'\'use strict\';',
27+
'',
28+
'/* global Plotly:false */',
29+
'',
30+
'Plotly.setPlotConfig({',
31+
' mapboxAccessToken: \'' + mapboxAccessToken + '\'',
32+
'});',
33+
''
34+
].join('\n');
35+
36+
fs.writeFile(constants.pathToSetPlotConfig, setPlotConfig, function(err) {
37+
if(err) throw err;
38+
});

tasks/util/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ module.exports = {
5151
pathToJasmineTests: path.join(pathToRoot, 'test/jasmine/tests'),
5252
pathToJasmineBundleTests: path.join(pathToRoot, 'test/jasmine/bundle_tests'),
5353

54+
pathToCredentials: path.join(pathToBuild, 'credentials.json'),
55+
pathToSetPlotConfig: path.join(pathToBuild, 'set_plot_config.js'),
56+
5457
uglifyOptions: {
5558
fromString: true,
5659
mangle: true,

tasks/util/shortcut_paths.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var constants = require('./constants');
1111
var shortcutsConfig = {
1212
'@src': constants.pathToSrc,
1313
'@lib': constants.pathToLib,
14-
'@mocks': constants.pathToTestImageMocks
14+
'@mocks': constants.pathToTestImageMocks,
15+
'@build': constants.pathToBuild
1516
};
1617

1718
module.exports = transformTools.makeRequireTransform('requireTransform',

0 commit comments

Comments
 (0)