generator-bitloops 0.3.7 → 0.3.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-bitloops",
3
- "version": "0.3.7",
3
+ "version": "0.3.8",
4
4
  "description": "Next.js with TypeScript, Tailwind, Storybook and Cypress generator by Bitloops",
5
5
  "license": "MIT",
6
6
  "author": "Bitloops S.A.",
package/setup/index.js CHANGED
@@ -119,6 +119,9 @@ export default class extends Generator {
119
119
  this.log('Installing Cypress...');
120
120
  this.spawnCommandSync('npm', ['install', '--save-dev', 'cypress']);
121
121
  this.log('Cypress installed!');
122
+ if (this.options.bitloops) {
123
+ this.spawnCommandSync('npm', ['install', '--save-dev', 'mochawesome', 'mochawesome-merge', 'mochawesome-report-generator']);
124
+ }
122
125
  }
123
126
  }
124
127
 
@@ -176,16 +179,27 @@ export default class extends Generator {
176
179
  this.destinationPath('src/app/globals.css'),
177
180
  );
178
181
 
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';
185
185
  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),
188
188
  );
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
+ }
189
203
  }
190
204
  }
191
205
 
@@ -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
+ };
@@ -1,8 +1,32 @@
1
1
  import { defineConfig } from 'cypress';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
2
4
 
3
5
  export default defineConfig({
4
6
  e2e: {
5
7
  specPattern: "**/*.cy.{ts,tsx}",
6
8
  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
+ },
7
24
  },
25
+ reporter: "mochawesome",
26
+ reporterOptions: {
27
+ reportDir: "cypress/results",
28
+ overwrite: true,
29
+ html: true,
30
+ json: true,
31
+ },
8
32
  });