Skip to content

Commit

Permalink
rum-recorder: import rrweb-snapshot code (#700)
Browse files Browse the repository at this point in the history
* rum-recorder: import rrweb-snapshot code

This commit removes the dependency on rrweb-snapshot and instead adds
the code directly, changing the imports accordingly.

* licenses: update 3p following embedding of rrweb-snapshot

* rum-recorder: remove unused code in rrweb-snapshot

* rum-recorder: address eslint issues

* rum-recorder: capitalize first letter of types

* rum-recorder: replace string.match() by RegExp.test()

* rum-recorder: add rrweb-snapshot unit tests

* rum-recorder: remove unused types
  • Loading branch information
vlad-mh authored Feb 2, 2021
1 parent 353f6dc commit 3e204dc
Show file tree
Hide file tree
Showing 13 changed files with 770 additions and 16 deletions.
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Component,Origin,License,Copyright
require,tslib,Apache-2.0,Copyright Microsoft Corporation
file,pako,MIT,(C) 2014-2017 Vitaly Puzrin and Andrey Tupitsin
file,rrweb,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb/graphs/contributors) and SmartX Inc.
file,rrweb-snapshot,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb-snapshot/graphs/contributors) and SmartX Inc.
file,tracekit,MIT,Copyright 2013 Onur Can Cakmak and all TraceKit contributors
prod,rrweb-snapshot,MIT,Copyright (c) 2018 Contributors (https://github.com/rrweb-io/rrweb-snapshot/graphs/contributors) and SmartX Inc.
dev,@types/connect-busboy,MIT,Copyright Microsoft Corporation
dev,@types/cors,MIT,Copyright Microsoft Corporation
dev,@types/express,MIT,Copyright Microsoft Corporation
Expand Down
1 change: 0 additions & 1 deletion packages/rum-recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"dependencies": {
"@datadog/browser-core": "2.4.0",
"@datadog/browser-rum-core": "2.4.0",
"rrweb-snapshot": "1.0.1",
"tslib": "^1.10.0"
},
"repository": {
Expand Down
4 changes: 4 additions & 0 deletions packages/rum-recorder/src/domain/rrweb-snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { serializeNodeWithId, transformAttribute, IGNORED_NODE, snapshot } from './snapshot'
export * from './types'

export { snapshot, serializeNodeWithId, transformAttribute, IGNORED_NODE }
75 changes: 75 additions & 0 deletions packages/rum-recorder/src/domain/rrweb-snapshot/snapshot.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* eslint-disable max-len */
import { absoluteToStylesheet } from './snapshot'

describe('absolute url to stylesheet', () => {
const href = 'http://localhost/css/style.css'

it('can handle relative path', () => {
expect(absoluteToStylesheet('url(a.jpg)', href)).toEqual(`url(http://localhost/css/a.jpg)`)
})

it('can handle same level path', () => {
expect(absoluteToStylesheet('url("./a.jpg")', href)).toEqual(`url("http://localhost/css/a.jpg")`)
})

it('can handle parent level path', () => {
expect(absoluteToStylesheet('url("../a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle absolute path', () => {
expect(absoluteToStylesheet('url("/a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle external path', () => {
expect(absoluteToStylesheet('url("http://localhost/a.jpg")', href)).toEqual(`url("http://localhost/a.jpg")`)
})

it('can handle single quote path', () => {
expect(absoluteToStylesheet(`url('./a.jpg')`, href)).toEqual(`url('http://localhost/css/a.jpg')`)
})

it('can handle no quote path', () => {
expect(absoluteToStylesheet('url(./a.jpg)', href)).toEqual(`url(http://localhost/css/a.jpg)`)
})

it('can handle multiple no quote paths', () => {
expect(
absoluteToStylesheet(
'background-image: url(images/b.jpg);background: #aabbcc url(images/a.jpg) 50% 50% repeat;',
href
)
).toEqual(
`background-image: url(http://localhost/css/images/b.jpg);` +
`background: #aabbcc url(http://localhost/css/images/a.jpg) 50% 50% repeat;`
)
})

it('can handle data url image', () => {
expect(absoluteToStylesheet('url(data:image/gif;base64,ABC)', href)).toEqual('url(data:image/gif;base64,ABC)')
expect(absoluteToStylesheet('url(data:application/font-woff;base64,d09GMgABAAAAAAm)', href)).toEqual(
'url(data:application/font-woff;base64,d09GMgABAAAAAAm)'
)
})

it('preserves quotes around inline svgs with spaces', () => {
expect(
absoluteToStylesheet(
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")",
href
)
).toEqual(
"url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3E%3Cpath fill='%2328a745' d='M3'/%3E%3C/svg%3E\")"
)
expect(
absoluteToStylesheet(
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')',
href
)
).toEqual(
'url(\'data:image/svg+xml;utf8,<svg width="28" height="32" viewBox="0 0 28 32" xmlns="http://www.w3.org/2000/svg"><path d="M27 14C28" fill="white"/></svg>\')'
)
})
it('can handle empty path', () => {
expect(absoluteToStylesheet(`url('')`, href)).toEqual(`url('')`)
})
})
Loading

0 comments on commit 3e204dc

Please sign in to comment.