-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmetadata-attr.test.js
More file actions
33 lines (30 loc) · 1.12 KB
/
metadata-attr.test.js
File metadata and controls
33 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const { expect } = require("chai");
const { createDOM } = require("./helpers/dom");
describe("metadata via data attribute", function () {
it("uses data-metadata-collector attribute", function (done) {
const dom = createDOM({
settings: { autoCollect: false },
beforeRun(vmContext) {
const { runInContext } = require("vm");
runInContext(
"window.collector = function(data){ return { fromAttr: true, path: data.path }; };" +
"Object.defineProperty(document, 'currentScript', {get: function(){ return { getAttribute: function(name){ return name === 'data-metadata-collector' ? 'collector' : null; } }; }});",
vmContext
);
},
});
dom.window.sa_pageview("/attr");
setTimeout(() => {
const req = dom.sent.find(
(r) => r.type === "image" && /path=%2Fattr/.test(r.url)
);
expect(req, "pageview request").to.exist;
const url = new URL(req.url);
const meta = JSON.parse(
decodeURIComponent(url.searchParams.get("metadata"))
);
expect(meta).to.include({ fromAttr: true });
done();
}, 10);
});
});