flexysnap 0.1.3-alpha.2 → 0.1.4-alpha.1
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/package.json +1 -1
- package/src/index.js +7 -1
- package/src/wireframeOutput.js +29 -0
- package/src/wireframeUtils.js +13 -14
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -23,4 +23,10 @@ export {
|
|
|
23
23
|
|
|
24
24
|
export { areWireframesStable } from './wireframeStability.js';
|
|
25
25
|
|
|
26
|
-
export { expectWireframe, getRGBHistogramFromBuffer } from './wireframeUtils.js';
|
|
26
|
+
export { expectWireframe, getRGBHistogramFromBuffer } from './wireframeUtils.js';
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
setWireframeOutputRoot,
|
|
30
|
+
getWireframeOutputRoot,
|
|
31
|
+
resolveWireframeOutputDir
|
|
32
|
+
} from './wireframeOutput.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
|
|
3
|
+
let outputRoot = process.cwd();
|
|
4
|
+
|
|
5
|
+
function setWireframeOutputRoot(rootPath) {
|
|
6
|
+
outputRoot = rootPath || process.cwd();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getWireframeOutputRoot() {
|
|
10
|
+
return outputRoot;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function resolveWireframeOutputDir(outputDir) {
|
|
14
|
+
if (!outputDir || typeof outputDir !== 'string') {
|
|
15
|
+
throw new Error('resolveWireframeOutputDir requires a non-empty string outputDir.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (path.isAbsolute(outputDir)) {
|
|
19
|
+
return outputDir;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return path.join(outputRoot, outputDir);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
setWireframeOutputRoot,
|
|
27
|
+
getWireframeOutputRoot,
|
|
28
|
+
resolveWireframeOutputDir
|
|
29
|
+
};
|
package/src/wireframeUtils.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { logTimestamp } from './testUtils.js';
|
|
4
4
|
import { loadImage, createCanvas } from 'canvas';
|
|
5
5
|
import { areWireframesStable } from './wireframeStability.js';
|
|
6
|
+
import { resolveWireframeOutputDir } from './wireframeOutput.js';
|
|
6
7
|
|
|
7
8
|
const FLEXYSNAP_ELEMENT_ID_ATTRIBUTE = 'data-flexysnap-id';
|
|
8
9
|
|
|
@@ -270,13 +271,11 @@ async function extractStableWireframe(page, elementGroups, retryDelay, maxRetryC
|
|
|
270
271
|
return {wireframeData: currentWireframeData, scrollPosition: currentScrollPosition};
|
|
271
272
|
}
|
|
272
273
|
|
|
273
|
-
async function expectWireframe(page, elementGroups,
|
|
274
|
-
|
|
275
|
-
const { wireframeData, scrollPosition } = await extractStableWireframe(page, elementGroups, retryDelay, maxRetryCount);
|
|
274
|
+
async function expectWireframe(page, elementGroups, outputDir, outputFile, outputName, options = {}) {
|
|
275
|
+
const { retryDelay = 1000, maxRetryCount = 10, metadata = {} } = options;
|
|
276
276
|
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
const testType = process.env.TEST_TYPE;
|
|
277
|
+
logTimestamp(`Starting wireframe capture for: ${outputFile}`);
|
|
278
|
+
const { wireframeData, scrollPosition } = await extractStableWireframe(page, elementGroups, retryDelay, maxRetryCount);
|
|
280
279
|
|
|
281
280
|
const screenshotScrollPosition = await page.evaluate(() => ({
|
|
282
281
|
x: window.scrollX,
|
|
@@ -286,25 +285,25 @@ async function expectWireframe(page, elementGroups, configName, outputFile, outp
|
|
|
286
285
|
const wireframeOutput = {
|
|
287
286
|
name: outputName,
|
|
288
287
|
timestamp: new Date().toISOString(),
|
|
289
|
-
deviceType: process.env.DEVICE_TYPE,
|
|
290
|
-
userType: process.env.USER_TYPE,
|
|
291
288
|
scrollPosition,
|
|
292
289
|
screenshotScrollPosition,
|
|
293
|
-
elementGroups: wireframeData
|
|
290
|
+
elementGroups: wireframeData,
|
|
291
|
+
...metadata
|
|
294
292
|
};
|
|
295
293
|
|
|
294
|
+
const resolvedDir = resolveWireframeOutputDir(outputDir);
|
|
295
|
+
fs.mkdirSync(resolvedDir, {recursive: true});
|
|
296
|
+
|
|
296
297
|
const fileName = `${outputFile}.json`;
|
|
297
|
-
const filePath = path.join(
|
|
298
|
-
const fileDir = path.dirname(filePath);
|
|
299
|
-
fs.mkdirSync(fileDir, {recursive: true});
|
|
298
|
+
const filePath = path.join(resolvedDir, fileName);
|
|
300
299
|
fs.writeFileSync(filePath, JSON.stringify(wireframeOutput, null, 2));
|
|
301
300
|
logTimestamp(`Wireframe captured and saved to: ${fileName}`);
|
|
302
301
|
|
|
303
|
-
const screenshotPath = path.join(
|
|
302
|
+
const screenshotPath = path.join(resolvedDir, `${outputFile}.png`);
|
|
304
303
|
await page.screenshot({ path: screenshotPath });
|
|
305
304
|
logTimestamp(`Wireframe screenshot saved to: ${screenshotPath}`);
|
|
306
305
|
|
|
307
|
-
return {wireframeOutput, screenshotPath};
|
|
306
|
+
return {wireframeOutput, screenshotPath, outputDir: resolvedDir};
|
|
308
307
|
}
|
|
309
308
|
|
|
310
309
|
export { expectWireframe, getRGBHistogramFromBuffer };
|