@epic-web/workshop-utils 4.26.2 → 4.27.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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { expect, test } from '@playwright/test';
|
|
2
2
|
import crossSpawn from 'cross-spawn';
|
|
3
3
|
import z from 'zod';
|
|
4
|
-
import { getApps,
|
|
4
|
+
import { getApps, isSolutionApp } from './apps.server.js';
|
|
5
5
|
export async function getInBrowserTestPages() {
|
|
6
6
|
const apps = (await getApps())
|
|
7
|
-
.filter(
|
|
7
|
+
.filter(isSolutionApp)
|
|
8
8
|
.filter((a) => a.test.type === 'browser');
|
|
9
9
|
const pages = apps.map((app) => {
|
|
10
10
|
if (app.test.type !== 'browser')
|
|
@@ -38,7 +38,7 @@ async function waitFor(cb, { timeout = 1000, interval = 30 } = {}) {
|
|
|
38
38
|
}
|
|
39
39
|
export function setupInBrowserTests() {
|
|
40
40
|
// doing this because playwright needs the tests to be registered synchoronously
|
|
41
|
-
const code = `import('@epic-web/workshop-utils/playwright.server').then(({ getInBrowserTestPages }) => getInBrowserTestPages().then(r => console.log(JSON.stringify(r))))`;
|
|
41
|
+
const code = `import('@epic-web/workshop-utils/playwright.server').then(({ getInBrowserTestPages }) => getInBrowserTestPages().then(r => console.log(JSON.stringify(r)))).catch(e => {console.error(e);throw e;})`;
|
|
42
42
|
const result = crossSpawn.sync('node', ['--eval', code], {
|
|
43
43
|
encoding: 'utf-8',
|
|
44
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"playwright.server.js","sourceRoot":"","sources":["../../src/playwright.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,UAAU,MAAM,aAAa,CAAA;AACpC,OAAO,CAAC,MAAM,KAAK,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"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AAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,EAAE;oBAC/D,OAAO,EAAE,MAAM;iBACf,CAAC;gBACF,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;oBAClD,OAAO,EAAE,MAAM;iBACf,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;oBAClB,MAAM,MAAM,CAAA;gBACb,CAAC,CAAC;aACF,CAAC,CAAA;YACF,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QACzC,CAAC,CAAC,CAAA;IACH,CAAC;AACF,CAAC","sourcesContent":["import { expect, test } from '@playwright/test'\nimport crossSpawn from 'cross-spawn'\nimport z from 'zod'\nimport { getApps, isSolutionApp } from './apps.server.js'\n\nexport async function getInBrowserTestPages() {\n\tconst apps = (await getApps())\n\t\t.filter(isSolutionApp)\n\t\t.filter((a) => a.test.type === 'browser')\n\tconst pages = apps.map((app) => {\n\t\tif (app.test.type !== 'browser') return null\n\t\tconst { pathname } = app.test\n\t\treturn app.test.testFiles.map((testFile) => {\n\t\t\treturn {\n\t\t\t\tpath: `${pathname}${testFile}`,\n\t\t\t\ttestFile,\n\t\t\t}\n\t\t})\n\t})\n\treturn pages.filter(Boolean).flat()\n}\n\nconst sleep = (time: number) =>\n\tnew Promise((resolve) => setTimeout(resolve, time))\n\nasync function waitFor<ReturnValue>(\n\tcb: () => ReturnValue | Promise<ReturnValue> | undefined | null,\n\t{ timeout = 1000, interval = 30 } = {},\n) {\n\tconst timeEnd = Date.now() + timeout\n\tlet lastError: unknown | null = null\n\twhile (Date.now() < timeEnd) {\n\t\ttry {\n\t\t\tconst result = await cb()\n\t\t\tif (result) return result\n\t\t} catch (error) {\n\t\t\tlastError = error\n\t\t}\n\t\tawait sleep(interval)\n\t}\n\tthrow lastError || new Error(`waitFor timed out after ${timeout}ms`)\n}\n\nexport function setupInBrowserTests() {\n\t// doing this because playwright needs the tests to be registered synchoronously\n\tconst code = `import('@epic-web/workshop-utils/playwright.server').then(({ getInBrowserTestPages }) => getInBrowserTestPages().then(r => console.log(JSON.stringify(r)))).catch(e => {console.error(e);throw e;})`\n\tconst result = crossSpawn.sync('node', ['--eval', code], {\n\t\tencoding: 'utf-8',\n\t})\n\tif (result.status !== 0) {\n\t\tconsole.error(result.output.join('\\n'))\n\t\tthrow new Error(\n\t\t\t`Failed to get in-browser test pages. Status: ${result.status}.`,\n\t\t)\n\t}\n\tconst testPages = z\n\t\t.array(z.object({ path: z.string() }))\n\t\t.parse(JSON.parse(result.stdout))\n\n\tfor (const testPage of testPages) {\n\t\ttest(testPage.path, async ({ page }) => {\n\t\t\tconst errors: Array<string> = []\n\t\t\tconst logs: Array<string> = []\n\t\t\tconst infos: Array<string> = []\n\t\t\tpage.on('console', (message) => {\n\t\t\t\tswitch (message.type()) {\n\t\t\t\t\tcase 'error': {\n\t\t\t\t\t\terrors.push(message.text())\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'log': {\n\t\t\t\t\t\tlogs.push(message.text())\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase 'info': {\n\t\t\t\t\t\tinfos.push(message.text())\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\tawait page.goto(testPage.path)\n\t\t\tawait page.waitForLoadState()\n\t\t\tawait waitFor(\n\t\t\t\t() => infos.find((info) => info.includes('status: pending')),\n\t\t\t\t{ timeout: 10_000 },\n\t\t\t)\n\t\t\tconst result = await Promise.race([\n\t\t\t\twaitFor(() => logs.find((log) => log.includes('status: pass')), {\n\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t}),\n\t\t\t\twaitFor(() => (errors.length > 0 ? errors : null), {\n\t\t\t\t\ttimeout: 10_000,\n\t\t\t\t}).then((errors) => {\n\t\t\t\t\tthrow errors\n\t\t\t\t}),\n\t\t\t])\n\t\t\texpect(result).toContain('status: pass')\n\t\t})\n\t}\n}\n"]}
|