@xylabs/sdk-meta 5.0.33 → 5.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -3
- package/dist/neutral/html/spec/mergeDocumentHead.approval.spec.d.ts +0 -2
- package/dist/neutral/html/spec/mergeDocumentHead.approval.spec.d.ts.map +0 -1
- package/dist/neutral/html/spec/mergeDocumentHead.spec.d.ts +0 -2
- package/dist/neutral/html/spec/mergeDocumentHead.spec.d.ts.map +0 -1
- package/dist/neutral/lib/spec/getMetaAsDict.spec.d.ts +0 -2
- package/dist/neutral/lib/spec/getMetaAsDict.spec.d.ts.map +0 -1
- package/dist/neutral/spec/builder.spec.d.ts +0 -2
- package/dist/neutral/spec/builder.spec.d.ts.map +0 -1
- package/src/html/spec/__snapshots__/mergeDocumentHead.approval.spec.ts.snap +0 -23
- package/src/html/spec/mergeDocumentHead.approval.spec.ts +0 -25
- package/src/html/spec/mergeDocumentHead.spec.ts +0 -50
- package/src/lib/spec/getMetaAsDict.spec.ts +0 -20
- package/src/spec/__snapshots__/builder.spec.ts.snap +0 -94
- package/src/spec/builder.spec.ts +0 -130
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/sdk-meta",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.35",
|
|
4
4
|
"description": "Base functionality used throughout XYO TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"meta",
|
|
@@ -34,10 +34,13 @@
|
|
|
34
34
|
"types": "./dist/neutral/index.d.ts",
|
|
35
35
|
"files": [
|
|
36
36
|
"dist",
|
|
37
|
-
"src"
|
|
37
|
+
"src",
|
|
38
|
+
"!**/*.bench.*",
|
|
39
|
+
"!**/*.spec.*",
|
|
40
|
+
"!**/*.test.*"
|
|
38
41
|
],
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@xylabs/typeof": "~5.0.
|
|
43
|
+
"@xylabs/typeof": "~5.0.35",
|
|
41
44
|
"cheerio": "~1.1.2"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDocumentHead.approval.spec.d.ts","sourceRoot":"","sources":["../../../../src/html/spec/mergeDocumentHead.approval.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mergeDocumentHead.spec.d.ts","sourceRoot":"","sources":["../../../../src/html/spec/mergeDocumentHead.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getMetaAsDict.spec.d.ts","sourceRoot":"","sources":["../../../../src/lib/spec/getMetaAsDict.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"builder.spec.d.ts","sourceRoot":"","sources":["../../../src/spec/builder.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`mergeDocumentHead > with real documents 1`] = `
|
|
4
|
-
"<!DOCTYPE html><html lang="en"><head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<link rel="icon" href="/favicon.ico">
|
|
7
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
8
|
-
<meta name="description" content="Your Data, Forever Long.">
|
|
9
|
-
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
10
|
-
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="">
|
|
11
|
-
<link href="https://fonts.googleapis.com/css2?family=Roboto+Flex:wght@300;400;500;600;800&display=swap" rel="stylesheet">
|
|
12
|
-
<link rel="apple-touch-icon" href="/foreventory-logo-icon-black.png">
|
|
13
|
-
<link rel="manifest" href="/manifest.json">
|
|
14
|
-
<title>Foreventory</title>
|
|
15
|
-
<script defer="defer" src="/static/js/main.297e104a.js"></script>
|
|
16
|
-
<meta content="website" property="og:type" data-react-helmet="true"><meta property="og:image" content="/netflix/insights/6f088236519e8e0c9ab9294c2e59fb2b8b434091a7559401ae860ff445fb1355/share/1600/900"><meta property="og:image:height" content="900"><meta property="og:image:secure_url" content="/netflix/insights/6f088236519e8e0c9ab9294c2e59fb2b8b434091a7559401ae860ff445fb1355/share/1600/900"><meta property="og:image:type" content="image/png"><meta property="og:image:url" content="/netflix/insights/6f088236519e8e0c9ab9294c2e59fb2b8b434091a7559401ae860ff445fb1355/share/1600/900"><meta property="og:image:width" content="1600"><meta property="twitter:image" content="/netflix/insights/6f088236519e8e0c9ab9294c2e59fb2b8b434091a7559401ae860ff445fb1355/share/1600/900"></head>
|
|
17
|
-
|
|
18
|
-
<body><noscript>You need to enable JavaScript to run this app.</noscript>
|
|
19
|
-
<div id="root"></div>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</body></html>"
|
|
23
|
-
`;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile } from 'node:fs/promises'
|
|
2
|
-
import Path from 'node:path'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
beforeAll,
|
|
6
|
-
describe, expect, it,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { mergeDocumentHead } from '../mergeDocumentHead.ts'
|
|
10
|
-
|
|
11
|
-
const writeDebugFile = false
|
|
12
|
-
|
|
13
|
-
describe('mergeDocumentHead', () => {
|
|
14
|
-
let destination: string
|
|
15
|
-
let source: string
|
|
16
|
-
beforeAll(async () => {
|
|
17
|
-
destination = await readFile(Path.join(__dirname, 'destination.html'), { encoding: 'utf8' })
|
|
18
|
-
source = await readFile(Path.join(__dirname, 'source.html'), { encoding: 'utf8' })
|
|
19
|
-
})
|
|
20
|
-
it('with real documents', async () => {
|
|
21
|
-
const result = mergeDocumentHead(destination, source)
|
|
22
|
-
expect(result).toMatchSnapshot()
|
|
23
|
-
if (writeDebugFile) await writeFile(Path.join(__dirname, 'result.html'), result)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @stylistic/max-len */
|
|
2
|
-
import {
|
|
3
|
-
describe, expect, it,
|
|
4
|
-
} from 'vitest'
|
|
5
|
-
|
|
6
|
-
import { mergeDocumentHead } from '../mergeDocumentHead.ts'
|
|
7
|
-
|
|
8
|
-
describe('mergeDocumentHead', () => {
|
|
9
|
-
const cases: [string, string, string, string][] = [
|
|
10
|
-
[
|
|
11
|
-
'Overwrites existing elements',
|
|
12
|
-
'<html><head><meta property="description" content="original"></head><body></body></html>',
|
|
13
|
-
'<html><head><meta property="description" content="updated"></head><body></body></html>',
|
|
14
|
-
'<html><head><meta property="description" content="updated"></head><body></body></html>',
|
|
15
|
-
],
|
|
16
|
-
[
|
|
17
|
-
'Merges unique elements',
|
|
18
|
-
'<html><head><meta property="og:title" content="original"></head><body></body></html>',
|
|
19
|
-
'<html><head><meta property="og:description" content="updated"></head><body></body></html>',
|
|
20
|
-
'<html><head><meta property="og:title" content="original"><meta property="og:description" content="updated"></head><body></body></html>',
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
'Overwrites existing elements & merges unique elements',
|
|
24
|
-
'<html><head><meta property="description" content="original"><meta property="og:title" content="original"></head><body></body></html>',
|
|
25
|
-
'<html><head><meta property="description" content="updated"><meta property="og:description" content="updated"></head><body></body></html>',
|
|
26
|
-
'<html><head><meta property="description" content="updated"><meta property="og:title" content="original"><meta property="og:description" content="updated"></head><body></body></html>',
|
|
27
|
-
],
|
|
28
|
-
[
|
|
29
|
-
'Handles missing head tag in source',
|
|
30
|
-
'<html><head><meta property="description" content="original"></head><body></body></html>',
|
|
31
|
-
'<html><body></body></html>',
|
|
32
|
-
'<html><head><meta property="description" content="original"></head><body></body></html>',
|
|
33
|
-
],
|
|
34
|
-
[
|
|
35
|
-
'Handles missing head tag in destination',
|
|
36
|
-
'<html><body></body></html>',
|
|
37
|
-
'<html><head><meta property="description" content="updated"></head><body></body></html>',
|
|
38
|
-
'<html><head><meta property="description" content="updated"></head><body></body></html>',
|
|
39
|
-
],
|
|
40
|
-
[
|
|
41
|
-
'Handles missing head tag in source & destination',
|
|
42
|
-
'<html><body>original</body></html>',
|
|
43
|
-
'<html><body>updated</body></html>',
|
|
44
|
-
'<html><head></head><body>original</body></html>',
|
|
45
|
-
],
|
|
46
|
-
]
|
|
47
|
-
it.each(cases)('%s', (_, a: string, b: string, expected: string) => {
|
|
48
|
-
expect(mergeDocumentHead(a, b)).toBe(expected)
|
|
49
|
-
})
|
|
50
|
-
})
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe, expect, it,
|
|
3
|
-
} from 'vitest'
|
|
4
|
-
|
|
5
|
-
import type { Meta } from '../../models/index.ts'
|
|
6
|
-
import { getMetaAsDict } from '../getMetaAsDict.ts'
|
|
7
|
-
|
|
8
|
-
describe('getMetaAsDict', () => {
|
|
9
|
-
const cases: Meta[] = [
|
|
10
|
-
{ description: 'description' },
|
|
11
|
-
{ twitter: { image: { '': 'twitter:image' } } },
|
|
12
|
-
]
|
|
13
|
-
it.each(cases)('Generates head meta', (meta: Meta) => {
|
|
14
|
-
const output = getMetaAsDict(meta)
|
|
15
|
-
expect(output).toBeDefined()
|
|
16
|
-
for (const [key, value] of Object.entries(output)) {
|
|
17
|
-
expect(key).toEqual(value)
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
})
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`builder > Adds meta > Open Graph (OG) 1`] = `
|
|
4
|
-
"<!DOCTYPE html><html lang="en"><head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<link rel="icon" href="/favicon.ico">
|
|
7
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
8
|
-
<meta name="theme-color" content="#000000">
|
|
9
|
-
<meta name="description" content="Own your piece of XYO's Decentralized Digital World!">
|
|
10
|
-
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
|
11
|
-
<link rel="manifest" href="/manifest.json">
|
|
12
|
-
<title>Death Valley Wilderness: Wilderness Light</title>
|
|
13
|
-
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans|Lexend+Deca|Rock+Salt|Source+Code+Pro&display=swap" rel="stylesheet">
|
|
14
|
-
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-795QBPW744"></script>
|
|
15
|
-
<script>function gtag() { dataLayer.push(arguments) } window.dataLayer = window.dataLayer || [], gtag("js", new Date), gtag("config", "G-795QBPW744")</script>
|
|
16
|
-
<style>
|
|
17
|
-
html {
|
|
18
|
-
overflow-y: auto;
|
|
19
|
-
overflow-x: hidden
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
#root,
|
|
23
|
-
body {
|
|
24
|
-
height: 100%;
|
|
25
|
-
width: 100%;
|
|
26
|
-
margin: 0;
|
|
27
|
-
padding: 0
|
|
28
|
-
}
|
|
29
|
-
</style>
|
|
30
|
-
<script defer="defer" src="/static/js/main.ae7f7033.js"></script>
|
|
31
|
-
<link href="/static/css/main.026e3fe6.css" rel="stylesheet">
|
|
32
|
-
<meta property="description" content="Follow the course of light through the Death Valley Wilderness and observe the obvious and subtle changes across the landscape.Produced by Sylvia JohnsonTo w..."><meta property="title" content="Death Valley Wilderness: Wilderness Light"><meta property="og:description" content="Follow the course of light through the Death Valley Wilderness and observe the obvious and subtle changes across the landscape.Produced by Sylvia JohnsonTo w..."><meta property="og:image" content="https://i.ytimg.com/vi/Kauv7MVPcsA/maxresdefault.jpg"><meta property="og:image:height" content="720"><meta property="og:image:width" content="1280"><meta property="og:site_name" content="YouTube"><meta property="og:title" content="Death Valley Wilderness: Wilderness Light"><meta property="og:type" content="video.other"><meta property="og:url" content="https://www.youtube.com/watch?v=Kauv7MVPcsA"><meta property="og:video:height" content="720"><meta property="og:video:secure_url" content="https://www.youtube.com/embed/Kauv7MVPcsA"><meta property="og:video:type" content="text/html"><meta property="og:video:url" content="https://www.youtube.com/embed/Kauv7MVPcsA"><meta property="og:video:width" content="1280"></head>
|
|
33
|
-
|
|
34
|
-
<body style="padding:0;margin:0;overflow-x:hidden"><noscript><iframe
|
|
35
|
-
src="https://www.googletagmanager.com/ns.html?id=GTM-W2TFNXL" height="0" width="0"
|
|
36
|
-
style="display:none;visibility:hidden"></iframe></noscript><noscript>You need to enable JavaScript to run this
|
|
37
|
-
app.</noscript>
|
|
38
|
-
<div id="root"></div>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
</body></html>"
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
exports[`builder > Adds meta > Twitter 1`] = `
|
|
45
|
-
"<!DOCTYPE html><html lang="en"><head>
|
|
46
|
-
<meta charset="utf-8">
|
|
47
|
-
<link rel="icon" href="/favicon.ico">
|
|
48
|
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
49
|
-
<meta name="theme-color" content="#000000">
|
|
50
|
-
<meta name="description" content="Own your piece of XYO's Decentralized Digital World!">
|
|
51
|
-
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
|
52
|
-
<link rel="manifest" href="/manifest.json">
|
|
53
|
-
<title>Death Valley Wilderness: Wilderness Light</title>
|
|
54
|
-
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans|Lexend+Deca|Rock+Salt|Source+Code+Pro&display=swap" rel="stylesheet">
|
|
55
|
-
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-795QBPW744"></script>
|
|
56
|
-
<script>function gtag() { dataLayer.push(arguments) } window.dataLayer = window.dataLayer || [], gtag("js", new Date), gtag("config", "G-795QBPW744")</script>
|
|
57
|
-
<style>
|
|
58
|
-
html {
|
|
59
|
-
overflow-y: auto;
|
|
60
|
-
overflow-x: hidden
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
#root,
|
|
64
|
-
body {
|
|
65
|
-
height: 100%;
|
|
66
|
-
width: 100%;
|
|
67
|
-
margin: 0;
|
|
68
|
-
padding: 0
|
|
69
|
-
}
|
|
70
|
-
</style>
|
|
71
|
-
<script defer="defer" src="/static/js/main.ae7f7033.js"></script>
|
|
72
|
-
<link href="/static/css/main.026e3fe6.css" rel="stylesheet">
|
|
73
|
-
<meta property="description" content="Follow the course of light through the Death Valley Wilderness and observe the obvious and subtle changes across the landscape.Produced by Sylvia JohnsonTo w..."><meta property="title" content="Death Valley Wilderness: Wilderness Light"><meta property="twitter:app:id:googleplay" content="com.google.android.youtube"><meta property="twitter:app:id:ipad" content="544007664"><meta property="twitter:app:id:iphone" content="544007664"><meta property="twitter:app:name:googleplay" content="YouTube"><meta property="twitter:app:name:ipad" content="YouTube"><meta property="twitter:app:name:iphone" content="YouTube"><meta property="twitter:app:url:googleplay" content="https://www.youtube.com/watch?v=Kauv7MVPcsA"><meta property="twitter:app:url:ipad" content="vnd.youtube://www.youtube.com/watch?v=Kauv7MVPcsA&feature=applinks"><meta property="twitter:app:url:iphone" content="vnd.youtube://www.youtube.com/watch?v=Kauv7MVPcsA&feature=applinks"><meta property="twitter:card" content="summary"><meta property="twitter:description" content="Follow the course of light through the Death Valley Wilderness and observe the obvious and subtle changes across the landscape.Produced by Sylvia JohnsonTo w..."><meta property="twitter:image" content="https://www.twitter.com/image/url"><meta property="twitter:player" content="https://www.youtube.com/watch?v=Kauv7MVPcsA"><meta property="twitter:player:height" content="720"><meta property="twitter:player:width" content="1028"><meta property="twitter:site" content="@youtube"><meta property="twitter:title" content="Death Valley Wilderness: Wilderness Light"></head>
|
|
74
|
-
|
|
75
|
-
<body style="padding:0;margin:0;overflow-x:hidden"><noscript><iframe
|
|
76
|
-
src="https://www.googletagmanager.com/ns.html?id=GTM-W2TFNXL" height="0" width="0"
|
|
77
|
-
style="display:none;visibility:hidden"></iframe></noscript><noscript>You need to enable JavaScript to run this
|
|
78
|
-
app.</noscript>
|
|
79
|
-
<div id="root"></div>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
</body></html>"
|
|
83
|
-
`;
|
|
84
|
-
|
|
85
|
-
exports[`builder > Overwrites existing values with new values 1`] = `
|
|
86
|
-
"<!DOCTYPE html><html lang="en"><head>
|
|
87
|
-
<title>XYO 2.0</title>
|
|
88
|
-
<meta property="og:image" content="https://example.com/newimage.jpg">
|
|
89
|
-
<meta property="twitter:image" content="https://example.com/newimage.jpg">
|
|
90
|
-
</head>
|
|
91
|
-
<body>
|
|
92
|
-
|
|
93
|
-
</body></html>"
|
|
94
|
-
`;
|
package/src/spec/builder.spec.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
import Path from 'node:path'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
beforeAll,
|
|
6
|
-
describe, expect, it,
|
|
7
|
-
} from 'vitest'
|
|
8
|
-
|
|
9
|
-
import { getMetaAsDict } from '../lib/index.ts'
|
|
10
|
-
import { metaBuilder } from '../meta/index.ts'
|
|
11
|
-
import type {
|
|
12
|
-
Meta, OpenGraphMeta, TwitterMeta,
|
|
13
|
-
} from '../models/index.ts'
|
|
14
|
-
|
|
15
|
-
const title = 'Death Valley Wilderness: Wilderness Light'
|
|
16
|
-
const description
|
|
17
|
-
// eslint-disable-next-line @stylistic/max-len
|
|
18
|
-
= 'Follow the course of light through the Death Valley Wilderness and observe the obvious and subtle changes across the landscape.Produced by Sylvia JohnsonTo w...'
|
|
19
|
-
|
|
20
|
-
const meta: Meta = { description, title }
|
|
21
|
-
|
|
22
|
-
const og: OpenGraphMeta = {
|
|
23
|
-
description,
|
|
24
|
-
image: {
|
|
25
|
-
'': 'https://i.ytimg.com/vi/Kauv7MVPcsA/maxresdefault.jpg',
|
|
26
|
-
'height': 720,
|
|
27
|
-
'width': 1280,
|
|
28
|
-
},
|
|
29
|
-
site_name: 'YouTube',
|
|
30
|
-
title,
|
|
31
|
-
type: 'video.other',
|
|
32
|
-
url: 'https://www.youtube.com/watch?v=Kauv7MVPcsA',
|
|
33
|
-
video: {
|
|
34
|
-
height: 720,
|
|
35
|
-
secure_url: 'https://www.youtube.com/embed/Kauv7MVPcsA',
|
|
36
|
-
// TODO: Multiple tags
|
|
37
|
-
// tag: ['Light', 'Death Valley'],
|
|
38
|
-
type: 'text/html',
|
|
39
|
-
url: 'https://www.youtube.com/embed/Kauv7MVPcsA',
|
|
40
|
-
width: 1280,
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const twitter: TwitterMeta = {
|
|
45
|
-
app: {
|
|
46
|
-
id: {
|
|
47
|
-
googleplay: 'com.google.android.youtube',
|
|
48
|
-
ipad: '544007664',
|
|
49
|
-
iphone: '544007664',
|
|
50
|
-
},
|
|
51
|
-
name: {
|
|
52
|
-
googleplay: 'YouTube',
|
|
53
|
-
ipad: 'YouTube',
|
|
54
|
-
iphone: 'YouTube',
|
|
55
|
-
},
|
|
56
|
-
url: {
|
|
57
|
-
googleplay: 'https://www.youtube.com/watch?v=Kauv7MVPcsA',
|
|
58
|
-
ipad: 'vnd.youtube://www.youtube.com/watch?v=Kauv7MVPcsA&feature=applinks',
|
|
59
|
-
iphone: 'vnd.youtube://www.youtube.com/watch?v=Kauv7MVPcsA&feature=applinks',
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
card: 'summary',
|
|
63
|
-
description,
|
|
64
|
-
image: { '': 'https://www.twitter.com/image/url' },
|
|
65
|
-
player: {
|
|
66
|
-
'': 'https://www.youtube.com/watch?v=Kauv7MVPcsA',
|
|
67
|
-
'height': 720,
|
|
68
|
-
'width': 1028,
|
|
69
|
-
},
|
|
70
|
-
site: { '': '@youtube' },
|
|
71
|
-
title,
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
describe('builder', () => {
|
|
75
|
-
it('Generates head meta if none exists', () => {
|
|
76
|
-
const html = '<html/>'
|
|
77
|
-
const output = metaBuilder(html, meta)
|
|
78
|
-
expect(output).toBeDefined()
|
|
79
|
-
})
|
|
80
|
-
describe('Adds meta', () => {
|
|
81
|
-
let html: string
|
|
82
|
-
beforeAll(async () => {
|
|
83
|
-
const template = Path.join(__dirname, 'template.html')
|
|
84
|
-
html = await readFile(template, { encoding: 'utf8' })
|
|
85
|
-
})
|
|
86
|
-
const cases: [title: string, meta: Meta][] = [
|
|
87
|
-
['Open Graph (OG)', { ...meta, og }],
|
|
88
|
-
['Twitter', { ...meta, twitter }],
|
|
89
|
-
]
|
|
90
|
-
it.each(cases)('%s', (_, meta) => {
|
|
91
|
-
const output = metaBuilder(html, meta)
|
|
92
|
-
expect(output).toContain(meta.description)
|
|
93
|
-
expect(output).toContain(`<title>${meta.title}</title>`)
|
|
94
|
-
const metaProperties = getMetaAsDict(meta)
|
|
95
|
-
for (const [property, content] of Object.entries(metaProperties)) {
|
|
96
|
-
expect(output).toContain(`<meta property="${property}" content="${content}">`)
|
|
97
|
-
}
|
|
98
|
-
expect(output).toMatchSnapshot()
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
it('Overwrites existing values with new values', () => {
|
|
102
|
-
const oldImage = 'https://example.com/oldimage.jpg'
|
|
103
|
-
const newImage = 'https://example.com/newimage.jpg'
|
|
104
|
-
const html = `
|
|
105
|
-
<!doctype html>
|
|
106
|
-
<html lang="en">
|
|
107
|
-
<head>
|
|
108
|
-
<title>XYO 2.0</title>
|
|
109
|
-
<meta property="og:image" content="${oldImage}">
|
|
110
|
-
<meta property="twitter:image" content="${oldImage}">
|
|
111
|
-
</head>
|
|
112
|
-
<body></body>
|
|
113
|
-
</html>
|
|
114
|
-
`
|
|
115
|
-
const meta: Meta = {
|
|
116
|
-
og: { image: newImage },
|
|
117
|
-
twitter: { image: { '': newImage } },
|
|
118
|
-
}
|
|
119
|
-
const properties = ['og:image', 'twitter:image']
|
|
120
|
-
for (const property of properties) {
|
|
121
|
-
expect(html).toContain(`<meta property="${property}" content="${oldImage}">`)
|
|
122
|
-
}
|
|
123
|
-
const output = metaBuilder(html, meta)
|
|
124
|
-
for (const property of properties) {
|
|
125
|
-
expect(output).not.toContain(`<meta property="${property}" content="${oldImage}">`)
|
|
126
|
-
expect(output).toContain(`<meta property="${property}" content="${newImage}">`)
|
|
127
|
-
}
|
|
128
|
-
expect(output).toMatchSnapshot()
|
|
129
|
-
})
|
|
130
|
-
})
|