-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathpretest.js
68 lines (56 loc) · 1.95 KB
/
pretest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var fs = require('fs');
var constants = require('./util/constants');
var common = require('./util/common');
// main
makeCredentialsFile();
makeSetPlotConfigFile();
makeTestImageFolders();
makeRequireJSFixture();
// Create a credentials json file,
// to be required in jasmine test suites and test dashboard
function makeCredentialsFile() {
var credentials = JSON.stringify({
MAPBOX_ACCESS_TOKEN: constants.mapboxAccessToken
}, null, 2);
common.writeFile(constants.pathToCredentials, credentials);
logger('make build/credentials.json');
}
// Create a 'set plot config' file,
// to be included in the image test index
function makeSetPlotConfigFile() {
var setPlotConfig = [
'\'use strict\';',
'',
'/* global Plotly:false */',
'',
'Plotly.setPlotConfig({',
' mapboxAccessToken: \'' + constants.mapboxAccessToken + '\'',
'});',
''
].join('\n');
common.writeFile(constants.pathToSetPlotConfig, setPlotConfig);
logger('make build/set_plot_config.js');
}
// Make artifact folders for image tests
function makeTestImageFolders() {
function makeOne(folderPath, info) {
if(!common.doesDirExist(folderPath)) {
fs.mkdirSync(folderPath);
logger('initialize ' + info);
}
else logger(info + ' is present');
}
makeOne(constants.pathToTestImages, 'test image folder');
makeOne(constants.pathToTestImagesDiff, 'test image diff folder');
}
// Make script file that define plotly in a RequireJS context
function makeRequireJSFixture() {
var bundle = fs.readFileSync(constants.pathToPlotlyDistMin, 'utf-8'),
template = 'define(\'plotly\', function(require, exports, module) { {{bundle}} });',
index = template.replace('{{bundle}}', bundle);
common.writeFile(constants.pathToRequireJSFixture, index);
logger('make build/requirejs_fixture.js');
}
function logger(task) {
console.log('ok ' + task);
}