Skip to content

Commit a8fe155

Browse files
tcapetdazgreer
authored andcommitted
fix(tests): await mjml2html result
- created utils.js and updated all tests to use extractStyle function from it - set keepComments to true by default as per previous minifier
1 parent 6263c2b commit a8fe155

16 files changed

+284
-685
lines changed

packages/mjml-core/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export default async function mjml2html(mjml, options = {}) {
134134
Roboto: 'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700',
135135
Ubuntu: 'https://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700',
136136
},
137-
keepComments,
137+
keepComments = true,
138138
minify = true,
139139
minifyOptions,
140140
ignoreIncludes = false,
@@ -438,6 +438,7 @@ export default async function mjml2html(mjml, options = {}) {
438438
: { preset: 'lite' },
439439
removeEmptyAttributes: true,
440440
minifyJs: false,
441+
removeComments: keepComments ? false : 'safe',
441442
...minifyOptionsRest,
442443
}
443444

packages/mjml/test/accordion-fontFamily.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { load } = require('cheerio')
33
const mjml = require('../lib')
44

55
describe('mj-accordion font-family inheritance', function () {
6-
it('should render correct font-family in CSS style values on accordion-title and accordion-text', function () {
6+
it('should render correct font-family in CSS style values on accordion-title and accordion-text', async function () {
77
const input = `
88
<mjml>
99
<mj-body>
@@ -35,7 +35,7 @@ describe('mj-accordion font-family inheritance', function () {
3535
</mjml>
3636
`
3737

38-
const { html } = mjml(input)
38+
const { html } = await mjml(input)
3939

4040
const $ = load(html)
4141

packages/mjml/test/accordion-padding.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const chai = require('chai')
22
const { load } = require('cheerio')
33
const mjml = require('../lib')
4+
const { extractStyle } = require('./utils')
45

56
describe('mj-accordion padding-X', function () {
6-
it('should render correct padding in CSS style values on accordion-title and accordion-text', function () {
7+
it('should render correct padding in CSS style values on accordion-title and accordion-text', async function () {
78
const input = `
89
<mjml>
910
<mj-body>
@@ -23,15 +24,9 @@ describe('mj-accordion padding-X', function () {
2324
</mjml>
2425
`
2526

26-
const { html } = mjml(input)
27+
const { html } = await mjml(input)
2728
const $ = load(html)
2829

29-
function extractPadding(style, prop) {
30-
const start = style.indexOf(`${prop}:`) + prop.length + 1
31-
const end = style.indexOf(';', start)
32-
return style.substring(start, end).trim()
33-
}
34-
3530
const paddings = [
3631
'padding-left',
3732
'padding-right',
@@ -44,7 +39,7 @@ describe('mj-accordion padding-X', function () {
4439
)
4540
.map(function () {
4641
const style = $(this).attr('style')
47-
return extractPadding(style, padding)
42+
return extractStyle(style, padding)
4843
})
4944
.get(),
5045
)

packages/mjml/test/accordionTitle-fontWeight.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { load } = require('cheerio')
33
const mjml = require('../lib')
44

55
describe('mj-accordion-title font-weight', function () {
6-
it('should render correct font-weight in CSS style values on accordion-title', function () {
6+
it('should render correct font-weight in CSS style values on accordion-title', async function () {
77
const input = `
88
<mjml>
99
<mj-head>
@@ -41,7 +41,7 @@ describe('mj-accordion-title font-weight', function () {
4141
</mjml>
4242
`
4343

44-
const { html } = mjml(input)
44+
const { html } = await mjml(input)
4545

4646
const $ = load(html)
4747

packages/mjml/test/carousel-hoverSupported.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { load } = require('cheerio')
33
const mjml = require('../lib')
44

55
describe('mj-carousel-thumbnail thumbnails supported', function () {
6-
it('should render correct display in CSS style values on mj-carousel-thumbnail', function () {
6+
it('should render correct display in CSS style values on mj-carousel-thumbnail', async function () {
77
const input = `
88
<mjml>
99
<mj-body>
@@ -20,7 +20,7 @@ describe('mj-carousel-thumbnail thumbnails supported', function () {
2020
</mjml>
2121
`
2222

23-
const { html } = mjml(input)
23+
const { html } = await mjml(input)
2424

2525
const $ = load(html)
2626

packages/mjml/test/column-border-radius.test.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const chai = require('chai')
22
const { load } = require('cheerio')
33
const mjml = require('../lib')
4+
const { extractStyle } = require('./utils')
45

56
describe('mj-column border-radius', function () {
6-
it('should render correct border-radius / inner-border-radius (and border-collapse) in CSS style values on mj-column', function () {
7+
it('should render correct border-radius / inner-border-radius (and border-collapse) in CSS style values on mj-column', async function () {
78
const input = `
89
<mjml>
910
<mj-body>
@@ -16,7 +17,7 @@ describe('mj-column border-radius', function () {
1617
</mjml>
1718
`
1819

19-
const { html } = mjml(input)
20+
const { html } = await mjml(input)
2021

2122
const $ = load(html)
2223

@@ -27,9 +28,8 @@ describe('mj-column border-radius', function () {
2728
'.mj-column-per-100 > table > tbody > tr > td, .mj-column-per-100 > table > tbody > tr > td > table',
2829
)
2930
.map(function getAttr() {
30-
const start = $(this).attr('style').indexOf('border-radius:') + 14
31-
const end = $(this).attr('style').indexOf(';', start)
32-
return $(this).attr('style').substring(start, end)
31+
const style = $(this).attr('style')
32+
return extractStyle(style, 'border-radius')
3333
})
3434
.get(),
3535
'Border-radius / inner-border-radius in CSS style values on mj-column',
@@ -43,9 +43,8 @@ describe('mj-column border-radius', function () {
4343
'.mj-column-per-100 > table > tbody > tr > td, .mj-column-per-100 > table > tbody > tr > td > table',
4444
)
4545
.map(function getAttr() {
46-
const start = $(this).attr('style').indexOf('border-collapse:') + 16
47-
const end = $(this).attr('style').indexOf(';', start)
48-
return $(this).attr('style').substring(start, end)
46+
const style = $(this).attr('style')
47+
return extractStyle(style, 'border-collapse')
4948
})
5049
.get(),
5150
'Border-collapse in CSS style values on mj-column',

packages/mjml/test/html-comments.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const chai = require('chai')
22
const mjml = require('../lib')
33

44
describe('HTML comments', function () {
5-
it('should not alter the whitespace between the opening/closing comment tags and the comment content', function () {
5+
it('should not alter the whitespace between the opening/closing comment tags and the comment content', async function () {
66
const input = `
77
<mjml>
88
<mj-body>
@@ -22,7 +22,7 @@ describe('HTML comments', function () {
2222
</mjml>
2323
`
2424

25-
const { html } = mjml(input)
25+
const { html } = await mjml(input)
2626

2727
// should not alter templating syntax, or move the content that is outside any tag (mj-raws)
2828
const expected = [

packages/mjml/test/navbar-ico-padding.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const chai = require('chai')
22
const { load } = require('cheerio')
33
const mjml = require('../lib')
4+
const { extractStyle } = require('./utils')
45

56
describe('mj-navbar ico-padding-X', function () {
6-
it('should render correct padding in CSS style values on navbar hamburger icon', function () {
7+
it('should render correct padding in CSS style values on navbar hamburger icon', async function () {
78
const input = `
89
<mjml>
910
<mj-body>
@@ -19,15 +20,9 @@ describe('mj-navbar ico-padding-X', function () {
1920
</mjml>
2021
`
2122

22-
const { html } = mjml(input)
23+
const { html } = await mjml(input)
2324
const $ = load(html)
2425

25-
function extractPadding(style, prop) {
26-
const start = style.indexOf(`${prop}:`) + prop.length + 1
27-
const end = style.indexOf(';', start)
28-
return style.substring(start, end).trim()
29-
}
30-
3126
const paddings = [
3227
'padding-bottom',
3328
'padding-left',
@@ -39,7 +34,7 @@ describe('mj-navbar ico-padding-X', function () {
3934
$('.mj-menu-label')
4035
.map(function () {
4136
const style = $(this).attr('style')
42-
return extractPadding(style, padding)
37+
return extractStyle(style, padding)
4338
})
4439
.get(),
4540
)

packages/mjml/test/social-align.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
const chai = require('chai')
22
const { load } = require('cheerio')
33
const mjml = require('../lib')
4+
const { extractStyle } = require('./utils')
45

56
describe('mj-social-element align', function () {
6-
it('should render correct align in CSS style values on mj-social-element', function () {
7+
it('should render correct align in CSS style values on mj-social-element', async function () {
78
const input = `
89
<mjml>
910
<mj-body>
@@ -20,7 +21,7 @@ describe('mj-social-element align', function () {
2021
</mjml>
2122
`
2223

23-
const { html } = mjml(input)
24+
const { html } = await mjml(input)
2425

2526
const $ = load(html)
2627

@@ -29,9 +30,8 @@ describe('mj-social-element align', function () {
2930
.expect(
3031
$('.my-social-element > td:first-child')
3132
.map(function getAttr() {
32-
const start = $(this).attr('style').indexOf('text-align:') + 11
33-
const end = $(this).attr('style').indexOf(';', start)
34-
return $(this).attr('style').substring(start, end)
33+
const style = $(this).attr('style')
34+
return extractStyle(style, 'text-align')
3535
})
3636
.get(),
3737
'align values on social elements',

packages/mjml/test/social-icon-height.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { load } = require('cheerio')
33
const mjml = require('../lib')
44

55
describe('mj-social icon-height', function () {
6-
it('should render correct icon-height align in CSS style values on mj-social', function () {
6+
it('should render correct icon-height align in CSS style values on mj-social', async function () {
77
const input = `
88
<mjml>
99
<mj-body>
@@ -20,7 +20,7 @@ describe('mj-social icon-height', function () {
2020
</mjml>
2121
`
2222

23-
const { html } = mjml(input)
23+
const { html } = await mjml(input)
2424

2525
const $ = load(html)
2626

0 commit comments

Comments
 (0)