Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions packages/renderers/harness/browser/diff.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {settled} from './settled.js'
* sideways overflow. Set `PROJECTIONS_DIFF_SCREENSHOTS` to a directory to save
* a screenshot of each at 1440 and 390 pixels.
*/
const renderers = ['graph', 'database', 'dependency-injection', 'code-statistics', 'runtime-policy', 'api', 'agentic-workflows']
const renderers = new Set(['graph', 'database', 'dependency-injection', 'code-statistics', 'runtime-policy', 'api', 'agentic-workflows'])
const shots = process.env.PROJECTIONS_DIFF_SCREENSHOTS
/** A comparison per renderer name whose diff is worth a picture; the first of each package otherwise. */
const pictured = new Set([
Expand All @@ -33,38 +33,36 @@ const pictured = new Set([
'agentic-workflows/docs-bot',
])

for (const directory of renderers) {
test(`${directory}: diff mode marks every change in its own form`, async ({page}, info) => {
test.slow()
// One test per scenario, so each has a scenario's budget and the shards share the renderers with the most scenarios: a
// test per renderer walked all 34 graph scenarios in both color modes and outgrew `test.slow()` on CI's Linux WebKit.
for (const {key} of scenarios.filter(item => renderers.has(item.directory))) {
test(`${key}: diff mode marks every change in its own form`, async ({page}, info) => {
const inspector = harnessInspector()
const mobile = info.project.name.endsWith('mobile')
const keys = scenarios.filter(item => item.directory === directory).map(item => item.key)
for (const key of keys) {
for (const colorMode of ['light', 'dark'] as const) {
const stage = await openStage(page, inspector, {scenario: key, comparisonMode: 'diff', colorMode})
const state = await stage.state()
if (state.comparisonMode !== 'diff') continue
expect(state.capabilities?.comparisonModes, key).toContain('diff')
await stage.measure('settle')
const marks = await stage.frame.locator('[data-entity-id][data-change], [data-change] [data-entity-id]').count()
// Every renderer leaves its summary to the host's summary bar: kind counts with their changes, and its domain facts.
const summary = await stage.frame.locator('.pk-diff-summary, .graph-summary, .api-compatibility-counts').count()
expect(summary, `${key}: no summary row; the host's summary bar counts the changes`).toBe(0)
await expect.poll(async () => ((await stage.state()).summary ?? []).length, `${key}: a summary for the host`).toBeGreaterThan(0)
expect(marks, `${key}: changes are marked in place`).toBeGreaterThan(0)
const overflow = await stage.frame.locator('html').evaluate(root => root.scrollWidth - root.clientWidth)
expect(overflow, `${key} (${colorMode}): no sideways overflow`).toBeLessThanOrEqual(1)
if (shots && pictured.has(key) && info.project.name.startsWith('chromium')) {
mkdirSync(shots, {recursive: true})
const width = mobile ? 390 : 1440
await page.setViewportSize({width, height: mobile ? 844 : 900})
// The frame takes the new width and the renderer refits before the picture.
await settled(async () => {
await stage.measure('settle')
return stage.frame.locator('body').evaluate(body => [innerWidth, body.scrollWidth, body.scrollHeight])
})
await stage.frame.locator('body').screenshot({path: `${shots}/${key.replace('/', '-')}-${colorMode}-${width}.png`})
}
for (const colorMode of ['light', 'dark'] as const) {
const stage = await openStage(page, inspector, {scenario: key, comparisonMode: 'diff', colorMode})
const state = await stage.state()
if (state.comparisonMode !== 'diff') continue
expect(state.capabilities?.comparisonModes, key).toContain('diff')
await stage.measure('settle')
const marks = await stage.frame.locator('[data-entity-id][data-change], [data-change] [data-entity-id]').count()
// Every renderer leaves its summary to the host's summary bar: kind counts with their changes, and its domain facts.
const summary = await stage.frame.locator('.pk-diff-summary, .graph-summary, .api-compatibility-counts').count()
expect(summary, `${key}: no summary row; the host's summary bar counts the changes`).toBe(0)
await expect.poll(async () => ((await stage.state()).summary ?? []).length, `${key}: a summary for the host`).toBeGreaterThan(0)
expect(marks, `${key}: changes are marked in place`).toBeGreaterThan(0)
const overflow = await stage.frame.locator('html').evaluate(root => root.scrollWidth - root.clientWidth)
expect(overflow, `${key} (${colorMode}): no sideways overflow`).toBeLessThanOrEqual(1)
if (shots && pictured.has(key) && info.project.name.startsWith('chromium')) {
mkdirSync(shots, {recursive: true})
const width = mobile ? 390 : 1440
await page.setViewportSize({width, height: mobile ? 844 : 900})
// The frame takes the new width and the renderer refits before the picture.
await settled(async () => {
await stage.measure('settle')
return stage.frame.locator('body').evaluate(body => [innerWidth, body.scrollWidth, body.scrollHeight])
})
await stage.frame.locator('body').screenshot({path: `${shots}/${key.replace('/', '-')}-${colorMode}-${width}.png`})
}
}
})
Expand Down