@essential-apps/shopify-test-runner 1.0.0

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.
Files changed (265) hide show
  1. package/dist/contracts/normalize.d.ts +61 -0
  2. package/dist/contracts/normalize.d.ts.map +1 -0
  3. package/dist/contracts/normalize.js +99 -0
  4. package/dist/contracts/normalize.js.map +1 -0
  5. package/dist/contracts/normalizeHtml.d.ts +37 -0
  6. package/dist/contracts/normalizeHtml.d.ts.map +1 -0
  7. package/dist/contracts/normalizeHtml.js +89 -0
  8. package/dist/contracts/normalizeHtml.js.map +1 -0
  9. package/dist/edge/cert.d.ts +44 -0
  10. package/dist/edge/cert.d.ts.map +1 -0
  11. package/dist/edge/cert.js +117 -0
  12. package/dist/edge/cert.js.map +1 -0
  13. package/dist/edge/edgeProxy.d.ts +43 -0
  14. package/dist/edge/edgeProxy.d.ts.map +1 -0
  15. package/dist/edge/edgeProxy.js +297 -0
  16. package/dist/edge/edgeProxy.js.map +1 -0
  17. package/dist/edge/nodeShim.d.ts +2 -0
  18. package/dist/edge/nodeShim.d.ts.map +1 -0
  19. package/dist/edge/nodeShim.js +217 -0
  20. package/dist/edge/nodeShim.js.map +1 -0
  21. package/dist/index.d.ts +39 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +36 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/lib/buildSourceBundle.d.ts +56 -0
  26. package/dist/lib/buildSourceBundle.d.ts.map +1 -0
  27. package/dist/lib/buildSourceBundle.js +153 -0
  28. package/dist/lib/buildSourceBundle.js.map +1 -0
  29. package/dist/lib/freePort.d.ts +5 -0
  30. package/dist/lib/freePort.d.ts.map +1 -0
  31. package/dist/lib/freePort.js +33 -0
  32. package/dist/lib/freePort.js.map +1 -0
  33. package/dist/lib/functionBuild.d.ts +99 -0
  34. package/dist/lib/functionBuild.d.ts.map +1 -0
  35. package/dist/lib/functionBuild.js +413 -0
  36. package/dist/lib/functionBuild.js.map +1 -0
  37. package/dist/lib/neonWsProxy.d.ts +41 -0
  38. package/dist/lib/neonWsProxy.d.ts.map +1 -0
  39. package/dist/lib/neonWsProxy.js +101 -0
  40. package/dist/lib/neonWsProxy.js.map +1 -0
  41. package/dist/lib/sourceZipUpload.d.ts +45 -0
  42. package/dist/lib/sourceZipUpload.d.ts.map +1 -0
  43. package/dist/lib/sourceZipUpload.js +129 -0
  44. package/dist/lib/sourceZipUpload.js.map +1 -0
  45. package/dist/lib/stealthLaunch.d.ts +35 -0
  46. package/dist/lib/stealthLaunch.d.ts.map +1 -0
  47. package/dist/lib/stealthLaunch.js +46 -0
  48. package/dist/lib/stealthLaunch.js.map +1 -0
  49. package/dist/lib/storeAutomation.d.ts +22 -0
  50. package/dist/lib/storeAutomation.d.ts.map +1 -0
  51. package/dist/lib/storeAutomation.js +85 -0
  52. package/dist/lib/storeAutomation.js.map +1 -0
  53. package/dist/playwright/baseConfig.d.ts +62 -0
  54. package/dist/playwright/baseConfig.d.ts.map +1 -0
  55. package/dist/playwright/baseConfig.js +68 -0
  56. package/dist/playwright/baseConfig.js.map +1 -0
  57. package/dist/playwright/globalSetup.d.ts +2 -0
  58. package/dist/playwright/globalSetup.d.ts.map +1 -0
  59. package/dist/playwright/globalSetup.js +139 -0
  60. package/dist/playwright/globalSetup.js.map +1 -0
  61. package/dist/playwright/index.d.ts +9 -0
  62. package/dist/playwright/index.d.ts.map +1 -0
  63. package/dist/playwright/index.js +9 -0
  64. package/dist/playwright/index.js.map +1 -0
  65. package/dist/probes/fonts.d.ts +4 -0
  66. package/dist/probes/fonts.d.ts.map +1 -0
  67. package/dist/probes/fonts.js +255 -0
  68. package/dist/probes/fonts.js.map +1 -0
  69. package/dist/probes/mirror.d.ts +4 -0
  70. package/dist/probes/mirror.d.ts.map +1 -0
  71. package/dist/probes/mirror.js +260 -0
  72. package/dist/probes/mirror.js.map +1 -0
  73. package/dist/probes/runProbe.d.ts +3 -0
  74. package/dist/probes/runProbe.d.ts.map +1 -0
  75. package/dist/probes/runProbe.js +219 -0
  76. package/dist/probes/runProbe.js.map +1 -0
  77. package/dist/probes/types.d.ts +72 -0
  78. package/dist/probes/types.d.ts.map +1 -0
  79. package/dist/probes/types.js +2 -0
  80. package/dist/probes/types.js.map +1 -0
  81. package/dist/scripts/_probeSourceUrl.d.ts +3 -0
  82. package/dist/scripts/_probeSourceUrl.d.ts.map +1 -0
  83. package/dist/scripts/_probeSourceUrl.js +119 -0
  84. package/dist/scripts/_probeSourceUrl.js.map +1 -0
  85. package/dist/scripts/addStore.d.ts +3 -0
  86. package/dist/scripts/addStore.d.ts.map +1 -0
  87. package/dist/scripts/addStore.js +46 -0
  88. package/dist/scripts/addStore.js.map +1 -0
  89. package/dist/scripts/buildDockerImage.d.ts +3 -0
  90. package/dist/scripts/buildDockerImage.d.ts.map +1 -0
  91. package/dist/scripts/buildDockerImage.js +60 -0
  92. package/dist/scripts/buildDockerImage.js.map +1 -0
  93. package/dist/scripts/captureAuth.d.ts +3 -0
  94. package/dist/scripts/captureAuth.d.ts.map +1 -0
  95. package/dist/scripts/captureAuth.js +124 -0
  96. package/dist/scripts/captureAuth.js.map +1 -0
  97. package/dist/scripts/captureContracts.d.ts +3 -0
  98. package/dist/scripts/captureContracts.d.ts.map +1 -0
  99. package/dist/scripts/captureContracts.js +517 -0
  100. package/dist/scripts/captureContracts.js.map +1 -0
  101. package/dist/scripts/captureRestContracts.d.ts +3 -0
  102. package/dist/scripts/captureRestContracts.d.ts.map +1 -0
  103. package/dist/scripts/captureRestContracts.js +245 -0
  104. package/dist/scripts/captureRestContracts.js.map +1 -0
  105. package/dist/scripts/checkOperationCoverage.d.ts +3 -0
  106. package/dist/scripts/checkOperationCoverage.d.ts.map +1 -0
  107. package/dist/scripts/checkOperationCoverage.js +302 -0
  108. package/dist/scripts/checkOperationCoverage.js.map +1 -0
  109. package/dist/scripts/cleanupStores.d.ts +3 -0
  110. package/dist/scripts/cleanupStores.d.ts.map +1 -0
  111. package/dist/scripts/cleanupStores.js +77 -0
  112. package/dist/scripts/cleanupStores.js.map +1 -0
  113. package/dist/scripts/createStores.d.ts +3 -0
  114. package/dist/scripts/createStores.d.ts.map +1 -0
  115. package/dist/scripts/createStores.js +66 -0
  116. package/dist/scripts/createStores.js.map +1 -0
  117. package/dist/scripts/deployAppVersion.d.ts +3 -0
  118. package/dist/scripts/deployAppVersion.d.ts.map +1 -0
  119. package/dist/scripts/deployAppVersion.js +591 -0
  120. package/dist/scripts/deployAppVersion.js.map +1 -0
  121. package/dist/scripts/devE2eBackend.d.ts +3 -0
  122. package/dist/scripts/devE2eBackend.d.ts.map +1 -0
  123. package/dist/scripts/devE2eBackend.js +117 -0
  124. package/dist/scripts/devE2eBackend.js.map +1 -0
  125. package/dist/scripts/devOnlineBackend.d.ts +3 -0
  126. package/dist/scripts/devOnlineBackend.d.ts.map +1 -0
  127. package/dist/scripts/devOnlineBackend.js +117 -0
  128. package/dist/scripts/devOnlineBackend.js.map +1 -0
  129. package/dist/scripts/installApp.d.ts +3 -0
  130. package/dist/scripts/installApp.d.ts.map +1 -0
  131. package/dist/scripts/installApp.js +163 -0
  132. package/dist/scripts/installApp.js.map +1 -0
  133. package/dist/scripts/listStores.d.ts +3 -0
  134. package/dist/scripts/listStores.d.ts.map +1 -0
  135. package/dist/scripts/listStores.js +18 -0
  136. package/dist/scripts/listStores.js.map +1 -0
  137. package/dist/scripts/runDocker.d.ts +3 -0
  138. package/dist/scripts/runDocker.d.ts.map +1 -0
  139. package/dist/scripts/runDocker.js +88 -0
  140. package/dist/scripts/runDocker.js.map +1 -0
  141. package/dist/scripts/runDockerAuth.d.ts +3 -0
  142. package/dist/scripts/runDockerAuth.d.ts.map +1 -0
  143. package/dist/scripts/runDockerAuth.js +108 -0
  144. package/dist/scripts/runDockerAuth.js.map +1 -0
  145. package/dist/scripts/runDockerOffline.d.ts +3 -0
  146. package/dist/scripts/runDockerOffline.d.ts.map +1 -0
  147. package/dist/scripts/runDockerOffline.js +129 -0
  148. package/dist/scripts/runDockerOffline.js.map +1 -0
  149. package/dist/scripts/runDockerOfflineExplore.d.ts +3 -0
  150. package/dist/scripts/runDockerOfflineExplore.d.ts.map +1 -0
  151. package/dist/scripts/runDockerOfflineExplore.js +116 -0
  152. package/dist/scripts/runDockerOfflineExplore.js.map +1 -0
  153. package/dist/scripts/runIsolatedDockerOffline.d.ts +3 -0
  154. package/dist/scripts/runIsolatedDockerOffline.d.ts.map +1 -0
  155. package/dist/scripts/runIsolatedDockerOffline.js +351 -0
  156. package/dist/scripts/runIsolatedDockerOffline.js.map +1 -0
  157. package/dist/scripts/runOffline.d.ts +3 -0
  158. package/dist/scripts/runOffline.d.ts.map +1 -0
  159. package/dist/scripts/runOffline.js +521 -0
  160. package/dist/scripts/runOffline.js.map +1 -0
  161. package/dist/scripts/runOfflineE2e.d.ts +3 -0
  162. package/dist/scripts/runOfflineE2e.d.ts.map +1 -0
  163. package/dist/scripts/runOfflineE2e.js +408 -0
  164. package/dist/scripts/runOfflineE2e.js.map +1 -0
  165. package/dist/scripts/runOfflineFullTests.d.ts +3 -0
  166. package/dist/scripts/runOfflineFullTests.d.ts.map +1 -0
  167. package/dist/scripts/runOfflineFullTests.js +1456 -0
  168. package/dist/scripts/runOfflineFullTests.js.map +1 -0
  169. package/dist/scripts/runSupermachine.d.ts +3 -0
  170. package/dist/scripts/runSupermachine.d.ts.map +1 -0
  171. package/dist/scripts/runSupermachine.js +474 -0
  172. package/dist/scripts/runSupermachine.js.map +1 -0
  173. package/dist/scripts/runSupermachineAuth.d.ts +3 -0
  174. package/dist/scripts/runSupermachineAuth.d.ts.map +1 -0
  175. package/dist/scripts/runSupermachineAuth.js +454 -0
  176. package/dist/scripts/runSupermachineAuth.js.map +1 -0
  177. package/dist/scripts/runTests.d.ts +3 -0
  178. package/dist/scripts/runTests.d.ts.map +1 -0
  179. package/dist/scripts/runTests.js +278 -0
  180. package/dist/scripts/runTests.js.map +1 -0
  181. package/dist/scripts/runVm.d.ts +3 -0
  182. package/dist/scripts/runVm.d.ts.map +1 -0
  183. package/dist/scripts/runVm.js +524 -0
  184. package/dist/scripts/runVm.js.map +1 -0
  185. package/dist/scripts/runVmAuth.d.ts +3 -0
  186. package/dist/scripts/runVmAuth.d.ts.map +1 -0
  187. package/dist/scripts/runVmAuth.js +475 -0
  188. package/dist/scripts/runVmAuth.js.map +1 -0
  189. package/dist/scripts/runVmScript.d.ts +3 -0
  190. package/dist/scripts/runVmScript.d.ts.map +1 -0
  191. package/dist/scripts/runVmScript.js +242 -0
  192. package/dist/scripts/runVmScript.js.map +1 -0
  193. package/dist/scripts/setupTestDb.d.ts +3 -0
  194. package/dist/scripts/setupTestDb.d.ts.map +1 -0
  195. package/dist/scripts/setupTestDb.js +61 -0
  196. package/dist/scripts/setupTestDb.js.map +1 -0
  197. package/dist/scripts/verifyContracts.d.ts +3 -0
  198. package/dist/scripts/verifyContracts.d.ts.map +1 -0
  199. package/dist/scripts/verifyContracts.js +258 -0
  200. package/dist/scripts/verifyContracts.js.map +1 -0
  201. package/dist/scripts/verifyRestContracts.d.ts +3 -0
  202. package/dist/scripts/verifyRestContracts.d.ts.map +1 -0
  203. package/dist/scripts/verifyRestContracts.js +237 -0
  204. package/dist/scripts/verifyRestContracts.js.map +1 -0
  205. package/dist/vite/offlineConfig.d.ts +34 -0
  206. package/dist/vite/offlineConfig.d.ts.map +1 -0
  207. package/dist/vite/offlineConfig.js +61 -0
  208. package/dist/vite/offlineConfig.js.map +1 -0
  209. package/dist/vite/onlineConfig.d.ts +42 -0
  210. package/dist/vite/onlineConfig.d.ts.map +1 -0
  211. package/dist/vite/onlineConfig.js +56 -0
  212. package/dist/vite/onlineConfig.js.map +1 -0
  213. package/docker/Dockerfile +67 -0
  214. package/docker/Dockerfile.vm +137 -0
  215. package/docker/README.md +50 -0
  216. package/docker/entrypoint.sh +198 -0
  217. package/package.json +85 -0
  218. package/src/contracts/normalize.ts +96 -0
  219. package/src/contracts/normalizeHtml.ts +98 -0
  220. package/src/edge/ca.cnf +14 -0
  221. package/src/edge/ca.crt +22 -0
  222. package/src/edge/ca.key +28 -0
  223. package/src/edge/cert.ts +117 -0
  224. package/src/edge/edgeProxy.ts +390 -0
  225. package/src/edge/server.cnf +28 -0
  226. package/src/edge/server.crt +26 -0
  227. package/src/edge/server.key +28 -0
  228. package/src/index.ts +67 -0
  229. package/src/lib/buildSourceBundle.ts +197 -0
  230. package/src/lib/freePort.ts +33 -0
  231. package/src/lib/functionBuild.ts +490 -0
  232. package/src/lib/neonWsProxy.ts +124 -0
  233. package/src/lib/sourceZipUpload.ts +168 -0
  234. package/src/lib/stealthLaunch.ts +57 -0
  235. package/src/lib/storeAutomation.ts +110 -0
  236. package/src/playwright/baseConfig.ts +120 -0
  237. package/src/playwright/globalSetup.ts +179 -0
  238. package/src/playwright/index.ts +11 -0
  239. package/src/probes/fonts.ts +279 -0
  240. package/src/probes/mirror.ts +283 -0
  241. package/src/probes/runProbe.ts +257 -0
  242. package/src/probes/types.ts +73 -0
  243. package/src/scripts/addStore.ts +59 -0
  244. package/src/scripts/buildDockerImage.ts +66 -0
  245. package/src/scripts/captureAuth.ts +145 -0
  246. package/src/scripts/captureContracts.ts +675 -0
  247. package/src/scripts/captureRestContracts.ts +319 -0
  248. package/src/scripts/checkOperationCoverage.ts +365 -0
  249. package/src/scripts/cleanupStores.ts +91 -0
  250. package/src/scripts/createStores.ts +77 -0
  251. package/src/scripts/deployAppVersion.ts +692 -0
  252. package/src/scripts/devOnlineBackend.ts +141 -0
  253. package/src/scripts/installApp.ts +188 -0
  254. package/src/scripts/listStores.ts +19 -0
  255. package/src/scripts/runDockerAuth.ts +120 -0
  256. package/src/scripts/runOffline.ts +577 -0
  257. package/src/scripts/runOfflineFullTests.ts +1634 -0
  258. package/src/scripts/runTests.ts +306 -0
  259. package/src/scripts/runVm.ts +562 -0
  260. package/src/scripts/runVmAuth.ts +541 -0
  261. package/src/scripts/runVmScript.ts +282 -0
  262. package/src/scripts/setupTestDb.ts +71 -0
  263. package/src/scripts/verifyContracts.ts +310 -0
  264. package/src/scripts/verifyRestContracts.ts +275 -0
  265. package/src/vite/onlineConfig.ts +60 -0
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Manual run of the online backend WITHOUT Shopify CLI.
4
+ *
5
+ * Used for `npm run test:online:install` (which needs a running backend to
6
+ * complete OAuth) and for local debugging. Mirrors the env-isolation
7
+ * guarantees of runTests.ts but uses a persistent DB
8
+ * (${appName}_online_${user}) instead of an ephemeral UUID one — so OAuth
9
+ * tokens persist across runs.
10
+ *
11
+ * Serves on https://localhost:PORT with a self-signed cert (vite +
12
+ * @vitejs/plugin-basic-ssl). No tunnel, no DNS.
13
+ */
14
+ import { spawn, execSync } from 'node:child_process';
15
+ import { existsSync, readFileSync } from 'node:fs';
16
+ import { resolve } from 'node:path';
17
+ import { loadEnv, printEnvSummary } from '@essential-apps/shopify-test-core';
18
+ import { isPortFree } from '../lib/freePort.js';
19
+
20
+ const PG_HOST = 'localhost';
21
+ const PG_PORT = '5432';
22
+
23
+ interface PackageJson {
24
+ name?: string;
25
+ }
26
+
27
+ function readAppName(): string {
28
+ const pkgPath = resolve(process.cwd(), 'package.json');
29
+ if (!existsSync(pkgPath)) {
30
+ throw new Error(
31
+ `No package.json at ${pkgPath}. Run this from the consuming app's repo root.`,
32
+ );
33
+ }
34
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as PackageJson;
35
+ if (!pkg.name) throw new Error(`package.json at ${pkgPath} has no \`name\` field.`);
36
+ return pkg.name.replace(/^@[^/]+\//, '');
37
+ }
38
+
39
+ function dbExists(name: string): boolean {
40
+ try {
41
+ execSync(`psql -h ${PG_HOST} -p ${PG_PORT} -lqt | cut -d \\| -f 1 | grep -qw ${name}`, {
42
+ stdio: 'ignore',
43
+ });
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ async function main(): Promise<void> {
51
+ const env = loadEnv();
52
+ printEnvSummary(env);
53
+
54
+ if (!env.apiSecret) {
55
+ throw new Error(
56
+ `SHOPIFY_API_SECRET is not set in .env.test.\n\n` +
57
+ `Get it from Partner Dashboard → Apps → "${env.devAppHandle}" → ` +
58
+ `Configuration → "Client credentials" → "Reveal client secret".\n` +
59
+ `Paste it into .env.test as SHOPIFY_API_SECRET=...`,
60
+ );
61
+ }
62
+
63
+ const appUrl = new URL(env.devAppUrl);
64
+ if (appUrl.hostname !== 'localhost' && appUrl.hostname !== '127.0.0.1') {
65
+ throw new Error(
66
+ `SHOPIFY_APP_URL must be a localhost URL (https://localhost:PORT). Got: ${env.devAppUrl}`,
67
+ );
68
+ }
69
+ if (appUrl.protocol !== 'https:') {
70
+ throw new Error(`SHOPIFY_APP_URL must use https:// — got ${env.devAppUrl}`);
71
+ }
72
+ const port = appUrl.port || '443';
73
+
74
+ if (!(await isPortFree(Number(port)))) {
75
+ throw new Error(
76
+ `Port ${port} is in use. Find what's there: lsof -i :${port}\n` +
77
+ `Or change SHOPIFY_APP_URL in .env.test to a different port (and update Partner Dashboard).`,
78
+ );
79
+ }
80
+
81
+ const appName = readAppName();
82
+ const dbPrefix = (process.env['TEST_ONLINE_DB_NAME_PREFIX'] ?? `${appName}_online`)
83
+ .toLowerCase()
84
+ .replace(/[^a-z0-9_]/g, '_');
85
+ const PERSISTENT_DB_NAME = `${dbPrefix}_${process.env['USER'] ?? 'local'}`;
86
+ const user = process.env['USER'] ?? '';
87
+ const url = `postgresql://${user}@${PG_HOST}:${PG_PORT}/${PERSISTENT_DB_NAME}`;
88
+
89
+ console.log(`[dev-online] Persistent DB: ${url}`);
90
+ console.log(`[dev-online] Backend: ${env.devAppUrl} (vite https, self-signed cert)`);
91
+ console.log('');
92
+
93
+ if (!dbExists(PERSISTENT_DB_NAME)) {
94
+ console.log(`[dev-online] createdb ${PERSISTENT_DB_NAME}…`);
95
+ execSync(`createdb -h ${PG_HOST} -p ${PG_PORT} ${PERSISTENT_DB_NAME}`, {
96
+ stdio: 'inherit',
97
+ });
98
+ } else {
99
+ console.log(`[dev-online] DB ${PERSISTENT_DB_NAME} exists, reusing.`);
100
+ }
101
+
102
+ const backendEnv: NodeJS.ProcessEnv = {
103
+ PATH: process.env['PATH'] ?? '',
104
+ // See runOfflineFullTests.ts for the long-form note — empty HOME
105
+ // makes npm write its cache to literal `~/.npm` in cwd.
106
+ HOME: process.env['HOME'] || '/root',
107
+ USER: process.env['USER'] ?? '',
108
+ NODE_ENV: 'test',
109
+ DATABASE_URL: url,
110
+ DIRECT_URL: url,
111
+ SHOPIFY_API_KEY: env.devClientId,
112
+ SHOPIFY_API_SECRET: env.apiSecret,
113
+ SCOPES: env.scopes,
114
+ SHOPIFY_APP_URL: env.devAppUrl,
115
+ PORT: port,
116
+ HOST: env.devAppUrl,
117
+ };
118
+
119
+ console.log('[dev-online] prisma migrate deploy…');
120
+ execSync('npx prisma migrate deploy', { stdio: 'inherit', env: backendEnv });
121
+
122
+ console.log('');
123
+ console.log('[dev-online] booting Remix dev server (vite, no tunnel)…');
124
+ console.log(` Open ${env.devAppUrl} (accept self-signed cert warning once).`);
125
+ console.log(' Ctrl-C to stop.');
126
+ console.log('');
127
+
128
+ const dev = spawn('npx', ['vite', '--port', port, '--strictPort', '--host', '0.0.0.0'], {
129
+ stdio: 'inherit',
130
+ env: backendEnv,
131
+ });
132
+
133
+ dev.on('exit', (code) => process.exit(code ?? 0));
134
+ process.on('SIGINT', () => dev.kill('SIGINT'));
135
+ process.on('SIGTERM', () => dev.kill('SIGTERM'));
136
+ }
137
+
138
+ main().catch((err) => {
139
+ console.error(err);
140
+ process.exit(1);
141
+ });
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Playwright-driven app install onto a registered test store. No
4
+ * human clicking, no Chrome PNA flag toggles.
5
+ *
6
+ * The consuming app's dev backend (e.g. `npm run dev:test-online`) MUST be
7
+ * running so the OAuth callback can hit localhost successfully.
8
+ */
9
+ import { existsSync } from 'node:fs';
10
+ import { parseArgs } from 'node:util';
11
+ import {
12
+ loadEnv,
13
+ printEnvSummary,
14
+ storageStatePath,
15
+ readRegistry,
16
+ writeRegistry,
17
+ } from '@essential-apps/shopify-test-core';
18
+ import { launchStealthBrowser } from '../lib/stealthLaunch.js';
19
+
20
+ async function main(): Promise<void> {
21
+ const { values } = parseArgs({
22
+ options: {
23
+ shop: { type: 'string' },
24
+ headless: { type: 'boolean', default: false },
25
+ },
26
+ });
27
+
28
+ const shop = values.shop?.trim();
29
+ if (!shop) {
30
+ console.error('Usage: npm run test:online:install -- --shop <shop>.myshopify.com');
31
+ process.exit(1);
32
+ }
33
+
34
+ const env = loadEnv();
35
+ printEnvSummary(env);
36
+
37
+ if (!existsSync(storageStatePath)) {
38
+ throw new Error(
39
+ `Auth state not found at ${storageStatePath}. Run: npm run test:online:auth`,
40
+ );
41
+ }
42
+
43
+ const reg = readRegistry();
44
+ const store = reg.stores.find((s) => s.shop === shop);
45
+ if (!store) {
46
+ throw new Error(
47
+ `Shop not in registry: ${shop}. Run: npm run test:online:add -- --shop ${shop}`,
48
+ );
49
+ }
50
+ if (store.appInstalled) {
51
+ console.log(`Already marked installed in registry. Skipping.`);
52
+ process.exit(0);
53
+ }
54
+
55
+ console.log('');
56
+ console.log(`Prerequisites: \`npm run dev:test-online\` must be running in another terminal.`);
57
+ console.log('');
58
+
59
+ // patchright's bundled Chromium (the one stealth engine the suite uses —
60
+ // same as the online storePool fixture + captureAuth) patches the CDP
61
+ // leak Cloudflare keys on, so its challenge fires less. PNA/LNA bypass
62
+ // flags are baked into launchStealthBrowser.
63
+ const browser = await launchStealthBrowser({ headless: values.headless ?? false });
64
+
65
+ const context = await browser.newContext({
66
+ storageState: storageStatePath,
67
+ ignoreHTTPSErrors: true,
68
+ viewport: { width: 1400, height: 900 },
69
+ });
70
+ await context.addInitScript(() => {
71
+ Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
72
+ });
73
+
74
+ const page = await context.newPage();
75
+ page.on('console', (msg) => {
76
+ if (['error', 'warning'].includes(msg.type())) {
77
+ console.log(`[browser console ${msg.type()}] ${msg.text()}`);
78
+ }
79
+ });
80
+
81
+ try {
82
+ // First, load any page on our origin so we can run JS in its context.
83
+ console.log(`[install] Loading ${env.devAppUrl}/auth/login to establish origin context…`);
84
+ await page.goto(`${env.devAppUrl}/auth/login`, { waitUntil: 'domcontentloaded' });
85
+
86
+ // POST to /auth/login with shop in form body via native form submit
87
+ // (bypasses Remix's <Form> fetch intercept, browser follows the
88
+ // 30x redirect to admin.shopify.com OAuth natively).
89
+ console.log(`[install] Submitting native POST to /auth/login (shop=${shop})…`);
90
+ await page.evaluate((shopParam) => {
91
+ const form = document.createElement('form');
92
+ form.action = '/auth/login';
93
+ form.method = 'POST';
94
+ const input = document.createElement('input');
95
+ input.name = 'shop';
96
+ input.value = shopParam;
97
+ form.appendChild(input);
98
+ document.body.appendChild(form);
99
+ form.submit();
100
+ }, shop);
101
+
102
+ // Wait for navigation away from our localhost origin — POST should
103
+ // redirect to admin.shopify.com or accounts.shopify.com.
104
+ await page.waitForURL((u) => !u.toString().includes('localhost:8181'), {
105
+ timeout: 30_000,
106
+ });
107
+
108
+ // Redirect chain can bounce through any combo of:
109
+ // accounts.shopify.com/select → account picker
110
+ // admin.shopify.com/login → no_cookie_session bounce
111
+ // admin.shopify.com/store/X/oauth/install → install consent
112
+ // Keep clicking through until we land on the consent screen.
113
+ for (let i = 0; i < 8; i++) {
114
+ await page.waitForLoadState('domcontentloaded').catch(() => {});
115
+ const url = page.url();
116
+ console.log(`[install] At: ${url}`);
117
+
118
+ if (url.includes('accounts.shopify.com/select')) {
119
+ const target = env.accountEmail
120
+ ? page.getByText(env.accountEmail, { exact: false }).first()
121
+ : page.locator('[role="link"], a, button').first();
122
+ await target.click({ timeout: 15_000 });
123
+ await page.waitForURL((u) => !u.toString().includes('/select'), {
124
+ timeout: 30_000,
125
+ });
126
+ continue;
127
+ }
128
+
129
+ if (url.includes('admin.shopify.com/login')) {
130
+ // The login page should auto-redirect once cookies settle.
131
+ await page.waitForURL((u) => !u.toString().includes('admin.shopify.com/login'), {
132
+ timeout: 30_000,
133
+ });
134
+ continue;
135
+ }
136
+
137
+ // We've landed somewhere stable — break and look for install button
138
+ break;
139
+ }
140
+
141
+ // Possible terminal states after the redirect chain:
142
+ // 1. /apps/{handle}* — app already installed at Shopify level. Done.
143
+ // 2. /oauth/install — fresh install, click "Install app".
144
+ // 3. /app/grant — scope change requested, click "Update".
145
+ const url = page.url();
146
+ if (url.includes(`/apps/${env.devAppHandle}`)) {
147
+ console.log(`[install] Landed on app page — installation already complete: ${url}`);
148
+ } else if (url.includes('/app/grant')) {
149
+ console.log('[install] Scope grant screen — clicking "Update"…');
150
+ await page.getByRole('button', { name: /^update$/i }).first().click();
151
+ await page.waitForURL((u) => u.toString().includes(`/apps/${env.devAppHandle}`), {
152
+ timeout: 90_000,
153
+ });
154
+ } else {
155
+ console.log('[install] Looking for "Install app" button…');
156
+ const installButton = page
157
+ .getByRole('button', { name: /^install app$|^install$/i })
158
+ .first();
159
+ await installButton.waitFor({ state: 'visible', timeout: 60_000 });
160
+ console.log('[install] Clicking "Install app"…');
161
+ await installButton.click();
162
+ console.log('[install] Waiting for OAuth callback + app load…');
163
+ await page.waitForURL((u) => u.toString().includes(`/apps/${env.devAppHandle}`), {
164
+ timeout: 90_000,
165
+ });
166
+ }
167
+ await page.waitForLoadState('domcontentloaded');
168
+
169
+ console.log('[install] ✓ Install completed');
170
+
171
+ store.appInstalled = true;
172
+ writeRegistry(reg);
173
+ console.log(`[install] Marked ${shop} as installed in registry.`);
174
+ } catch (err) {
175
+ console.error(`[install] Failed: ${(err as Error).message}`);
176
+ console.error(`Final URL: ${page.url()}`);
177
+ await page.screenshot({ path: 'tests/test-online/install-failure.png' }).catch(() => {});
178
+ console.error('Screenshot: tests/test-online/install-failure.png');
179
+ process.exit(1);
180
+ } finally {
181
+ await browser.close();
182
+ }
183
+ }
184
+
185
+ main().catch((err) => {
186
+ console.error(err);
187
+ process.exit(1);
188
+ });
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { readRegistry } from '@essential-apps/shopify-test-core';
3
+
4
+ const reg = readRegistry();
5
+ if (reg.stores.length === 0) {
6
+ console.log('Pool is empty. Run: npm run test:online:create -- --count 2');
7
+ process.exit(0);
8
+ }
9
+
10
+ console.log(`${reg.stores.length} store(s) in pool:`);
11
+ console.log('');
12
+ for (const s of reg.stores) {
13
+ console.log(` ${s.shop}`);
14
+ console.log(` plan : ${s.plan}`);
15
+ console.log(` created : ${s.createdAt ?? '(unknown)'}`);
16
+ console.log(` installed : ${s.appInstalled}`);
17
+ console.log(` status : ${s.status}`);
18
+ console.log('');
19
+ }
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * One-time interactive Shopify auth capture inside the test container.
4
+ *
5
+ * Why a separate script: tests run with the chromium browser invisible
6
+ * inside Xvfb, which means there's no way to interactively log in.
7
+ * This script starts the same container, exposes the Xvfb display via
8
+ * x11vnc on host port 5900, and opens macOS's built-in Screen Sharing
9
+ * (`vnc://localhost:5900`) so a developer can log in once. The
10
+ * resulting tests/test-online/.auth/storageState.json is bind-mounted into
11
+ * the project, so subsequent test runs use the captured cookies —
12
+ * bound to the container's Linux Chrome fingerprint, which is what
13
+ * Cloudflare expects to see during automated runs.
14
+ *
15
+ * Usage (one-time per developer machine, or whenever cookies expire):
16
+ * npm run test:online:capture-auth
17
+ *
18
+ * macOS Screen Sharing.app opens automatically; just log in to
19
+ * Shopify, wait until you see the Partner Dashboard, then hit Enter
20
+ * back in the terminal where this script is running.
21
+ */
22
+ import { spawn } from 'node:child_process';
23
+ import { existsSync, mkdirSync, readFileSync } from 'node:fs';
24
+ import { homedir, platform } from 'node:os';
25
+ import { resolve } from 'node:path';
26
+ import { setTimeout as sleep } from 'node:timers/promises';
27
+ import { envFileArgs } from '@essential-apps/shopify-test-core';
28
+ const repoRoot = process.cwd();
29
+ const VNC_PORT = 5900;
30
+
31
+ interface PackageJson {
32
+ name?: string;
33
+ }
34
+
35
+ function readAppName(): string {
36
+ const pkgPath = resolve(repoRoot, 'package.json');
37
+ if (!existsSync(pkgPath)) {
38
+ throw new Error(
39
+ `No package.json at ${pkgPath}. Run this from the consuming app's repo root.`,
40
+ );
41
+ }
42
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as PackageJson;
43
+ if (!pkg.name) throw new Error(`package.json at ${pkgPath} has no \`name\` field.`);
44
+ return pkg.name.replace(/^@[^/]+\//, '');
45
+ }
46
+
47
+ async function main(): Promise<void> {
48
+ const appName = readAppName();
49
+ const image = process.env['TEST_IMAGE'] ?? `${appName}-test:latest`;
50
+ const linuxModules =
51
+ process.env['TEST_LINUX_NODE_MODULES'] ??
52
+ resolve(homedir(), `.cache/${appName}-test/node_modules`);
53
+ const vncPassword = process.env['TEST_ONLINE_VNC_PASSWORD'] ?? 'test';
54
+
55
+ mkdirSync(linuxModules, { recursive: true });
56
+
57
+ const args = [
58
+ 'run',
59
+ '--rm',
60
+ '--arch',
61
+ 'amd64',
62
+ '--memory',
63
+ '4096M',
64
+ '--cpus',
65
+ '2',
66
+ '--publish',
67
+ `127.0.0.1:${VNC_PORT}:${VNC_PORT}`,
68
+ '--env',
69
+ 'TEST_ONLINE_VNC=1',
70
+ '--env',
71
+ `TEST_ONLINE_VNC_PASSWORD=${vncPassword}`,
72
+ '--mount',
73
+ `type=bind,source=${repoRoot},target=/workspace`,
74
+ '--mount',
75
+ `type=bind,source=${linuxModules},target=/workspace/node_modules`,
76
+ '-w',
77
+ '/workspace',
78
+ image,
79
+ 'bash',
80
+ '-c',
81
+ [
82
+ 'sleep 1',
83
+ `echo "[runDockerAuth] Container ready. VNC server should be on 127.0.0.1:${VNC_PORT}."`,
84
+ 'echo ""',
85
+ // captureAuth is now in @essential-apps/shopify-test-runner.
86
+ `node ${envFileArgs(repoRoot)} node_modules/@essential-apps/shopify-test-runner/dist/scripts/captureAuth.js`,
87
+ ].join(' && '),
88
+ ];
89
+
90
+ console.log(`[runDockerAuth] Starting container with VNC on 127.0.0.1:${VNC_PORT}…`);
91
+ console.log(`[runDockerAuth] VNC password (paste into Screen Sharing): ${vncPassword}`);
92
+ console.log('');
93
+ const p = spawn('container', args, { stdio: 'inherit' });
94
+
95
+ if (platform() === 'darwin') {
96
+ void (async () => {
97
+ await sleep(4_000);
98
+ // Embed the password in the URL (vnc://:<pw>@host) so Screen Sharing
99
+ // connects WITHOUT prompting — prefilled, not typed.
100
+ const vncUrl = `vnc://:${encodeURIComponent(vncPassword)}@localhost:${VNC_PORT}`;
101
+ console.log(`[runDockerAuth] Opening macOS Screen Sharing → vnc://localhost:${VNC_PORT} (password prefilled)`);
102
+ console.log(`[runDockerAuth] (If nothing opens, run manually: open '${vncUrl}')`);
103
+ spawn('open', [vncUrl], {
104
+ stdio: 'ignore',
105
+ detached: true,
106
+ }).unref();
107
+ })();
108
+ } else {
109
+ console.log(`[runDockerAuth] Connect any VNC viewer to localhost:${VNC_PORT}.`);
110
+ }
111
+
112
+ p.on('exit', (code) => process.exit(code ?? 0));
113
+ process.on('SIGINT', () => p.kill('SIGINT'));
114
+ process.on('SIGTERM', () => p.kill('SIGTERM'));
115
+ }
116
+
117
+ main().catch((err) => {
118
+ console.error(err);
119
+ process.exit(1);
120
+ });