Skip to content

Commit

Permalink
Workaround for cheerio issues + jasmine test to protect from bad chee…
Browse files Browse the repository at this point in the history
…rio releases

See cheeriojs/cheerio#2500
  • Loading branch information
bago committed Apr 28, 2022
1 parent 9800348 commit ab1f2b1
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 31 deletions.
191 changes: 166 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"browserify-incremental": "3.1.1",
"browserify-shim": "3.8.14",
"browserify-versionify": "^1.0.6",
"cheerio": "1.0.0-rc.6",
"cheerio": "1.0.0-rc.5",
"connect-livereload": "0.6.1",
"express": "4.18.0",
"gm": "1.23.1",
Expand Down Expand Up @@ -116,7 +116,8 @@
"async": "3.2.3",
"minimist": "1.2.6",
"shelljs": "0.8.5",
"superagent": "7.1.2"
"superagent": "7.1.2",
"css-what": "6.1.0"
},
"scripts": {
"start": "grunt",
Expand Down
11 changes: 9 additions & 2 deletions package.json.NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
(still broken in 4.8.0)
- grunt-release is "locked" to 0.13.1 because 0.14.0 is broken and no new
releases have been made since that.
- cheerio is "locked" to 1.0.0-rc.6 because 1.0.0-rc.10 doesn't support $(html)
anymore.
- cheerio is "locked" to 1.0.0-rc.5 because 1.0.0-rc.6 and following fail to
deal with 2 sibling comments in html.
was: (cheerio is "locked" to 1.0.0-rc.6 because 1.0.0-rc.10 doesn't support
$(html) anymore)
- jsep is "locked" to 0.4.0 because 1.0+ is ES6 and breaks IE11 compatibility

Other:

- we manually declare "postcss" as a devDependencies because @ladder/grunt-postcss
does not declare it as a dependency.

Overrides:

- the overrides are only used to override security issues
- css-what 6.1.0 can be removed once we'll be able to update cheerio
12 changes: 11 additions & 1 deletion spec/converter-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Template converter', function() {
var _parseTemplate;

beforeAll(function() {
mockery.registerMock('jquery', require('cheerio'));
mockery.registerMock('jquery', require('cheerio').load('<html />'));
mockery.registerAllowables(['fs', '../src/js/converter/declarations.js', '../src/js/converter/model.js', '../src/js/converter/parser.js', 'console', './utils.js', './domutils.js', 'console', '../node_modules/mensch', './lib/lexer', './lib/parser', './lib/stringify', './debug', 'jsep', './declarations.js', 'mensch/lib/parser.js', 'mensch/lib/parser.js', './lexer', './stylesheet.js', './model.js']);
mockery.enable();

Expand All @@ -41,6 +41,16 @@ describe('Template converter', function() {
}
});

it('should have a working cheerio', function() {
try {
var $ = require('cheerio').load("whatever");
const a = $('<!-- comment 1 --><!-- comment 2 -->');
} catch (e) {
console.log(e);
fail("Bundled cheerio is broken!");
}
});

it('should handle basic template conversion', function() {
var parseData = _parseTemplate('<replacedhtml><replacedhead></replacedhead><repleacedbody><div data-ko-container="main"><div data-ko-block="simpleBlock"><div data-ko-editable="text">block1</div></div></div></replacedbody></replacedhtml>');

Expand Down
2 changes: 1 addition & 1 deletion spec/declarations-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Style declaration processor', function() {
};

beforeAll(function() {
mockery.registerMock('jquery', require('cheerio'));
mockery.registerMock('jquery', require('cheerio').load('<html />'));
mockery.registerAllowables(['cheerio', '../src/js/converter/declarations.js', './utils.js', 'console', 'jsep', 'mensch/lib/parser.js', './debug', './lexer', './domutils.js']);
mockery.enable();
elaborateDeclarations = require('../src/js/converter/declarations.js');
Expand Down

0 comments on commit ab1f2b1

Please sign in to comment.