|
1 | 1 | var fs = require('fs'); |
2 | | -var constants = require('./util/constants'); |
3 | 2 |
|
| 3 | +var constants = require('./util/constants'); |
| 4 | +var common = require('./util/common'); |
| 5 | +var containerCommands = require('./util/container_commands'); |
| 6 | +var isCI = process.env.CIRCLECI; |
4 | 7 |
|
| 8 | +// main |
| 9 | +makeCredentialsFile(); |
| 10 | +makeSetPlotConfigFile(); |
| 11 | +makeTestImageFolders(); |
| 12 | +if(isCI) runAndSetupImageTestContainer(); |
5 | 13 |
|
6 | 14 | // Create a credentials json file, |
7 | 15 | // to be required in jasmine test suites and test dashboard |
8 | | -var credentials = JSON.stringify({ |
9 | | - MAPBOX_ACCESS_TOKEN: mapboxAccessToken |
10 | | -}, null, 2); |
| 16 | +function makeCredentialsFile() { |
| 17 | + var credentials = JSON.stringify({ |
| 18 | + MAPBOX_ACCESS_TOKEN: constants.mapboxAccessToken |
| 19 | + }, null, 2); |
11 | 20 |
|
12 | | -fs.writeFile(constants.pathToCredentials, credentials, function(err) { |
13 | | - if(err) throw err; |
14 | | -}); |
| 21 | + common.writeFile(constants.pathToCredentials, credentials); |
| 22 | + logger('make build/credentials.json'); |
| 23 | +} |
15 | 24 |
|
16 | 25 | // Create a 'set plot config' file, |
17 | 26 | // to be included in the image test index |
18 | | -var setPlotConfig = [ |
19 | | - '\'use strict\';', |
20 | | - '', |
21 | | - '/* global Plotly:false */', |
22 | | - '', |
23 | | - 'Plotly.setPlotConfig({', |
24 | | - ' mapboxAccessToken: \'' + mapboxAccessToken + '\'', |
25 | | - '});', |
26 | | - '' |
27 | | -].join('\n'); |
28 | | - |
29 | | -fs.writeFile(constants.pathToSetPlotConfig, setPlotConfig, function(err) { |
30 | | - if(err) throw err; |
31 | | -}); |
32 | | - |
33 | | -// make artifact folders for image tests |
34 | | -if(!doesDirExist(constants.pathToTestImagesDiff)) { |
35 | | - fs.mkdirSync(constants.pathToTestImagesDiff); |
| 27 | +function makeSetPlotConfigFile() { |
| 28 | + var setPlotConfig = [ |
| 29 | + '\'use strict\';', |
| 30 | + '', |
| 31 | + '/* global Plotly:false */', |
| 32 | + '', |
| 33 | + 'Plotly.setPlotConfig({', |
| 34 | + ' mapboxAccessToken: \'' + constants.mapboxAccessToken + '\'', |
| 35 | + '});', |
| 36 | + '' |
| 37 | + ].join('\n'); |
| 38 | + |
| 39 | + common.writeFile(constants.pathToSetPlotConfig, setPlotConfig); |
| 40 | + logger('make build/set_plot_config.js'); |
36 | 41 | } |
37 | | -if(!doesDirExist(constants.pathToTestImages)) { |
38 | | - fs.mkdirSync(constants.pathToTestImages); |
| 42 | + |
| 43 | +// Make artifact folders for image tests |
| 44 | +function makeTestImageFolders() { |
| 45 | + |
| 46 | + function makeOne(folderPath, info) { |
| 47 | + if(!common.doesDirExist(folderPath)) { |
| 48 | + fs.mkdirSync(folderPath); |
| 49 | + logger('initialize ' + info); |
| 50 | + } |
| 51 | + else logger(info + ' is present'); |
| 52 | + } |
| 53 | + |
| 54 | + makeOne(constants.pathToTestImages, 'test image folder'); |
| 55 | + makeOne(constants.pathToTestImagesDiff, 'test image diff folder'); |
39 | 56 | } |
40 | 57 |
|
41 | | -function doesDirExist(dirPath) { |
42 | | - try { |
43 | | - if(fs.statSync(dirPath).isDirectory()) return true; |
| 58 | +// On CircleCI, run and setup image test container once an for all |
| 59 | +function runAndSetupImageTestContainer() { |
| 60 | + |
| 61 | + function run() { |
| 62 | + var cmd = containerCommands.dockerRun; |
| 63 | + common.execCmd(cmd, function() { |
| 64 | + logger('run docker container'); |
| 65 | + setup(); |
| 66 | + }); |
44 | 67 | } |
45 | | - catch(e) { |
46 | | - return false; |
| 68 | + |
| 69 | + function setup() { |
| 70 | + var cmd = containerCommands.getRunCmd(isCI, [ |
| 71 | + containerCommands.setup |
| 72 | + ]); |
| 73 | + common.execCmd(cmd, function() { |
| 74 | + logger('setup docker container'); |
| 75 | + }); |
47 | 76 | } |
48 | 77 |
|
49 | | - return false; |
| 78 | + run(); |
| 79 | +} |
| 80 | + |
| 81 | +function logger(task) { |
| 82 | + console.log('ok ' + task); |
50 | 83 | } |
0 commit comments