@qoretechnologies/reqore 0.78.5-pr.708.ga60ab46 → 0.78.5-pr.708.gbb7157e

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/vitest.config.ts CHANGED
@@ -1,14 +1,80 @@
1
1
  import { qlipVitestPlugin } from '@qoretechnologies/qlip';
2
2
  import { storybookTest } from '@storybook/addon-vitest/vitest-plugin';
3
3
  import { playwright } from '@vitest/browser-playwright';
4
+ import { readFileSync, readdirSync } from 'node:fs';
4
5
  import path from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
6
- import { defineConfig, mergeConfig } from 'vitest/config';
7
+ import { configDefaults, defineConfig, mergeConfig } from 'vitest/config';
7
8
  import viteConfig from './vite.config';
8
9
 
9
10
  const dirname = path.dirname(fileURLToPath(import.meta.url));
10
11
  const qlipUploadToken = process.env.QLIP_UPLOAD_TOKEN;
11
12
 
13
+ /**
14
+ * Story files with no story tagged `touch`, relative to the project root. The touch project leaves them out,
15
+ * so it does not load every story module only to skip it. Read from the files themselves: tagging a story
16
+ * is all it takes to run it on a touch screen.
17
+ */
18
+ const storyFilesWithoutTouch = (): string[] =>
19
+ readdirSync(path.join(dirname, 'src'), { recursive: true, encoding: 'utf8' })
20
+ .filter((file) => file.endsWith('.stories.tsx'))
21
+ .map((file) => path.join('src', file).split(path.sep).join('/'))
22
+ .filter(
23
+ (file) =>
24
+ !/\btags:\s*\[[^\]]*['"]touch['"]/.test(readFileSync(path.join(dirname, file), 'utf8'))
25
+ );
26
+
27
+ // One plugin for both story projects, so they make one qlip build: one build id, and one upload at the end
28
+ // of the run (the plugin registers its reporter once, however many projects load it).
29
+ const qlip = qlipVitestPlugin({
30
+ auto: true,
31
+ captureOnError: true,
32
+ disableAnimations: true,
33
+ pauseAnimationsAtEnd: true,
34
+ viewport: { width: 1920, height: 1080 },
35
+ // serverUrl omitted — defaults to https://qlip.qoretechnologies.com
36
+ ...(qlipUploadToken ? { upload: { uploadToken: qlipUploadToken } } : {}),
37
+ });
38
+
39
+ /**
40
+ * The browser a story project runs in: a desktop with a mouse, or - `phone` - the phone the stories tagged
41
+ * `touch` run on (`src/stories/utils/touchScreen.ts`). A new object for each project: Vitest names a
42
+ * project's browser instances on the objects themselves.
43
+ */
44
+ const storyBrowser = (phone = false) => ({
45
+ enabled: true,
46
+ // Vitest 4's @vitest/browser-playwright no longer applies
47
+ // `browser.viewport` to the Playwright context (the line is
48
+ // commented out in the provider), so the context silently falls
49
+ // back to Playwright's 1280×720 default and every capture is
50
+ // clamped to it — while the manifest still records qlip's
51
+ // 1920×1080, yielding blurry, mislabeled snapshots. Pass the
52
+ // viewport through the provider's `contextOptions` (which IS
53
+ // applied) so the browser window matches qlip's capture viewport
54
+ // 1:1 and screenshots come out at their true resolution.
55
+ //
56
+ // The phone is a phone from the start: Playwright makes its context with `isMobile` and `hasTouch`, so
57
+ // `(pointer: coarse)` and `(hover: none)` match and a touch is a finger's, and nothing turns that on or
58
+ // off. Turning Chromium's touch emulation off over the DevTools protocol (how a touch story used to
59
+ // borrow a desktop page) leaves the page with the hover and pointer the machine reports, not the mouse
60
+ // Playwright launched it with (`--blink-settings=primaryHoverType=2,…`), and a Linux CI runner reports
61
+ // none: every later story in the page found `(hover: none)` (qorus#646).
62
+ provider: playwright({
63
+ contextOptions: phone
64
+ ? { viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }
65
+ : { viewport: { width: 1920, height: 1080 } },
66
+ }),
67
+ headless: true,
68
+ instances: [{ browser: 'chromium' as const }],
69
+ });
70
+
71
+ const storyTest = {
72
+ setupFiles: ['./.storybook/vitest.setup.ts'],
73
+ // Some interaction stories deliberately render slow content and the shared
74
+ // play-function helpers wait up to ~17s; give them headroom.
75
+ testTimeout: 30000,
76
+ };
77
+
12
78
  export default mergeConfig(
13
79
  viteConfig,
14
80
  defineConfig({
@@ -16,46 +82,47 @@ export default mergeConfig(
16
82
  projects: [
17
83
  // Component/interaction tests: run every story in a real browser via Playwright.
18
84
  // Replaces the former @storybook/test-runner.
85
+ //
86
+ // Stories run in two projects, each in a browser of its own kind (see `storyBrowser`): every story on
87
+ // a desktop with a mouse, but those tagged `touch`, which run on a phone. `.storybook/vitest.setup.ts`
88
+ // checks each story's browser is the one its project promises.
19
89
  {
20
90
  extends: true,
21
91
  plugins: [
22
- qlipVitestPlugin({
23
- auto: true,
24
- captureOnError: true,
25
- disableAnimations: true,
26
- pauseAnimationsAtEnd: true,
27
- viewport: { width: 1920, height: 1080 },
28
- // serverUrl omitted — defaults to https://qlip.qoretechnologies.com
29
- ...(qlipUploadToken ? { upload: { uploadToken: qlipUploadToken } } : {}),
30
- }),
92
+ qlip,
31
93
  storybookTest({
32
94
  configDir: path.join(dirname, '.storybook'),
33
95
  storybookScript: 'yarn storybook --no-open',
96
+ tags: { exclude: ['touch'] },
34
97
  }),
35
98
  ],
36
99
  test: {
37
100
  name: 'storybook',
38
- browser: {
39
- enabled: true,
40
- // Vitest 4's @vitest/browser-playwright no longer applies
41
- // `browser.viewport` to the Playwright context (the line is
42
- // commented out in the provider), so the context silently falls
43
- // back to Playwright's 1280×720 default and every capture is
44
- // clamped to it — while the manifest still records qlip's
45
- // 1920×1080, yielding blurry, mislabeled snapshots. Pass the
46
- // viewport through the provider's `contextOptions` (which IS
47
- // applied) so the browser window matches qlip's capture viewport
48
- // 1:1 and screenshots come out at their true resolution.
49
- provider: playwright({
50
- contextOptions: { viewport: { width: 1920, height: 1080 } },
51
- }),
52
- headless: true,
53
- instances: [{ browser: 'chromium' }],
54
- },
55
- setupFiles: ['./.storybook/vitest.setup.ts'],
56
- // Some interaction stories deliberately render slow content and the shared
57
- // play-function helpers wait up to ~17s; give them headroom.
58
- testTimeout: 30000,
101
+ // after the stories on the phone: each story here checks it still has its mouse
102
+ sequence: { groupOrder: 1 },
103
+ browser: storyBrowser(),
104
+ ...storyTest,
105
+ },
106
+ },
107
+ // The stories tagged `touch`, on the phone. Before the others, not beside them: the two projects share
108
+ // Storybook's dependency cache (it is named after the config directory), which is not built twice at
109
+ // once.
110
+ {
111
+ extends: true,
112
+ plugins: [
113
+ qlip,
114
+ storybookTest({
115
+ configDir: path.join(dirname, '.storybook'),
116
+ storybookScript: 'yarn storybook --no-open',
117
+ tags: { include: ['touch'] },
118
+ }),
119
+ ],
120
+ test: {
121
+ name: 'storybook-touch',
122
+ exclude: [...configDefaults.exclude, ...storyFilesWithoutTouch()],
123
+ sequence: { groupOrder: 0 },
124
+ browser: storyBrowser(true),
125
+ ...storyTest,
59
126
  },
60
127
  },
61
128
  // Unit tests: the former Jest suite, now on Vitest + jsdom.