Skip to content

Commit

Permalink
#8596 improve definition diffing (#8778)
Browse files Browse the repository at this point in the history
* Improve mod definition snapshot diffing

Switching to using textual diffing for easier and more concise
visual comparisons

* fiezes
  • Loading branch information
fungairino authored Jul 9, 2024
1 parent a98eb0e commit 1dcc399
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 49 deletions.
29 changes: 21 additions & 8 deletions end-to-end-tests/fixtures/modDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import { expect } from "@playwright/test";
import { test as pageContextFixture } from "./pageContext";
import { WorkshopPage } from "../pageObjects/extensionConsole/workshop/workshopPage";
import diff from "deep-diff";
import { loadBrickYaml } from "@/runtime/brickYaml";
import { createPatch } from "diff";
import { dumpBrickYaml, loadBrickYaml } from "@/runtime/brickYaml";

// The mod definitions are a map of mod names to their test metadata
type ModDefinitions = Record<
Expand Down Expand Up @@ -141,14 +141,27 @@ export const test = pageContextFixture.extend<{
currentModDefinitionYaml,
);
const parsedLastModDefinitionYaml = loadBrickYaml(lastModDefinition);
const yamlDiff =
diff(parsedLastModDefinitionYaml, parsedCurrentModDefinitionYaml) ||
[];

expect(JSON.stringify(yamlDiff, undefined, 2) + "\n").toMatchSnapshot(
snapshotName + ".json",
const yamlDiff = createPatch(
snapshotName,
normalizeUUIDs(
dumpBrickYaml(parsedLastModDefinitionYaml, {
indent: 2,
sortKeys: true,
}),
),
normalizeUUIDs(
dumpBrickYaml(parsedCurrentModDefinitionYaml, {
indent: 2,
sortKeys: true,
}),
),
undefined,
undefined,
{ context: 40 },
);

expect(yamlDiff).toMatchSnapshot(snapshotName + ".diff");

// Update the mod definition to the last known state
modDefinitionsMap[modDefinitionName] = {
id: modId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Index: description-change
===================================================================
--- description-change
+++ description-change
@@ -23,52 +23,52 @@
body:
- config:
body:
- children:
- children:
- children:
- config:
heading: h1
title: !nunjucks Simple Sidebar Panel
type: header
config: {}
type: column
config: {}
type: row
- children:
- children:
- config:
enableMarkdown: true
text: !nunjucks >-
Simple sidebar panel for testing sidepanel
open/close behavior
type: text
config: {}
type: column
config: {}
type: row
config: {}
type: container
id: '@pixiebrix/document'
root: null
rootMode: document
heading: Simple Sidebar Panel
id: extensionPoint
label: Simple Sidebar Panel
permissions:
origins: []
permissions: []
services: {}
kind: recipe
metadata:
- description: Created with the PixieBrix Page Editor
+ description: Created in end to end tests
id: >-
@extension-e2e-test-unaffiliated/simple-sidebar-panel-00000000-0000-0000-0000-000000000000
name: Simple Sidebar Panel
version: 1.0.0
options:
schema:
properties: {}
type: object
uiSchema:
ui:order:
- '*'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Index: heading-change
===================================================================
--- heading-change
+++ heading-change
@@ -14,61 +14,61 @@
urlPatterns: []
reader:
- '@pixiebrix/document-metadata'
- '@pixiebrix/document-context'
trigger: load
type: actionPanel
kind: extensionPoint
extensionPoints:
- config:
body:
- config:
body:
- children:
- children:
- children:
- config:
heading: h1
title: !nunjucks Simple Sidebar Panel
type: header
config: {}
type: column
config: {}
type: row
- children:
- children:
- config:
enableMarkdown: true
text: !nunjucks >-
Simple sidebar panel for testing sidepanel
open/close behavior
type: text
config: {}
type: column
config: {}
type: row
config: {}
type: container
id: '@pixiebrix/document'
root: null
rootMode: document
- heading: Simple Sidebar Panel
+ heading: Simple Sidebar Panel -- Updated
id: extensionPoint
label: Simple Sidebar Panel
permissions:
origins: []
permissions: []
services: {}
kind: recipe
metadata:
description: Created in end to end tests
id: >-
@extension-e2e-test-unaffiliated/simple-sidebar-panel-00000000-0000-0000-0000-000000000000
name: Simple Sidebar Panel
version: 1.0.0
options:
schema:
properties: {}
type: object
uiSchema:
ui:order:
- '*'

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Index: no-changes
===================================================================
--- no-changes
+++ no-changes

This file was deleted.

31 changes: 17 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
"@testing-library/user-event": "^14.5.2",
"@total-typescript/ts-reset": "^0.5.1",
"@types/chrome": "^0.0.268",
"@types/deep-diff": "^1.0.5",
"@types/diff": "^5.2.1",
"@types/dom-navigation": "^1.0.3",
"@types/dompurify": "^3.0.5",
"@types/downloadjs": "^1.4.6",
Expand Down Expand Up @@ -258,7 +258,7 @@
"csp-parse": "0.0.2",
"css-loader": "^6.11.0",
"css-minimizer-webpack-plugin": "^7.0.0",
"deep-diff": "^1.0.2",
"diff": "^5.2.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-pixiebrix": "^0.39.0",
Expand Down

0 comments on commit 1dcc399

Please sign in to comment.