powerbi-visuals-tools 5.0.0 → 5.0.2

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,253 +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 { promises as fsPromises } from "fs";
32
- import FileSystem from '../helpers/FileSystem.js';
33
- import { writeMetadata, readdirSyncRecursive } from "./testUtils.js";
34
- import { download, createFolder, readJsonFromRoot } from "../../lib/utils.js";
35
-
36
- const config = readJsonFromRoot('config.json');
37
- const tempPath = FileSystem.getTempPath();
38
- const templatePath = FileSystem.getTemplatePath();
39
- const startPath = process.cwd();
40
- const visualName = 'visualName';
41
- const visualPath = path.join(tempPath, visualName);
42
-
43
- describe("E2E - pbiviz new", () => {
44
-
45
- beforeEach(() => {
46
- FileSystem.resetTempDirectory();
47
- process.chdir(tempPath);
48
- });
49
-
50
- afterEach(() => {
51
- process.chdir(startPath);
52
- });
53
-
54
- afterAll(() => {
55
- FileSystem.deleteTempDirectory();
56
- });
57
-
58
- it("Should generate new visual with default template", () => {
59
- const template = 'default';
60
-
61
- FileSystem.runPbiviz('new', visualName, ' -t default');
62
-
63
- writeMetadata(visualPath);
64
-
65
- //check base dir
66
- const stat = fs.statSync(visualPath);
67
- expect(stat.isDirectory()).toBe(true);
68
-
69
- //check contents
70
- const expectedFiles = readdirSyncRecursive(path.join(templatePath, 'visuals', template));
71
- expectedFiles.concat(readdirSyncRecursive(path.join(templatePath, 'visuals', '_global')));
72
- expectedFiles.push('/pbiviz.json');
73
- const visualFiles = readdirSyncRecursive(visualPath);
74
- const fileDiff = [expectedFiles, visualFiles].reduce((a, b) => a.filter(c => !b.includes(c)));
75
- expect(fileDiff.length).toBe(0);
76
-
77
- // check exists node_modules directory
78
- const nodeModulesDirStat = fs.statSync(path.join(visualPath, "node_modules"));
79
- expect(nodeModulesDirStat.isDirectory()).toBe(true);
80
-
81
- //check pbiviz.json config file
82
- const visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
83
- expect(visualConfig.name).toBe(visualName);
84
- expect(visualConfig.displayName).toBe(visualName);
85
- expect(visualConfig.guid).toBeDefined();
86
- expect(visualConfig.guid).toMatch(/^[a-zA-Z0-9]+$/g);
87
- expect(visualConfig.guid.substr(0, visualName.length)).toBe(visualName);
88
- });
89
-
90
- describe(`Should download 'Circlecard' visual archive from the repo`, () => {
91
- const template = 'circlecard';
92
-
93
- it(`Verifiy size`, async () => {
94
- const folder = createFolder(template);
95
- const archiveSize = 10000;
96
- const archiveName = path.join(folder, `${template}Archive.zip`);
97
- await download(config.visualTemplates[template], archiveName);
98
- const stats = await fsPromises.stat(archiveName);
99
- await expect(stats.size).toBeGreaterThanOrEqual(archiveSize);
100
- await fsPromises.unlink(archiveName);
101
- });
102
-
103
- });
104
-
105
- describe('Should generate new visual using specified template', () => {
106
-
107
- function testGeneratedVisualByTemplateName(template) {
108
- FileSystem.runPbiviz('new', visualName, `--template ${template}`);
109
- if (template !== 'circlecard') {
110
- FileSystem.runCMDCommand('npm i', visualPath, startPath);
111
- }
112
-
113
- //check base dir exists
114
- const stat = fs.statSync(visualPath);
115
- expect(stat.isDirectory()).toBe(true);
116
-
117
- //read pbiviz json generated in visual
118
- const pbivizJson = fs.readJsonSync(path.join(visualPath, 'pbiviz.json'));
119
-
120
- //check pbiviz.json config file
121
- const visualConfig = pbivizJson.visual;
122
- if (template === 'circlecard') {
123
- expect(visualConfig.name).toBe('reactCircleCard');
124
- expect(visualConfig.displayName).toBe('ReactCircleCard');
125
- } else {
126
- expect(visualConfig.name).toBe(visualName);
127
- expect(visualConfig.displayName).toBe(visualName);
128
- }
129
- expect(visualConfig.guid).toBeDefined();
130
- expect(visualConfig.guid).toMatch(/^[a-zA-Z0-9]+$/g);
131
- expect(visualConfig.guid.substr(0, visualName.length)).toBe(visualName);
132
- }
133
-
134
- it('table', () => {
135
- const template = 'table';
136
-
137
- testGeneratedVisualByTemplateName(template);
138
- });
139
-
140
- it('slicer', () => {
141
- const template = 'slicer';
142
-
143
- testGeneratedVisualByTemplateName(template);
144
- });
145
-
146
- it('rvisual', () => {
147
- const template = 'rvisual';
148
-
149
- testGeneratedVisualByTemplateName(template);
150
- });
151
-
152
- it('rhtml', () => {
153
- const template = 'rhtml';
154
-
155
- testGeneratedVisualByTemplateName(template);
156
- });
157
-
158
- it('circlecard', () => {
159
- const template = 'circlecard';
160
-
161
- testGeneratedVisualByTemplateName(template);
162
- });
163
- });
164
-
165
- it("Should convert multi-word visual name to camelCase", () => {
166
- const visualDisplayName = 'Visual Name';
167
- FileSystem.runPbiviz('new', `"${visualDisplayName}"`);
168
-
169
- const stat = fs.statSync(visualPath);
170
- expect(stat.isDirectory()).toBe(true);
171
-
172
- const visualConfig = fs.readJsonSync(path.join(visualPath, 'pbiviz.json')).visual;
173
- expect(visualConfig.name).toBe(visualName);
174
- expect(visualConfig.displayName).toBe(visualDisplayName);
175
- });
176
-
177
- it("Should throw error if the visual name invalid", () => {
178
- let error;
179
- let invalidVisualName = '12test';
180
- try {
181
- FileSystem.runPbiviz('new', invalidVisualName);
182
- }
183
- catch (e) {
184
- error = e;
185
- }
186
- expect(error.message).toMatch("The visual name can't begin with a number digit");
187
-
188
- invalidVisualName = '\u200c';
189
- try {
190
- FileSystem.runPbiviz('new', invalidVisualName);
191
- }
192
- catch (e) {
193
- error = e;
194
- }
195
- expect(error.message).toMatch("The visual name can contain only letters and numbers");
196
-
197
- invalidVisualName = 'do';
198
- try {
199
- FileSystem.runPbiviz('new', invalidVisualName);
200
- }
201
- catch (e) {
202
- error = e;
203
- }
204
- expect(error.message).toMatch("The visual name cannot be equal to a reserved JavaScript keyword");
205
-
206
- });
207
-
208
- it("Should throw error if the visual already exists", () => {
209
- let error;
210
- FileSystem.runPbiviz('new', visualName);
211
-
212
- try {
213
- FileSystem.runPbiviz('new', visualName);
214
- } catch (e) {
215
- error = e;
216
- }
217
-
218
- expect(error).toBeDefined();
219
- expect(error.status).toBe(1);
220
-
221
- });
222
-
223
- it("Should overwrite existing visual with force flag", () => {
224
- const visualTestFilePath = path.join(visualPath, 'testFile.txt');
225
- let visualNewError, testFileError1, testFileError2;
226
-
227
- FileSystem.runPbiviz('new', visualName);
228
- fs.writeFileSync(visualTestFilePath, 'hello!!');
229
-
230
- try {
231
- fs.statSync(visualTestFilePath);
232
- } catch (e) {
233
- testFileError1 = e;
234
- }
235
-
236
- try {
237
- FileSystem.runPbiviz('new', visualName, '-f');
238
- } catch (e) {
239
- visualNewError = e;
240
- }
241
-
242
- try {
243
- fs.statSync(visualTestFilePath);
244
- } catch (e) {
245
- testFileError2 = e;
246
- }
247
-
248
- expect(visualNewError).not.toBeDefined();
249
- expect(testFileError1).not.toBeDefined();
250
- expect(testFileError2).toBeDefined();
251
- expect(testFileError2.code).toBe('ENOENT');
252
- });
253
- });