powerbi-visuals-tools 5.0.1 → 5.0.3

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.
@@ -1,406 +0,0 @@
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
- import fs from 'fs-extra';
30
- import path from 'path';
31
- import async from 'async';
32
- import FileSystem from '../helpers/FileSystem.js';
33
- import { writeMetadata } from "./testUtils.js";
34
- import { download, createFolder } from "../../lib/utils.js";
35
-
36
- const tempPath = FileSystem.getTempPath();
37
- const startPath = process.cwd();
38
-
39
- // these tests can take a bit longer
40
- jasmine.DEFAULT_TIMEOUT_INTERVAL = 180000;
41
-
42
- let startChecker = (proc) => new Promise((resolve) => {
43
- proc.stdout.on('data', (data) => {
44
- let dataStr = (data.toString()).toLowerCase();
45
- if ((dataStr.indexOf("compiled") !== -1 && dataStr.indexOf("successfully") !== -1) || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
46
- resolve();
47
- }
48
- });
49
- });
50
-
51
- let procKiller = (proc, done) => {
52
- FileSystem.killProcess(proc, 'SIGTERM', (error) => {
53
- expect(error).toBeNull();
54
- done();
55
- });
56
- };
57
-
58
- describe("E2E - pbiviz start", () => {
59
- const visualName = 'visualname';
60
- const visualPath = path.join(tempPath, visualName);
61
- const tmpPath = path.join(visualPath, '.tmp');
62
- const dropPath = path.join(tmpPath, 'drop');
63
- const assetFiles = ['visual.js', 'visual.css', 'pbiviz.json', 'status'];
64
-
65
- beforeEach(() => {
66
- FileSystem.resetTempDirectory();
67
- process.chdir(tempPath);
68
- FileSystem.runPbiviz('new', visualName, '--force');
69
- FileSystem.runCMDCommand('npm i', visualPath, tempPath);
70
-
71
- writeMetadata(visualPath);
72
- });
73
-
74
- afterEach(() => {
75
- process.chdir(startPath);
76
- });
77
-
78
- afterAll(() => {
79
- process.chdir(startPath);
80
- FileSystem.deleteTempDirectory();
81
- });
82
-
83
- xit("Should throw error if not in the visual root", () => {
84
- let error;
85
-
86
- try {
87
- FileSystem.runPbiviz('start', "-d");
88
- } catch (e) {
89
- error = e;
90
- }
91
- expect(error).toBeDefined();
92
- expect(error.status).toBe(1);
93
- expect(error.message).toContain("Error: pbiviz.json not found. You must be in the root of a visual project to run this command");
94
- });
95
-
96
- it("Should generate statistic files without flags", (done) => {
97
- process.chdir(visualPath);
98
- const pbivizProc = FileSystem.runPbivizAsync('start');
99
- startChecker(pbivizProc).then(() => {
100
- const statisticFilePath = path.join(visualPath, 'webpack.statistics.dev.html');
101
- try {
102
- expect(fs.statSync(statisticFilePath).isFile()).toBe(true);
103
- } catch (error) {
104
- expect(error).toBeNull();
105
- }
106
- procKiller(pbivizProc, done);
107
- });
108
- });
109
-
110
- it("Shouldn't generate statistic files with --no-stats flag", (done) => {
111
- process.chdir(visualPath);
112
- const pbivizProc = FileSystem.runPbivizAsync('start', '--no-stats');
113
- startChecker(pbivizProc).then(() => {
114
- const statisticFilePath = path.join(visualPath, 'webpack.statistics.dev.html');
115
- try {
116
- fs.statSync(statisticFilePath).isFile();
117
- } catch (error) {
118
- expect(error).not.toBeNull();
119
- }
120
- procKiller(pbivizProc, done);
121
- });
122
- });
123
-
124
- describe("Build and Server", () => {
125
- let pbivizProc;
126
-
127
- beforeEach(() => {
128
- process.chdir(visualPath);
129
- pbivizProc = FileSystem.runPbivizAsync("start", "-d");
130
- });
131
-
132
- it("Should build visual and generate resources in drop folder", (done) => {
133
- let visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
134
- let visualCapabilities = fs.readJsonSync(path.join(visualPath, 'capabilities.json'));
135
- startChecker(pbivizProc).then(() => {
136
- //check files on filesystem
137
- expect(fs.statSync(dropPath).isDirectory()).toBe(true);
138
- try {
139
- assetFiles.forEach(file => {
140
- let filePath = path.join(dropPath, file);
141
- expect(fs.statSync(filePath).isFile()).toBe(true);
142
- });
143
- } catch (error) {
144
- expect(error).toBeNull();
145
- }
146
- //check metadata
147
- let pbivizPath = path.join(dropPath, 'pbiviz.json');
148
- let pbiviz = fs.readJsonSync(pbivizPath);
149
- //should append "_DEBUG" to guid to avoid collisions
150
- visualConfig.guid += "_DEBUG";
151
- expect(pbiviz.visual).toEqual(visualConfig);
152
- expect(pbiviz.capabilities).toEqual(visualCapabilities);
153
- expect(pbiviz.content.js).toBeDefined();
154
- expect(pbiviz.content.css).toBeDefined();
155
- expect(pbiviz.content.iconBase64).toBeDefined();
156
- procKiller(pbivizProc, done);
157
- });
158
- });
159
-
160
- it("Should serve files from drop folder on port 8080", (done) => {
161
- startChecker(pbivizProc).then(() => {
162
- async.each(
163
- assetFiles,
164
- (file, next) => {
165
- let errorMessage = `error in request to "${file}" response,`;
166
- let filePath = path.join(dropPath, file);
167
- let testFolder = createFolder("./testFolder");
168
- let testFile = path.join(testFolder, file);
169
- const options = {
170
- host: 'localhost',
171
- hostname: 'localhost',
172
- port: 8080,
173
- path: '/assets/' + file,
174
- method: 'GET',
175
- rejectUnauthorized: false
176
- };
177
-
178
- download(options, testFile)
179
- .then(() => {
180
- let downloadedBody = fs.existsSync(testFile) ? fs.readFileSync(testFile).toString() : null;
181
- let comparisonBody = fs.existsSync(filePath) ? fs.readFileSync(filePath).toString() : null;
182
- expect(downloadedBody).withContext(`${errorMessage} body`).toBe(comparisonBody);
183
- next();
184
- })
185
- .catch((error) => {
186
- expect(error).toBeNull();
187
- next(`request to "${file}" error.`);
188
- });
189
- },
190
- error => {
191
- if (error) {
192
- procKiller(pbivizProc, done);
193
- } else {
194
- procKiller(pbivizProc, done);
195
- }
196
- }
197
- );
198
- });
199
- });
200
-
201
-
202
- // TODO rewrite this UT because build sequence is different
203
- xit("Should rebuild files on change and update status", (done) => {
204
- let statusPath = path.join(dropPath, 'status');
205
- let lastStatus;
206
- let tsChangeCount = 0;
207
- let lessChangeCount = 0;
208
- let jsonChangeCount = 0;
209
-
210
- function getStatus() {
211
- return fs.readFileSync(statusPath);
212
- }
213
-
214
- let callbackCalled = false;
215
- pbivizProc.stdout.on('data', (data) => {
216
- let dataStr = data.toString();
217
- if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
218
- if (callbackCalled) {
219
- return;
220
- }
221
- callbackCalled = true;
222
- expect(tsChangeCount).toBe(0);
223
- expect(lessChangeCount).toBe(0);
224
- expect(jsonChangeCount).toBe(0);
225
- lastStatus = getStatus();
226
-
227
- //trigger ts change
228
- let tsSrcPath = path.join(visualPath, 'src/visual.ts');
229
- fs.appendFileSync(tsSrcPath, '// appended to ts file');
230
- }
231
-
232
- if (dataStr.indexOf('Visual rebuild completed') !== -1) {
233
- tsChangeCount++;
234
- expect(tsChangeCount).toBe(1);
235
- expect(lessChangeCount).toBe(0);
236
- expect(jsonChangeCount).toBe(0);
237
- let status = getStatus();
238
- expect(status).not.toBe(lastStatus);
239
- lastStatus = status;
240
-
241
- //trigger less change
242
- let lessSrcPath = path.join(visualPath, 'style/visual.less');
243
- fs.appendFileSync(lessSrcPath, '/* appended to less file */');
244
- }
245
-
246
- if (dataStr.indexOf('Less build complete') !== -1) {
247
- lessChangeCount++;
248
- expect(tsChangeCount).toBe(1);
249
- expect(lessChangeCount).toBe(1);
250
- expect(jsonChangeCount).toBe(0);
251
- let status = getStatus();
252
- expect(status).not.toBe(lastStatus);
253
- lastStatus = status;
254
-
255
- //trigger json change
256
- let capabilitiesPath = path.join(visualPath, 'capabilities.json');
257
- let visualCapabilities = fs.readJsonSync(capabilitiesPath);
258
- visualCapabilities.dataRoles.pop();
259
- fs.writeJsonSync(capabilitiesPath, visualCapabilities);
260
- }
261
-
262
- if (dataStr.indexOf('JSON build complete') !== -1) {
263
- jsonChangeCount++;
264
- expect(tsChangeCount).toBe(1);
265
- expect(lessChangeCount).toBe(1);
266
- expect(jsonChangeCount).toBe(1);
267
- let status = getStatus();
268
- expect(status).not.toBe(lastStatus);
269
- lastStatus = status;
270
-
271
- //the end
272
- FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
273
- expect(error).toBeNull();
274
- done();
275
- });
276
- }
277
- });
278
- });
279
- });
280
-
281
- // custom port wans't implemented in new tools
282
- xit("Should serve files from drop folder on custom port with -p flag", (done) => {
283
- process.chdir(visualPath);
284
- let pbivizProc = FileSystem.runPbivizAsync('start', ['-p', '3333']);
285
- pbivizProc.stderr.on('data', (data) => {
286
- if (data.toString().indexOf("DeprecationWarning") === -1) {
287
- throw new Error(data.toString());
288
- }
289
- });
290
- let callbackCalled = false;
291
- pbivizProc.stdout.on('data', (data) => {
292
- let dataStr = data.toString();
293
-
294
- if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
295
- if (callbackCalled) {
296
- return;
297
- }
298
- callbackCalled = true;
299
- async.each(
300
- assetFiles,
301
- (file, next) => {
302
- let filePath = path.join(dropPath, file);
303
- request({
304
- url: 'https://localhost:3333/assets/' + file,
305
- //allow self signed cert
306
- strictSSL: false
307
- }, (error, response, body) => {
308
- expect(error).toBeNull();
309
- expect(response.statusCode).toBe(200);
310
- expect(body).toBe(fs.readFileSync(filePath).toString());
311
- next();
312
- });
313
- },
314
- error => {
315
- if (error) { throw error; }
316
- FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
317
- expect(error).toBeNull();
318
- done();
319
- });
320
- }
321
- );
322
-
323
- }
324
- });
325
- });
326
-
327
- });
328
-
329
- describe("E2E - pbiviz start for R Visuals", () => {
330
-
331
- let visualName = 'visualname';
332
- let visualPath = path.join(tempPath, visualName);
333
- let dropPath = path.join(visualPath, '.tmp', 'drop');
334
-
335
- beforeEach(() => {
336
- FileSystem.resetTempDirectory();
337
- process.chdir(tempPath);
338
- FileSystem.runPbiviz('new', visualName, '--template rvisual');
339
- });
340
-
341
- afterEach(() => {
342
- process.chdir(startPath);
343
- });
344
-
345
- afterAll(() => {
346
- process.chdir(startPath);
347
- FileSystem.deleteTempDirectory();
348
- });
349
-
350
- // todo check R visuals build
351
- xdescribe("Build and Server for R Visuals", () => {
352
- let pbivizProc;
353
-
354
- beforeEach(() => {
355
- process.chdir(visualPath);
356
- FileSystem.runCMDCommand('npm i', visualPath);
357
- pbivizProc = FileSystem.runPbivizAsync('start');
358
- pbivizProc.stderr.on('data', (data) => {
359
- if (data.toString().indexOf("DeprecationWarning") === -1) {
360
- throw new Error(data.toString());
361
- }
362
- });
363
- });
364
-
365
- it("Should rebuild files on change and update status for R Visuals", (done) => {
366
- let statusPath = path.join(dropPath, 'status');
367
- let lastStatus;
368
- let rChangeCount = 0;
369
-
370
- function getStatus() {
371
- return fs.readFileSync(statusPath);
372
- }
373
-
374
- let callbackCalled = false;
375
- pbivizProc.stdout.on('data', (data) => {
376
- let dataStr = data.toString();
377
- if (dataStr.indexOf("Compiled successfully") !== -1 || dataStr.match(/Compiled with\s*(\d)* warnings/) !== null) {
378
- if (callbackCalled) {
379
- return;
380
- }
381
- callbackCalled = true;
382
- expect(rChangeCount).toBe(0);
383
- lastStatus = getStatus();
384
-
385
- //trigger r change
386
- let rScriptPath = path.join(visualPath, 'script.r');
387
- fs.appendFileSync(rScriptPath, '// appended to R file');
388
- }
389
-
390
- if (dataStr.indexOf('RScript build complete') !== -1) {
391
- rChangeCount++;
392
- expect(rChangeCount).toBe(1);
393
- let status = getStatus();
394
- expect(status).not.toBe(lastStatus);
395
- lastStatus = status;
396
-
397
- //the end
398
- FileSystem.killProcess(pbivizProc, 'SIGTERM', (error) => {
399
- expect(error).toBeNull();
400
- done();
401
- });
402
- }
403
- });
404
- });
405
- });
406
- });
@@ -1,100 +0,0 @@
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
- import fs from 'fs-extra';
30
- import path from 'path';
31
- import semver from 'semver';
32
- import FileSystem from '../helpers/FileSystem.js';
33
- import { writeMetadata } from "./testUtils.js";
34
-
35
- const tempPath = FileSystem.getTempPath();
36
- const startPath = process.cwd();
37
- const visualName = 'visualname';
38
- const visualPath = path.join(tempPath, visualName);
39
-
40
- describe("E2E - webpack tools", () => {
41
- beforeEach(() => {
42
- FileSystem.resetTempDirectory();
43
- process.chdir(tempPath);
44
- FileSystem.runPbiviz('new', visualName, ' -t default --force');
45
- process.chdir(visualPath);
46
-
47
- writeMetadata(visualPath);
48
- });
49
-
50
- afterEach(() => {
51
- process.chdir(startPath);
52
- });
53
-
54
- afterAll(() => {
55
- process.chdir(startPath);
56
- FileSystem.deleteTempDirectory();
57
- });
58
-
59
- const removeApi = () => {
60
- const packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
61
- delete packageJson.dependencies["powerbi-visuals-api"];
62
-
63
- fs.writeJsonSync(path.join(visualPath, 'package.json'), packageJson);
64
-
65
- fs.removeSync(path.join(visualPath, "node_modules", "powerbi-visuals-api"));
66
- };
67
-
68
- it("Should not add empty dependencies option into visual config", () => {
69
- FileSystem.runPbiviz('package');
70
-
71
- const packageJson = fs.readJsonSync(path.join(visualPath, '.tmp/drop/pbiviz.json'));
72
- expect(packageJson.dependencies).not.toBeDefined();
73
- });
74
-
75
- it("Should install the latest powerbi-visual-api if apiVersion is undefined", () => {
76
- const pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
77
- pbivizJson.apiVersion = null;
78
- fs.writeJsonSync(path.join(visualPath, 'pbiviz.json'), pbivizJson);
79
-
80
- removeApi();
81
- FileSystem.runPbiviz('package');
82
-
83
- const packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
84
- expect(packageJson.dependencies["powerbi-visuals-api"]).toBeDefined();
85
- });
86
-
87
- it("Should install powerbi-visual-api with version from pbiviz.json on 'pbiviz start/package'", () => {
88
- const pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
89
- removeApi();
90
- FileSystem.runPbiviz('package');
91
-
92
- const packageJson = fs.readJsonSync(path.join(visualPath, 'package.json'));
93
- expect(packageJson.dependencies["powerbi-visuals-api"]).toBeDefined();
94
- expect(semver.major(pbivizJson.apiVersion))
95
- .toBe(semver.major(packageJson.dependencies["powerbi-visuals-api"].replace(/\^|\~/, ""))); // eslint-disable-line no-useless-escape
96
- expect(semver.minor(pbivizJson.apiVersion))
97
- .toBe(semver.minor(packageJson.dependencies["powerbi-visuals-api"].replace(/\^|\~/, ""))); // eslint-disable-line no-useless-escape
98
- });
99
-
100
- });
@@ -1,60 +0,0 @@
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
- import path from "path";
30
- import fs from 'fs-extra';
31
-
32
- export const readdirSyncRecursive = (baseDir) => {
33
- const read = (dir) => {
34
- let results = [];
35
- const list = fs.readdirSync(dir);
36
- list.forEach((file) => {
37
- file = dir + '/' + file;
38
- const stat = fs.statSync(file);
39
- if (stat && stat.isDirectory()) {
40
- /* Recurse into a subdirectory */
41
- results = results.concat(read(file));
42
- } else {
43
- /* Is a file */
44
- results.push(file.replace(baseDir, ""));
45
- }
46
- });
47
- return results;
48
- };
49
- return read(baseDir);
50
- };
51
-
52
- export const writeMetadata = (visualPath) => {
53
- const pbivizJSONFile = path.join(visualPath, '/pbiviz.json');
54
- const pbiviz = fs.readJSONSync(pbivizJSONFile);
55
- pbiviz.visual.description = "description";
56
- pbiviz.visual.supportUrl = "supportUrl";
57
- pbiviz.author.name = "Microsoft";
58
- pbiviz.author.email = "pbicvsupport";
59
- fs.writeJSONSync(pbivizJSONFile, pbiviz);
60
- };