powerbi-visuals-tools 4.0.5 → 4.0.7
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.
- package/Changelog.md +11 -0
- package/bin/pbiviz-start.js +3 -1
- package/certs/PowerBICustomVisualTest_private.key +28 -0
- package/certs/PowerBICustomVisualTest_public.crt +19 -0
- package/config.json +35 -1
- package/lib/VisualGenerator.js +0 -95
- package/package.json +19 -16
- package/spec/.jshintrc +5 -0
- package/spec/clean-tests.js +31 -0
- package/spec/e2e/pbivizCertSpec.js +56 -0
- package/spec/e2e/pbivizInfoSpec.js +82 -0
- package/spec/e2e/pbivizNewSpec.js +265 -0
- package/spec/e2e/pbivizPackageSpec.js +670 -0
- package/spec/e2e/pbivizStartSpec.js +380 -0
- package/spec/e2e/pbivizWebpackVerSpec.js +102 -0
- package/spec/e2e/utils.js +63 -0
- package/spec/helpers/FileSystem.js +173 -0
- package/spec/jasmine-runner.js +36 -0
- package/spec/support/jasmine.json +11 -0
- package/templates/visuals/default/capabilities.json +2 -7
- package/templates/visuals/default/package.json +2 -2
- package/templates/visuals/default/pbiviz.json +1 -1
- package/templates/visuals/default/src/settings.ts +54 -3
- package/templates/visuals/default/src/visual.ts +14 -17
- package/templates/visuals/rhtml/capabilities.json +2 -1
- package/templates/visuals/rhtml/package.json +2 -2
- package/templates/visuals/rhtml/pbiviz.json +1 -1
- package/templates/visuals/rhtml/src/settings.ts +28 -3
- package/templates/visuals/rhtml/src/visual.ts +29 -23
- package/templates/visuals/rvisual/capabilities.json +2 -1
- package/templates/visuals/rvisual/package.json +2 -2
- package/templates/visuals/rvisual/pbiviz.json +1 -1
- package/templates/visuals/rvisual/src/settings.ts +28 -3
- package/templates/visuals/rvisual/src/visual.ts +13 -15
- package/templates/visuals/slicer/capabilities.json +2 -1
- package/templates/visuals/slicer/package.json +2 -2
- package/templates/visuals/slicer/pbiviz.json +1 -1
- package/templates/visuals/slicer/src/settings.ts +29 -3
- package/templates/visuals/slicer/src/visual.ts +14 -17
- package/templates/visuals/table/capabilities.json +2 -1
- package/templates/visuals/table/package.json +2 -2
- package/templates/visuals/table/pbiviz.json +1 -1
- package/templates/visuals/table/src/settings.ts +23 -3
- package/templates/visuals/table/src/visual.ts +18 -16
- package/.eslintrc.json +0 -313
- package/.gitattributes +0 -4
- package/.github/workflows/build.yml +0 -32
- package/.github/workflows/codeql-analysis.yml +0 -54
- package/.snyk +0 -4
- package/.vscode/launch.json +0 -74
- package/.vscode/settings.json +0 -3
|
@@ -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
|
+
});
|