powerbi-visuals-tools 4.0.4 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/Changelog.md +8 -0
  2. package/certs/PowerBICustomVisualTest_private.key +28 -0
  3. package/certs/PowerBICustomVisualTest_public.crt +19 -0
  4. package/config.json +35 -1
  5. package/lib/VisualGenerator.js +0 -95
  6. package/package.json +3 -3
  7. package/spec/.jshintrc +5 -0
  8. package/spec/clean-tests.js +31 -0
  9. package/spec/e2e/pbivizCertSpec.js +56 -0
  10. package/spec/e2e/pbivizInfoSpec.js +82 -0
  11. package/spec/e2e/pbivizNewSpec.js +265 -0
  12. package/spec/e2e/pbivizPackageSpec.js +670 -0
  13. package/spec/e2e/pbivizStartSpec.js +380 -0
  14. package/spec/e2e/pbivizWebpackVerSpec.js +102 -0
  15. package/spec/e2e/utils.js +63 -0
  16. package/spec/helpers/FileSystem.js +173 -0
  17. package/spec/jasmine-runner.js +36 -0
  18. package/spec/support/jasmine.json +11 -0
  19. package/templates/visuals/default/capabilities.json +2 -7
  20. package/templates/visuals/default/package.json +2 -2
  21. package/templates/visuals/default/pbiviz.json +1 -1
  22. package/templates/visuals/default/src/settings.ts +54 -3
  23. package/templates/visuals/default/src/visual.ts +14 -17
  24. package/templates/visuals/rhtml/capabilities.json +2 -1
  25. package/templates/visuals/rhtml/package.json +2 -2
  26. package/templates/visuals/rhtml/pbiviz.json +1 -1
  27. package/templates/visuals/rhtml/src/settings.ts +28 -3
  28. package/templates/visuals/rhtml/src/visual.ts +29 -23
  29. package/templates/visuals/rvisual/capabilities.json +2 -1
  30. package/templates/visuals/rvisual/package.json +2 -2
  31. package/templates/visuals/rvisual/pbiviz.json +1 -1
  32. package/templates/visuals/rvisual/src/settings.ts +28 -3
  33. package/templates/visuals/rvisual/src/visual.ts +13 -15
  34. package/templates/visuals/slicer/capabilities.json +2 -1
  35. package/templates/visuals/slicer/package.json +2 -2
  36. package/templates/visuals/slicer/pbiviz.json +1 -1
  37. package/templates/visuals/slicer/src/settings.ts +29 -3
  38. package/templates/visuals/slicer/src/visual.ts +14 -17
  39. package/templates/visuals/table/capabilities.json +2 -1
  40. package/templates/visuals/table/package.json +2 -2
  41. package/templates/visuals/table/pbiviz.json +1 -1
  42. package/templates/visuals/table/src/settings.ts +23 -3
  43. package/templates/visuals/table/src/visual.ts +18 -16
  44. package/.eslintrc.json +0 -313
  45. package/.gitattributes +0 -4
  46. package/.github/workflows/build.yml +0 -32
  47. package/.github/workflows/codeql-analysis.yml +0 -54
  48. package/.snyk +0 -4
  49. package/.vscode/launch.json +0 -74
  50. package/.vscode/settings.json +0 -3
package/Changelog.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  This page contains information about changes to the PowerBI Visual Tools (pbiviz).
4
4
 
5
+ ## 4.0.6
6
+ Update templates visuals to:
7
+ * Support new visuals-api version 5.1.0
8
+ * Replace `enumerateObjectInstances` by `getFormattingModel` API
9
+ * Import and use `powerbi-visuals-utils-formattingmodel`
10
+
11
+ ## 4.0.5
12
+ * Updated dependencies, fixed npm audit issues
5
13
  ## 4.0.3 - 4.0.4
6
14
  ### **⚠ BREAKING CHANGES**
7
15
  * Removed polyfills and 'Internet Explorer` browser support
@@ -0,0 +1,28 @@
1
+ -----BEGIN PRIVATE KEY-----
2
+ MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC5mklx3Q18S0J1
3
+ WN3Th5riawccYs060HO5hAZjUyAaB9Tl7GPUCNiKqOYVYkorgOg8xZzBQUFMexvB
4
+ 7jjSImev+RCyW5CT/Ssg6uDgza6tTFTYkLtA9eT48mGmk+nhbZxOjdFJ4Msj00MY
5
+ luxSYuhnnj2i+szBvT83+6gnHPVahVLoshSZgL+QMYTZ1p5QK6lw/yYCX5P4Cja2
6
+ Ei6RfKTKK5BLSFTxskg88Kza4DdH6Cf8R6ecTUCLvQ8LEfT3bJc8fXLnrGYwr+R/
7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wYDVR0jBBgwFoAUYJZtzb9sVfhg4MbB
12
+ imIX4S59EgAwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAcaAW
13
+ CHtfOXSXOwhSvvZVXciYlkFGa7TBvetFlPAwpcx0iyp/xkagyhlBqmzM8gUA6+1y
14
+ 40WIJVCLKObBrHeV/3JM/7VEwRnua9LWDTraYYLd5yQ/eGhdeUIOvtBRWV0TCHmq
15
+ 2ArLPov4dAsYJkp5WNQNChg2IPizxEuEjJk+SAafZh7ZXJcyF3bUik5Nz2tX0O+h
16
+ 35BP/DVD3HqT9Ve0Em86Pd5tbGYdz0OQ9XteS5YG7wfe9XmKFOUp2Xwgv4joAFe5
17
+ ysD+MpqokkgMXjjmNcj75H1yKs3FmvkT4nGWthvWAC5J+CIgvitKf7Vp7YcGtDUP
18
+ +dMag6GYu0DoWVYElA==
19
+ -----END CERTIFICATE-----
package/config.json CHANGED
@@ -1 +1,35 @@
1
- {"templates":{"visuals":"templates/visuals","pbiviz":"templates/pbiviz.json.template","plugin":"templates/plugin.ts.template","package":"templates/package.json.template"},"generate":{"apiVersion":"3.8.0"},"constants":{"minAPIversion":"3.2.0"},"build":{"precompileFolder":".tmp/precompile","dropFolder":".tmp/drop","js":"tmp.visual.js","css":"visual.css","stats":"../../webpack.statistics.html"},"package":{"dropFolder":"dist"},"server":{"root":"webRoot","assetsRoute":"/assets","privateKey":"certs/PowerBICustomVisualTest_private.key","certificate":"certs/PowerBICustomVisualTest_public.crt","pfx":"certs/PowerBICustomVisualTest_public.pfx","port":"8080","passphrase":"9065569868692609"},"visualTemplates":{"circlecard":"https://codeload.github.com/microsoft/powerbi-visuals-circlecard-react/zip/master"}}
1
+ {
2
+ "templates": {
3
+ "visuals": "templates/visuals",
4
+ "pbiviz": "templates/pbiviz.json.template",
5
+ "plugin": "templates/plugin.ts.template",
6
+ "package": "templates/package.json.template"
7
+ },
8
+ "generate": {
9
+ "apiVersion": "3.8.0"
10
+ },
11
+ "constants": {
12
+ "minAPIversion": "3.2.0"
13
+ },
14
+ "build": {
15
+ "precompileFolder": ".tmp/precompile",
16
+ "dropFolder": ".tmp/drop",
17
+ "js": "tmp.visual.js",
18
+ "css": "visual.css",
19
+ "stats": "../../webpack.statistics.html"
20
+ },
21
+ "package": {
22
+ "dropFolder": "dist"
23
+ },
24
+ "server": {
25
+ "root": "webRoot",
26
+ "assetsRoute": "/assets",
27
+ "privateKey": "certs/PowerBICustomVisualTest_private.key",
28
+ "certificate": "certs/PowerBICustomVisualTest_public.crt",
29
+ "pfx": "certs/PowerBICustomVisualTest_public.pfx",
30
+ "port": "8080"
31
+ },
32
+ "visualTemplates": {
33
+ "circlecard": "https://codeload.github.com/microsoft/powerbi-visuals-circlecard-react/zip/master"
34
+ }
35
+ }
@@ -122,101 +122,7 @@ function copyVisualTemplate(targetPath, templateName) {
122
122
  fs.copySync(path.join(VISUAL_TEMPLATES_PATH, '_global'), targetPath);
123
123
  fs.copySync(path.join(VISUAL_TEMPLATES_PATH, templateName), targetPath);
124
124
  }
125
- /**
126
- * Generate settings.ts
127
- *
128
- * @param {string} targetPath - file path to root of visual package
129
- * @param {string} verbose - to verbose output
130
- */
131
- function generateSettings(targetPath, verbose) {
132
- let capabilitiesFileName = targetPath + '/capabilities.json';
133
-
134
- fs.readJson(capabilitiesFileName, (err, packageObj) => {
135
- if (err) {
136
- console.error(err);
137
- return;
138
- }
139
- if (verbose) {
140
- console.log('parse capabilities.json. Searching for settings');
141
- console.log(packageObj.dataRoles[0].displayName);
142
- }
143
- let VisualSettingsMethods = 'export class VisualSettings extends DataViewObjectsParser {\n';
144
- if (packageObj.objects) {
145
- let subClassesDefinitionArray = [];
146
- for (let settingsSubClass in packageObj.objects) {
147
- if (verbose) {
148
- console.log('Settings sub class: ' + settingsSubClass);
149
- }
150
- let subClassProperties = packageObj.objects[settingsSubClass].properties;
151
- VisualSettingsMethods += ' public ' + settingsSubClass + ': ' +
152
- settingsSubClass + 'Settings = new ' + settingsSubClass + 'Settings();\n';
153
-
154
- let settingsSubClassDefinition = '\n export class ' + settingsSubClass + 'Settings {\n';
155
-
156
- if (subClassProperties) {
157
- for (let property in subClassProperties) {
158
- if (verbose) {
159
- console.log('property: ' + subClassProperties[property].displayName);
160
- }
161
- let propertyType = subClassProperties[property].type;
162
- if (verbose) {
163
- console.log('prop type: ' + propertyType);
164
- }
165
- // add some spaghetti to this meals
166
- settingsSubClassDefinition += ' // ' + subClassProperties[property].displayName +
167
- '\n public ' + property;
168
125
 
169
- if (verbose) {
170
- console.log(propertyType.keys);
171
- }
172
- if (propertyType.bool) {
173
- if (verbose) {
174
- console.log('bool');
175
- }
176
- settingsSubClassDefinition += ': boolean = true;\n';
177
- } else if (propertyType.fill) {
178
- if (verbose) {
179
- console.log('fill');
180
- }
181
- settingsSubClassDefinition += ': string = "";\n';
182
- } else if (propertyType.formatting) {
183
- if (verbose) {
184
- console.log('formatting');
185
- }
186
- if (propertyType.formatting.fontSize) {
187
- settingsSubClassDefinition += ': number = 12;\n';
188
- }
189
- }
190
- }
191
- }
192
- settingsSubClassDefinition += ' }\n';
193
- subClassesDefinitionArray.push(settingsSubClassDefinition);
194
- }
195
- VisualSettingsMethods += ' }\n';
196
- // Add properties class per each setting
197
- for (let subDefinitions in subClassesDefinitionArray) {
198
- VisualSettingsMethods += subClassesDefinitionArray[subDefinitions];
199
- }
200
- if (verbose) {
201
- console.log('final text: ' + VisualSettingsMethods);
202
- }
203
-
204
- } else {
205
- if (verbose) {
206
- console.log('Settings not found');
207
- }
208
- VisualSettingsMethods += '// TODO: fill all visual settings here\n ' +
209
- '// public dataPoint: DataPointSettings = new DataPointSettings();\n }\n' +
210
- '// TODO: fill all visual settings here\n// export class DataPointSettings ' +
211
- '{ \n // public fill: string = "#005c55";\n// }';
212
- }
213
- // read file and update
214
- let settingsFileName = targetPath + '/src/settings.ts';
215
- let setingsFileContents = fs.readFileSync(settingsFileName, 'utf8');
216
- setingsFileContents = setingsFileContents.replace('<%= visualSettingsClasses %>', VisualSettingsMethods);
217
- fs.writeFileSync(settingsFileName, setingsFileContents);
218
- });
219
- }
220
126
  /**
221
127
  * Checks if the specified template is valid
222
128
  *
@@ -273,7 +179,6 @@ class VisualGenerator {
273
179
  fs.removeSync(visualPath);
274
180
  }
275
181
  copyVisualTemplate(visualPath, buildOptions.template);
276
- generateSettings(visualPath);
277
182
  createPbiVizJson(visualPath, visualOptions, options.template);
278
183
  resolve(visualPath);
279
184
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powerbi-visuals-tools",
3
- "version": "4.0.4",
3
+ "version": "4.0.6",
4
4
  "description": "Command line tool for creating and publishing visuals for Power BI",
5
5
  "main": "./lib/VisualPackage.js",
6
6
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "homepage": "https://github.com/Microsoft/PowerBI-visuals-tools#readme",
28
28
  "dependencies": {
29
29
  "assert": "^2.0.0",
30
- "async": "3.2.0",
30
+ "async": "^3.2.3",
31
31
  "base64-inline-loader": "^2.0.1",
32
32
  "browserify-zlib": "^0.2.0",
33
33
  "buffer": "^6.0.3",
@@ -71,7 +71,7 @@
71
71
  "vm-browserify": "^1.1.2",
72
72
  "webpack": "^5.51.1",
73
73
  "webpack-bundle-analyzer": "4.4.2",
74
- "webpack-dev-server": "^4.1.0"
74
+ "webpack-dev-server": "^4.8.1"
75
75
  },
76
76
  "devDependencies": {
77
77
  "eslint": "^7.31.0",
package/spec/.jshintrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "esversion": 6,
3
+ "node": true,
4
+ "jasmine": true
5
+ }
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ let FileSystem = require('./helpers/FileSystem.js');
30
+
31
+ FileSystem.deleteTempDirectory();
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ let fs = require('fs-extra');
30
+ let path = require('path');
31
+ console.log(__dirname);
32
+ let config = require('./../../config.json');
33
+
34
+ let CertificateTools = require('./../../lib/CertificateTools');
35
+
36
+ describe("E2E - pbiviz --install-cert", () => {
37
+ beforeEach((done) => {
38
+ CertificateTools.createCertFile(config, false).then(done);
39
+ });
40
+
41
+ describe("pbiviz", () => {
42
+ it("pbiviz --install-cert command should generate certificate", (done) => {
43
+ let certPath = path.join(__dirname, "../../", config.server.certificate);
44
+ let keyPath = path.join(__dirname, "../../", config.server.privateKey);
45
+ let pfxPath = path.join(__dirname, "../../", config.server.pfx);
46
+ let certExists = fs.existsSync(certPath);
47
+ let keyExists = fs.existsSync(keyPath);
48
+ let pfxExists = fs.existsSync(pfxPath);
49
+
50
+ let result = (certExists && keyExists) || pfxExists;
51
+
52
+ expect(result).toBeTruthy();
53
+ done();
54
+ });
55
+ });
56
+ });
@@ -0,0 +1,82 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ const fs = require('fs-extra');
30
+ const path = require('path');
31
+
32
+ const FileSystem = require('../helpers/FileSystem.js');
33
+
34
+ const tempPath = FileSystem.getTempPath();
35
+ const startPath = process.cwd();
36
+ const writeMetadata = require("./utils").writeMetadata;
37
+
38
+ describe("E2E - pbiviz info", () => {
39
+
40
+ const visualName = 'myuniquevisualnamegoeshere';
41
+ const visualPath = path.join(tempPath, visualName);
42
+
43
+ beforeEach(() => {
44
+ FileSystem.resetTempDirectory();
45
+ process.chdir(tempPath);
46
+ FileSystem.runPbiviz('new', visualName);
47
+ process.chdir(visualPath);
48
+
49
+ writeMetadata(visualPath);
50
+ });
51
+
52
+ afterEach(() => {
53
+ process.chdir(startPath);
54
+ });
55
+
56
+ afterAll(() => {
57
+ process.chdir(startPath);
58
+ FileSystem.deleteTempDirectory();
59
+ });
60
+
61
+ it("Should throw error if not in the visual root", () => {
62
+ let error;
63
+ process.chdir(tempPath);
64
+
65
+ try {
66
+ FileSystem.runPbiviz('info');
67
+ } catch (e) {
68
+ error = e;
69
+ }
70
+
71
+ expect(error).toBeDefined();
72
+ expect(error.status).toBe(1);
73
+ expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
74
+ });
75
+
76
+ it("Should output visual info", () => {
77
+ const output = FileSystem.runPbiviz('info').toString();
78
+ const visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
79
+ expect(output).toContain(visualName);
80
+ expect(output).toContain(visualConfig.guid);
81
+ });
82
+ });
@@ -0,0 +1,265 @@
1
+ /*
2
+ * Power BI Visual CLI
3
+ *
4
+ * Copyright (c) Microsoft Corporation
5
+ * All rights reserved.
6
+ * MIT License
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the ""Software""), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+
27
+ "use strict";
28
+
29
+ const fs = require('fs-extra');
30
+ const path = require('path');
31
+ const fsPromises = require("fs").promises;
32
+ const utils = require('./utils');
33
+
34
+ const FileSystem = require('../helpers/FileSystem.js');
35
+ const writeMetadata = require("./utils").writeMetadata;
36
+ const download = require("../../lib/utils").download;
37
+ const createFolder = require("../../lib/utils").createFolder;
38
+ const config = require("../../config.json");
39
+
40
+ const tempPath = FileSystem.getTempPath();
41
+ const templatePath = FileSystem.getTemplatePath();
42
+ const startPath = process.cwd();
43
+
44
+ describe("E2E - pbiviz new", () => {
45
+
46
+ beforeEach(() => {
47
+ FileSystem.resetTempDirectory();
48
+ process.chdir(tempPath);
49
+ });
50
+
51
+ afterEach(() => {
52
+ process.chdir(startPath);
53
+ });
54
+
55
+ afterAll(() => {
56
+ process.chdir(startPath);
57
+ FileSystem.deleteTempDirectory();
58
+ });
59
+
60
+ it("Should generate new visual with default template", () => {
61
+ let visualName = 'visualname';
62
+ let template = 'default';
63
+ let visualPath = path.join(tempPath, visualName);
64
+
65
+ FileSystem.runPbiviz('new', visualName, ' -t default');
66
+
67
+ writeMetadata(visualPath);
68
+
69
+ //check base dir
70
+ let stat = fs.statSync(visualPath);
71
+ expect(stat.isDirectory()).toBe(true);
72
+
73
+ //check contents
74
+ let expectedFiles = utils.readdirSyncRecursive(path.join(templatePath, 'visuals', template));
75
+ expectedFiles.concat(utils.readdirSyncRecursive(path.join(templatePath, 'visuals', '_global')));
76
+ expectedFiles.push('/pbiviz.json');
77
+ let visualFiles = utils.readdirSyncRecursive(visualPath);
78
+ let fileDiff = [expectedFiles, visualFiles].reduce((a, b) => a.filter(c => !b.includes(c)));
79
+ expect(fileDiff.length).toBe(0);
80
+
81
+ // check exists node_modules directory
82
+ let nodeModulesDirStat = fs.statSync(path.join(visualPath, "node_modules"));
83
+ expect(nodeModulesDirStat.isDirectory()).toBe(true);
84
+
85
+ //check pbiviz.json config file
86
+ let visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
87
+ expect(visualConfig.name).toBe(visualName);
88
+ expect(visualConfig.displayName).toBe(visualName);
89
+ expect(visualConfig.guid).toBeDefined();
90
+ expect(visualConfig.guid).toMatch(/^[a-zA-Z0-9]+$/g);
91
+ expect(visualConfig.guid.substr(0, visualName.length)).toBe(visualName);
92
+ });
93
+
94
+ describe(`Should download 'Circlecard' visual archive from the repo`, () => {
95
+ let template = 'circlecard';
96
+
97
+ it(`Verifiy size`, async () => {
98
+ const folder = createFolder(template);
99
+ const archiveSize = 49558;
100
+ const archiveName = path.join(folder, `${template}Archive.zip`);
101
+ await download(config.visualTemplates[template], archiveName);
102
+ const stats = await fsPromises.stat(archiveName);
103
+ await expect(stats.size).toBe(archiveSize);
104
+ await fsPromises.unlink(archiveName);
105
+ });
106
+
107
+ });
108
+
109
+ describe('Should generate new visual using specified template', () => {
110
+
111
+ it('table', () => {
112
+ const template = 'table';
113
+
114
+ testGeneratedVisualByTemplateName(template);
115
+ });
116
+
117
+ it('slicer', () => {
118
+ const template = 'slicer';
119
+
120
+ testGeneratedVisualByTemplateName(template);
121
+ });
122
+
123
+ it('rvisual', () => {
124
+ const template = 'rvisual';
125
+
126
+ testGeneratedVisualByTemplateName(template);
127
+ });
128
+
129
+ it('rhtml', () => {
130
+ const template = 'rhtml';
131
+
132
+ testGeneratedVisualByTemplateName(template);
133
+ });
134
+
135
+ it('circlecard', () => {
136
+ const template = 'circlecard';
137
+
138
+ testGeneratedVisualByTemplateName(template);
139
+ });
140
+
141
+ function testGeneratedVisualByTemplateName(template) {
142
+ let visualName = 'visualname',
143
+ visualPath = path.join(tempPath, visualName);
144
+
145
+ FileSystem.runPbiviz('new', visualName, `--template ${template}`);
146
+ if (template !== 'circlecard') {
147
+ FileSystem.runCMDCommand('npm i', visualPath, startPath);
148
+ }
149
+
150
+ //check base dir exists
151
+ let stat = fs.statSync(visualPath);
152
+ expect(stat.isDirectory()).toBe(true);
153
+
154
+ //read pbiviz json generated in visual
155
+ let pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
156
+
157
+ //check pbiviz.json config file
158
+ let visualConfig = pbivizJson.visual;
159
+ if (template === 'circlecard') {
160
+ expect(visualConfig.name).toBe('reactCircleCard');
161
+ expect(visualConfig.displayName).toBe('ReactCircleCard');
162
+ } else {
163
+ expect(visualConfig.name).toBe(visualName);
164
+ expect(visualConfig.displayName).toBe(visualName);
165
+ }
166
+ expect(visualConfig.guid).toBeDefined();
167
+ expect(visualConfig.guid).toMatch(/^[a-zA-Z0-9]+$/g);
168
+ expect(visualConfig.guid.substr(0, visualName.length)).toBe(visualName);
169
+ }
170
+ });
171
+
172
+ it("Should convert multi-word visual name to camelCase", () => {
173
+ let visualDisplayName = 'My Visual Name here';
174
+ let visualName = 'myVisualNameHere';
175
+ FileSystem.runPbiviz('new', visualDisplayName);
176
+
177
+ let visualPath = path.join(tempPath, visualName);
178
+ let stat = fs.statSync(visualPath);
179
+ expect(stat.isDirectory()).toBe(true);
180
+
181
+ let visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
182
+ expect(visualConfig.name).toBe(visualName);
183
+ expect(visualConfig.displayName).toBe(visualDisplayName);
184
+ });
185
+
186
+ it("Should throw error if the visual name invalid", () => {
187
+ let invalidVisualName = '12test';
188
+ let error;
189
+ try {
190
+ FileSystem.runPbiviz('new', invalidVisualName);
191
+ }
192
+ catch (e) {
193
+ error = e;
194
+ }
195
+ expect(error.message).toMatch("The visual name can't begin with a number digit");
196
+
197
+ invalidVisualName = '\u200c';
198
+ try {
199
+ FileSystem.runPbiviz('new', invalidVisualName);
200
+ }
201
+ catch (e) {
202
+ error = e;
203
+ }
204
+ expect(error.message).toMatch("The visual name can contain only letters and numbers");
205
+
206
+ invalidVisualName = 'do';
207
+ try {
208
+ FileSystem.runPbiviz('new', invalidVisualName);
209
+ }
210
+ catch (e) {
211
+ error = e;
212
+ }
213
+ expect(error.message).toMatch("The visual name cannot be equal to a reserved JavaScript keyword");
214
+
215
+ });
216
+
217
+ it("Should throw error if the visual already exists", () => {
218
+ let visualName = 'visualname';
219
+ let error;
220
+
221
+ FileSystem.runPbiviz('new', visualName);
222
+
223
+ try {
224
+ FileSystem.runPbiviz('new', visualName);
225
+ } catch (e) {
226
+ error = e;
227
+ }
228
+
229
+ expect(error).toBeDefined();
230
+ expect(error.status).toBe(1);
231
+ });
232
+
233
+ it("Should overwrite existing visual with force flag", () => {
234
+ let visualName = 'visualname';
235
+ let visualPath = path.join(tempPath, visualName);
236
+ let visualTestFilePath = path.join(visualPath, 'testFile.txt');
237
+ let visualNewError, testFileError1, testFileError2;
238
+
239
+ FileSystem.runPbiviz('new', visualName);
240
+ fs.writeFileSync(visualTestFilePath, 'hello!!');
241
+
242
+ try {
243
+ fs.statSync(visualTestFilePath);
244
+ } catch (e) {
245
+ testFileError1 = e;
246
+ }
247
+
248
+ try {
249
+ FileSystem.runPbiviz('new', visualName, '-f');
250
+ } catch (e) {
251
+ visualNewError = e;
252
+ }
253
+
254
+ try {
255
+ fs.statSync(visualTestFilePath);
256
+ } catch (e) {
257
+ testFileError2 = e;
258
+ }
259
+
260
+ expect(visualNewError).not.toBeDefined();
261
+ expect(testFileError1).not.toBeDefined();
262
+ expect(testFileError2).toBeDefined();
263
+ expect(testFileError2.code).toBe('ENOENT');
264
+ });
265
+ });