Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use non-forked rrweb #34

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion __playwright-tests__/archiving-assets.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from '../src';

test('asset paths', async ({ page }) => {
await page.goto('/asset-paths');
await page.goto('/asset-paths/');
});
1 change: 1 addition & 0 deletions __playwright-tests__/fixtures/asset-paths.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<div><img src="/img?url=fixtures/pink.png"/></div>
<div><img src="/img"/></div>
<div><img src="/img/another"/></div>
<div><img src="relative/purple.png"/></div>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thafryer added that relative path test for AP-3789

<div><img src="/blahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahbblahblahblahblahblahblahblahblahblahblahb"></div>
<div><img src="https://www.chromatic.com/emails/icon-chroma-64x64.png?test=query"/></div>
<div class="with-background-img"></div>
Expand Down
4 changes: 4 additions & 0 deletions __playwright-tests__/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ app.get('/img/another', (req, res) => {
res.sendFile(path.join(__dirname, 'fixtures/pink.png'));
});

app.get('/asset-paths/relative/purple.png', (req, res) => {
res.sendFile(path.join(__dirname, 'fixtures/purple.png'));
});

app.get('/background-img.png', (req, res) => {
res.sendFile(path.join(__dirname, 'fixtures/purple.png'));
});
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.21.4",
"@chromaui/archive-storybook": "^0.0.15",
"@chromaui/test-archiver": "^0.0.32",
"@jest/types": "^27.0.6",
"@playwright/test": "^1.39.0",
"@storybook/addon-essentials": "^7.5.2",
Expand Down Expand Up @@ -97,10 +96,10 @@
"access": "public"
},
"dependencies": {
"@chromaui/rrweb-snapshot": "2.0.0-alpha.7-noAbsolute.2",
"@segment/analytics-node": "^1.1.0",
"fs-extra": "^11.1.1",
"mime": "^3.0.0",
"rrweb-snapshot": "^2.0.0-alpha.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rrweb is up to like alpha.11, but alpha.4 is the one published as latest.

"ts-dedent": "^2.2.0"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/cypress-api/commands.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { snapshot } from '@chromaui/rrweb-snapshot';
import type { elementNode } from '@chromaui/rrweb-snapshot';
import { snapshot } from 'rrweb-snapshot';
import type { elementNode } from 'rrweb-snapshot';
// @ts-expect-error will fix when Cypress has its own package
Cypress.Commands.add('takeChromaticArchive', () => {
cy.document().then((doc) => {
// here, handle the source map
const manualSnapshot = snapshot(doc, { noAbsolute: true });
const manualSnapshot = snapshot(doc);
// reassign manualSnapshots so it includes this new snapshot
cy.get('@manualSnapshots')
// @ts-expect-error will fix when Cypress has its own package
Expand Down
2 changes: 1 addition & 1 deletion src/cypress-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { elementNode } from '@chromaui/rrweb-snapshot';
import type { elementNode } from 'rrweb-snapshot';
import { writeTestResult } from '../write-archive';
import type { ChromaticStorybookParameters } from '../types';
import type { ResourceArchive } from '../resource-archive';
Expand Down
4 changes: 2 additions & 2 deletions src/cypress-api/support.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { snapshot } from '@chromaui/rrweb-snapshot';
import { snapshot } from 'rrweb-snapshot';
import type { ResourceArchive } from '../resource-archive';
import './commands';

Expand Down Expand Up @@ -55,7 +55,7 @@ const completeArchive = () => {
cy.get('@archive').then((archive) => {
// can we be sure this always fires after all the requests are back?
cy.document().then((doc) => {
const snap = snapshot(doc, { noAbsolute: true });
const snap = snapshot(doc);
// @ts-expect-error will fix when Cypress has its own package
cy.get('@manualSnapshots').then((manualSnapshots = []) => {
// pass the snapshot to the server to write to disk
Expand Down
9 changes: 3 additions & 6 deletions src/playwright-api/takeArchive.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import type { Page, TestInfo } from '@playwright/test';
import { readFileSync } from 'fs';
import type { elementNode } from '@chromaui/rrweb-snapshot';
import type { elementNode } from 'rrweb-snapshot';

import dedent from 'ts-dedent';

import { logger } from '../utils/logger';

const rrweb = readFileSync(
require.resolve('@chromaui/rrweb-snapshot/dist/rrweb-snapshot.js'),
'utf8'
);
const rrweb = readFileSync(require.resolve('rrweb-snapshot/dist/rrweb-snapshot.js'), 'utf8');

export const contentType = 'application/rrweb.snapshot+json';

Expand Down Expand Up @@ -39,7 +36,7 @@ async function takeArchive(
// Serialize and capture the DOM
const domSnapshot: elementNode = await page.evaluate(dedent`
${rrweb};
rrwebSnapshot.snapshot(document, { noAbsolute: true });
rrwebSnapshot.snapshot(document);
`);

testInfo.attach(name, { contentType, body: JSON.stringify(domSnapshot) });
Expand Down
2 changes: 1 addition & 1 deletion src/write-archive/archive-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('ArchiveFile', () => {
archiveFile.toFileSystemPath();
const originalSrc = archiveFile.originalSrc();

expect(originalSrc).toEqual('/some/directory/ok?src=some-other-url');
expect(originalSrc).toEqual('http://localhost:333/some/directory/ok?src=some-other-url');
});
});
});
3 changes: 1 addition & 2 deletions src/write-archive/archive-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export class ArchiveFile {
}

originalSrc() {
// Assets that we capture will be stripped of the domain in the source
return `${this.url.pathname}${this.url.search}`;
return this.url.toString();
Copy link
Contributor Author

@tevanoff tevanoff Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change required after all of the previous asset mapping work. We're now expecting all asset paths to be full URLs since that's what rrweb does, so we don't strip off the protocol and origin here anymore.

}

toFileSystemPath() {
Expand Down
4 changes: 2 additions & 2 deletions src/write-archive/dom-snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-param-reassign */
import type { serializedNodeWithId } from '@chromaui/rrweb-snapshot';
import { NodeType } from '@chromaui/rrweb-snapshot';
import type { serializedNodeWithId } from 'rrweb-snapshot';
import { NodeType } from 'rrweb-snapshot';

// Matches `url(...)` function in CSS text, excluding data URLs
const CSS_URL_REGEX = /url\((?!['"]?(?:data):)['"]?([^'")]*)['"]?\)/gi;
Expand Down
6 changes: 3 additions & 3 deletions src/write-archive/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import { resolve } from 'path';
import type { TestInfo } from '@playwright/test';
import { NodeType } from '@chromaui/rrweb-snapshot';
import { NodeType } from 'rrweb-snapshot';
import { writeTestResult } from '.';

jest.mock('fs-extra');
Expand All @@ -11,13 +11,13 @@ const snapshotJson = {
{
type: NodeType.Element,
attributes: {
src: '/home/',
src: 'http://localhost:3000/home/',
},
},
{
type: NodeType.Element,
attributes: {
src: '/img?src=some-path',
src: 'http://localhost:3000/img?src=some-path',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we save the URLs like this in the archives or as relative paths? If we save as absolutes, that would be a non-starter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asset archive is built by watching network requests, so they are always the full URL there. This change makes it easier to match the assets from the archive with the attributes in the DOM since both sides will be full URLs now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me rephrase my question.

What happens when you render in the Capture Cloud? Do the archives try to pull from a relative path or http://localhost:3000? The localhost lookup will not work in the capture cloud so those need to be replaced by relative paths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, they are relative in the archive storybook so that they load from the capture cloud. Otherwise all the images in the build would be broken!

},
},
],
Expand Down
16 changes: 5 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2052,17 +2052,6 @@
resolved "https://registry.npmjs.org/@chromaui/rrweb-snapshot/-/rrweb-snapshot-2.0.0-alpha.7-noAbsolute.2.tgz"
integrity sha512-vOVSOgfNyxomxm6ENMqm1C4rLkLLOlyEyhR5J2SKBALuFfuJHjhIqNLSOgqVRO9J3++AUOCktknyJ/F+mSvEfA==

"@chromaui/test-archiver@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@chromaui/test-archiver/-/test-archiver-0.0.32.tgz#6e0560b39108581b9d3d55d3f5e462350b3cda9c"
integrity sha512-O6le42KqoliioAQG2RY+XhrwSttwnYHV2lIk3TNKJ1l9sTjQT5AUAZJ6N4CkUAsU8TVtX8wEDUY0mrNL00M/DQ==
dependencies:
"@chromaui/rrweb-snapshot" "2.0.0-alpha.7-noAbsolute.2"
"@segment/analytics-node" "^1.1.0"
fs-extra "^11.1.1"
mime "^3.0.0"
ts-dedent "^2.2.0"

"@colors/[email protected]":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
Expand Down Expand Up @@ -11571,6 +11560,11 @@ rollup@^3.2.5:
optionalDependencies:
fsevents "~2.3.2"

rrweb-snapshot@^2.0.0-alpha.4:
version "2.0.0-alpha.4"
resolved "https://registry.yarnpkg.com/rrweb-snapshot/-/rrweb-snapshot-2.0.0-alpha.4.tgz#2801bf5946177b9d685a01661a62d9d2e958f174"
integrity sha512-KQ2OtPpXO5jLYqg1OnXS/Hf+EzqnZyP5A+XPqBCjYpj3XIje/Od4gdUwjbFo3cVuWq5Cw5Y1d3/xwgIS7/XpQQ==

run-parallel@^1.1.9:
version "1.2.0"
resolved "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz"
Expand Down
Loading