From d1c69303b36932f8b9ef6d66a06e6f587f7e6f36 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Wed, 10 May 2023 18:09:07 +0800 Subject: [PATCH] fix readability's substack test page failure by mocking the tweet redirect link --- packages/readabilityjs/package.json | 1 + packages/readabilityjs/test/test-readability.js | 16 ++++++++++++++++ yarn.lock | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/packages/readabilityjs/package.json b/packages/readabilityjs/package.json index c42d58c8a..39611dd29 100644 --- a/packages/readabilityjs/package.json +++ b/packages/readabilityjs/package.json @@ -31,6 +31,7 @@ "js-beautify": "^1.13.0", "linkedom": "^0.14.9", "mocha": "^8.2.0", + "nock": "^13.3.1", "puppeteer": "^10.1.0", "sinon": "^7.3.2" }, diff --git a/packages/readabilityjs/test/test-readability.js b/packages/readabilityjs/test/test-readability.js index 818367b27..05460f8b3 100644 --- a/packages/readabilityjs/test/test-readability.js +++ b/packages/readabilityjs/test/test-readability.js @@ -2,6 +2,7 @@ var chai = require("chai"); var sinon = require("sinon"); var chaiAsPromised = require("chai-as-promised"); const { parseHTML } = require("linkedom"); +const nock = require("nock"); chai.use(chaiAsPromised); chai.config.includeStack = true; @@ -323,6 +324,21 @@ describe("Readability API", function() { }); describe("Test pages", function() { + before(function() { + // mock the substack redirect to twitter + nock('https://email.mg2.substack.com') + .get('/c/eJxNkcuO3SAMhp8m7E5EzC1ZsDjT0fQidVG1qtRVRIKToCYQAZmZ9OlLejaVEBhk-__5PJqMc4in3kPK5Nr6fO6oPb6lFXPGSI6EsXdWK8ZAcQXEam6bVrTEpX6KiJtxq87xQLIfw-pGk13wVwWojlNKFo1UMpgYWCrbtoNJmIYh60AMYKxopoewOaxDP6LGV4xn8EjGsG3o89WLrHrJeU8Vu1fwUlZ-c5e9uuSU2_cF1xX9gHHG-PW5vKRs8pFK0AjoWq6KdMNapVoJvGIvpdEz0ApkLsEdPrLz6dP5Pv76LNOfnx_gxxd6J04DBaACZDkphZrVVqnR0nZCaVs6GVFxus1Qp2MoeuPvyw2Jegl-HsJNheC-JX7DkuX8EN5vFrdQh8271xCxNvt-Ieuvbx7e5bNHb4YV7YNmfgzlH99-Ro-xDMv2JutGCiY6yRsGgj_gFURCyk6wRpHixoZS5fXmxsXgmv6n8xdPFKS3') + .reply(302, '', [ + 'location', + 'https://twitter.com/ShellenbergerMD/status/1529847068138778624?s=20&t=A2G3yBHyxcYI6szVC2TJ0A' + ]); + + nock('https://twitter.com') + .get('/ShellenbergerMD/status/1529847068138778624') + .query({"s":"20","t":"A2G3yBHyxcYI6szVC2TJ0A"}) + .reply(200); + }); + testPages.forEach(function(testPage) { describe(testPage.dir, function() { var uri = "http://fakehost/test/page.html"; diff --git a/yarn.lock b/yarn.lock index 706afcf7c..c5e4c91a5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20857,6 +20857,16 @@ nock@^13.2.9: lodash "^4.17.21" propagate "^2.0.0" +nock@^13.3.1: + version "13.3.1" + resolved "https://registry.yarnpkg.com/nock/-/nock-13.3.1.tgz#f22d4d661f7a05ebd9368edae1b5dc0a62d758fc" + integrity sha512-vHnopocZuI93p2ccivFyGuUfzjq2fxNyNurp7816mlT5V5HF4SzXu8lvLrVzBbNqzs+ODooZ6OksuSUNM7Njkw== + dependencies: + debug "^4.1.0" + json-stringify-safe "^5.0.1" + lodash "^4.17.21" + propagate "^2.0.0" + node-abort-controller@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/node-abort-controller/-/node-abort-controller-3.0.1.tgz#f91fa50b1dee3f909afabb7e261b1e1d6b0cb74e"