Skip to content

Commit b159b12

Browse files
daniasellik95
andauthored
V0.3.8 (#1)
* refactored path for Unsupported * Added json results for Cypress and mocha html report generation * Added bitloops option check in patching step * added cypress helper functions --------- Co-authored-by: ellik95 <[email protected]>
1 parent db411ae commit b159b12

File tree

6 files changed

+104
-9
lines changed

6 files changed

+104
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-bitloops",
3-
"version": "0.3.7",
3+
"version": "0.3.8",
44
"description": "Next.js with TypeScript, Tailwind, Storybook and Cypress generator by Bitloops",
55
"license": "MIT",
66
"author": "Bitloops S.A.",

setup/index.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export default class extends Generator {
119119
this.log('Installing Cypress...');
120120
this.spawnCommandSync('npm', ['install', '--save-dev', 'cypress']);
121121
this.log('Cypress installed!');
122+
if (this.options.bitloops) {
123+
this.spawnCommandSync('npm', ['install', '--save-dev', 'mochawesome', 'mochawesome-merge', 'mochawesome-report-generator']);
124+
}
122125
}
123126
}
124127

@@ -176,16 +179,27 @@ export default class extends Generator {
176179
this.destinationPath('src/app/globals.css'),
177180
);
178181

179-
this.log('Adding Bitloops support components...');
180-
this.fs.copyTpl(
181-
this.templatePath('src.components.bitloops.Unsupported.tsx'),
182-
this.destinationPath('src/components/bitloops/Unsupported.tsx'),
183-
);
184-
if (this.options.storybook) {
182+
if (this.options.bitloops) {
183+
this.log('Adding Bitloops support components...');
184+
const path = 'src/components/bitloops/Unsupported.tsx';
185185
this.fs.copyTpl(
186-
this.templatePath('src.components.bitloops.Unsupported.stories.tsx'),
187-
this.destinationPath('src/components/bitloops/Unsupported.stories.tsx'),
186+
this.templatePath(path),
187+
this.destinationPath(path),
188188
);
189+
if (this.options.storybook) {
190+
const path = 'src/components/bitloops/Unsupported.stories.tsx';
191+
this.fs.copyTpl(
192+
this.templatePath(path),
193+
this.destinationPath(path),
194+
);
195+
}
196+
if (this.options.cypress) {
197+
const path = 'cypress/helpers/index.ts';
198+
this.fs.copyTpl(
199+
this.templatePath(path),
200+
this.destinationPath(path),
201+
);
202+
}
189203
}
190204
}
191205

setup/templates/cypress.config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
import { defineConfig } from 'cypress';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
24

35
export default defineConfig({
46
e2e: {
57
specPattern: "**/*.cy.{ts,tsx}",
68
supportFile: false,
9+
testIsolation: false,
10+
setupNodeEvents(on) {
11+
on('task', {
12+
saveTestResults(results) {
13+
const resultsPath = path.join(__dirname, '.', 'cypress', 'results', 'results.json');
14+
if (!fs.existsSync(resultsPath)) {
15+
fs.writeFileSync(resultsPath, '[]'); // Create file if it doesn't exist
16+
}
17+
const existingResults = JSON.parse(fs.readFileSync(resultsPath, 'utf8'));
18+
existingResults.push(JSON.parse(results));
19+
fs.writeFileSync(resultsPath, JSON.stringify(existingResults, null, 2));
20+
return null; // Indicate the task was successful
21+
}
22+
});
23+
},
724
},
25+
reporter: "mochawesome",
26+
reporterOptions: {
27+
reportDir: "cypress/results",
28+
overwrite: true,
29+
html: true,
30+
json: true,
31+
},
832
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export const getWindowBounds = (window: Window): DOMRect => {
2+
return new DOMRect(0, 0, window.innerWidth, window.innerHeight);
3+
};
4+
5+
export const isOutOfBounds = (inRect: DOMRect, outRect: DOMRect): boolean => {
6+
const isOut =
7+
inRect.left < outRect.left ||
8+
inRect.right > outRect.right ||
9+
inRect.bottom > outRect.bottom ||
10+
inRect.top < outRect.top;
11+
return isOut;
12+
};
13+
14+
export const hasHorizontalScroll = (document: Document): boolean => {
15+
const scrollingElement = document.scrollingElement;
16+
if (!scrollingElement) {
17+
return false;
18+
}
19+
const scrollWidth = scrollingElement.scrollWidth || 0;
20+
const clientWidth = scrollingElement.clientWidth || 0;
21+
22+
return scrollWidth > clientWidth;
23+
};
24+
25+
export const areVerticalLeftAligned = (rects: DOMRect[]): boolean => {
26+
const firstRect = rects[0];
27+
for (let i = 1; i < rects.length; i++) {
28+
if (rects[i].x !== firstRect.x) {
29+
return false;
30+
}
31+
}
32+
return true;
33+
};
34+
35+
export const areVerticalCenteredAligned = (rects: DOMRect[]): boolean => {
36+
const firstRect = rects[0];
37+
const xCenterOfFirstRect = firstRect.x + firstRect.width / 2;
38+
for (let i = 1; i < rects.length; i++) {
39+
const xCenterOfRect = rects[i].x + rects[i].width / 2;
40+
if (xCenterOfRect !== xCenterOfFirstRect) {
41+
return false;
42+
}
43+
}
44+
return true;
45+
};
46+
47+
export const areVerticalRightAligned = (rects: DOMRect[]): boolean => {
48+
const firstRect = rects[0];
49+
const xRightOfFirstRect = firstRect.x + firstRect.width;
50+
for (let i = 1; i < rects.length; i++) {
51+
const xRightOfRect = rects[i].x + rects[i].width;
52+
if (xRightOfRect !== xRightOfFirstRect) {
53+
return false;
54+
}
55+
}
56+
return true;
57+
};

0 commit comments

Comments
 (0)