From 6dfc0d7e6711a94ab47f32a6571bbaddce120a23 Mon Sep 17 00:00:00 2001 From: Maxime Brazeilles Date: Tue, 6 Aug 2024 11:40:48 +0200 Subject: [PATCH] [FIX] Move into async func --- packages/mjml/test/html-attributes.test.js | 80 ++++++++++++---------- packages/mjml/test/lazy-head-style.test.js | 69 ++++++++++--------- 2 files changed, 79 insertions(+), 70 deletions(-) diff --git a/packages/mjml/test/html-attributes.test.js b/packages/mjml/test/html-attributes.test.js index 5adb1696a..0483cca42 100755 --- a/packages/mjml/test/html-attributes.test.js +++ b/packages/mjml/test/html-attributes.test.js @@ -3,7 +3,8 @@ const { load } = require('cheerio') const { sortBy } = require('lodash') const mjml = require('../lib') -const input = ` +async function run() { + const input = ` @@ -35,44 +36,49 @@ const input = ` ` -const { html } = mjml(input) -const $ = load(html) + const { html } = await mjml(input) + const $ = load(html) -// should put the attributes at the right place -chai - .expect( - $('.text div') - .map(function getAttr() { - return $(this).attr('data-id') - }) - .get(), - 'Custom attributes added on texts', - ) - .to.eql(['42', '42']) + // should put the attributes at the right place + chai + .expect( + $('.text div') + .map(function getAttr() { + return $(this).attr('data-id') + }) + .get(), + 'Custom attributes added on texts', + ) + .to.eql(['42', '42']) -chai - .expect( - $('.image td') - .map(function getAttr() { - return $(this).attr('data-name') - }) - .get(), - 'Custom attributes added on image', - ) - .to.eql(['43']) + chai + .expect( + $('.image td') + .map(function getAttr() { + return $(this).attr('data-name') + }) + .get(), + 'Custom attributes added on image', + ) + .to.eql(['43']) -// should not alter templating syntax, or move the content that is outside any tag (mj-raws) -const expected = [ - '{ if item < 5 }', - 'class="section"', - '{ if item > 10 }', - 'class="text"', - '{ item }', - '{ end if }', - '{ item + 1 }', -] -const indexes = expected.map((str) => html.indexOf(str)) + // should not alter templating syntax, or move the content that is outside any tag (mj-raws) + const expected = [ + '{ if item < 5 }', + 'class="section"', + '{ if item > 10 }', + 'class="text"', + '{ item }', + '{ end if }', + '{ item + 1 }', + ] + const indexes = expected.map((str) => html.indexOf(str)) -chai.expect(indexes, 'Templating syntax unaltered').to.not.include(-1) + chai.expect(indexes, 'Templating syntax unaltered').to.not.include(-1) -chai.expect(sortBy(indexes), 'Mj-raws kept same positions').to.deep.eql(indexes) + chai + .expect(sortBy(indexes), 'Mj-raws kept same positions') + .to.deep.eql(indexes) +} + +run() diff --git a/packages/mjml/test/lazy-head-style.test.js b/packages/mjml/test/lazy-head-style.test.js index ad489a677..f7dfaadd2 100644 --- a/packages/mjml/test/lazy-head-style.test.js +++ b/packages/mjml/test/lazy-head-style.test.js @@ -1,46 +1,49 @@ const chai = require('chai') const spies = require('chai-spies') const mjml = require('../lib') - -chai.use(spies) - const { HeadComponent, registerComponent, } = require('../../mjml-core/lib/index') -const addStyle = chai.spy( - (breakpoint) => ` - @media only screen and (max-width:${breakpoint}) { - h1 { - font-size: 20px; +async function run() { + chai.use(spies) + + const addStyle = chai.spy( + (breakpoint) => ` + @media only screen and (max-width:${breakpoint}) { + h1 { + font-size: 20px; + } } - } - `, -) + `, + ) -class HeadComponentWithFunctionStyle extends HeadComponent { - handler() { - const { add } = this.context - add('style', addStyle) + class HeadComponentWithFunctionStyle extends HeadComponent { + handler() { + const { add } = this.context + add('style', addStyle) + } } + HeadComponentWithFunctionStyle.componentName = + 'mj-head-component-with-function-style' + HeadComponentWithFunctionStyle.endingTag = true + HeadComponentWithFunctionStyle.allowedAttributes = {} + + registerComponent(HeadComponentWithFunctionStyle) + + mjml(` + + + + + + + + + `) + + chai.expect(addStyle).to.have.been.called.with('300px') } -HeadComponentWithFunctionStyle.componentName = 'mj-head-component-with-function-style' -HeadComponentWithFunctionStyle.endingTag = true -HeadComponentWithFunctionStyle.allowedAttributes = {} - - -registerComponent(HeadComponentWithFunctionStyle) - -mjml(` - - - - - - - - -`) -chai.expect(addStyle).to.have.been.called.with('300px') +run()