Skip to content

Commit 61b285f

Browse files
TonySynenkojennifer-shehane
authored andcommitted
utf removal from banners test (#2010)
1 parent 6ebc75d commit 61b285f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

cypress/integration/contentful_banners_spec.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
const YAML = require('yamljs')
2-
const utf8 = require('utf8')
32

43
const allBannersYaml = 'source/_data/banners.yml'
54

5+
function emojiStrip (string, utf16Encoded = true) {
6+
if (!utf16Encoded) {
7+
return string.replace(/\\u[\dA-F]{8}/gi, '')
8+
}
9+
10+
return string.replace(/([\uE000-\uF8FF]|\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDDFF])/g, '')
11+
}
12+
613
describe('Contentful driven banners', () => {
714
it('displays all current banners with proper info', function () {
815
cy.task('readFileMaybe', allBannersYaml)
916
.then((yamlString) => {
1017
if (typeof yamlString === 'undefined' || yamlString === null) return this.skip()
1118

12-
const yamlObject = YAML.parse(yamlString)
19+
const yamlObject = YAML.parse(emojiStrip(yamlString, false))
1320

1421
// remove all outdated or future banners
1522
const setMyTimezoneToDate = (date) => new Date(Date.parse(date))
@@ -35,7 +42,7 @@ describe('Contentful driven banners', () => {
3542
.should((bannerText) => {
3643
const yamlText = Cypress.$(banners[i].text).text().trim()
3744

38-
expect(utf8.encode(bannerText), `Banner #${i + 1} text is proper`).to.eq(yamlText)
45+
expect(emojiStrip(bannerText), `Banner #${i + 1} text is proper`).to.eq(yamlText)
3946
})
4047

4148
cy.wrap(banner)

0 commit comments

Comments
 (0)