Skip to content

Commit 25e8678

Browse files
committed
add b64 test dashboard - add script to convert mocks to b64
1 parent 509f7df commit 25e8678

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

devtools/test_dashboard/server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config.optimization = { minimize: false };
1212

1313
var args = minimist(process.argv.slice(2), {});
1414
var PORT = args.port || 3000;
15+
var b64 = args.b64;
1516
var strict = args.strict;
1617
var mathjax3 = args.mathjax3;
1718
var mathjax3chtml = args.mathjax3chtml;
@@ -23,6 +24,7 @@ if(!strict) {
2324
config.devtool = 'eval';
2425
}
2526

27+
var mockFolder = path.join(constants.pathToImageTest, b64 ? 'b64' : 'mocks');
2628

2729
// mock list
2830
getMockFiles()
@@ -104,7 +106,7 @@ compiler.run(function(devtoolsErr, devtoolsStats) {
104106

105107
function getMockFiles() {
106108
return new Promise(function(resolve, reject) {
107-
fs.readdir(constants.pathToTestImageMocks, function(err, files) {
109+
fs.readdir(mockFolder, function(err, files) {
108110
if(err) {
109111
reject(err);
110112
} else {
@@ -116,7 +118,7 @@ function getMockFiles() {
116118

117119
function readFiles(files) {
118120
var promises = files.map(function(file) {
119-
var filePath = path.join(constants.pathToTestImageMocks, file);
121+
var filePath = path.join(mockFolder, file);
120122
return readFilePromise(filePath);
121123
});
122124

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"test-requirejs": "node tasks/test_requirejs.js",
5353
"test-plain-obj": "node tasks/test_plain_obj.js",
5454
"test": "npm run test-jasmine -- --nowatch && npm run test-bundle && npm run test-image && npm run test-export && npm run test-syntax && npm run lint",
55+
"b64": "python3 test/image/generate_b64_mocks.py && node devtools/test_dashboard/server.js --b64",
5556
"mathjax3": "node devtools/test_dashboard/server.js --mathjax3",
5657
"mathjax3chtml": "node devtools/test_dashboard/server.js --mathjax3chtml",
5758
"strict": "node devtools/test_dashboard/server.js --strict",

test/image/b64/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.json

test/image/generate_b64_mocks.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
import sys
3+
import json
4+
import plotly.io as pio
5+
from convert_b64 import arraysToB64
6+
7+
args = []
8+
if len(sys.argv) == 2 :
9+
args = sys.argv[1].split()
10+
elif len(sys.argv) > 1 :
11+
args = sys.argv
12+
13+
root = os.getcwd()
14+
dirIn = os.path.join(root, 'test', 'image', 'mocks')
15+
dirOut = os.path.join(root, 'test', 'image', 'b64')
16+
17+
print('output to', dirOut)
18+
19+
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
20+
ALL_MOCKS.sort()
21+
22+
if len(args) > 0 :
23+
allNames = [a for a in args if a in ALL_MOCKS]
24+
else :
25+
allNames = ALL_MOCKS
26+
27+
if len(allNames) == 0 :
28+
print('error: Nothing to create!')
29+
sys.exit(1)
30+
31+
for name in allNames :
32+
outName = name
33+
34+
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
35+
fig = json.load(_in)
36+
37+
before = json.dumps(fig, indent = 2)
38+
39+
newFig = dict()
40+
arraysToB64(fig, newFig)
41+
fig = newFig
42+
43+
after = json.dumps(fig, indent = 2)
44+
45+
if before != after :
46+
print(outName)
47+
48+
_out = open(os.path.join(dirOut, outName + '.json'), 'w')
49+
_out.write(json.dumps(fig, indent = 2))
50+
_out.close()

0 commit comments

Comments
 (0)