Skip to content

Commit 27094e4

Browse files
Move unit test customJS stuff into global file
1 parent c8d4d30 commit 27094e4

8 files changed

Lines changed: 25 additions & 121 deletions

File tree

test/analyze.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Analyze Tests', function() {
44

@@ -26,22 +26,6 @@ describe('Analyze Tests', function() {
2626

2727
it('should generate the analyze GET request with custom JS', async () => {
2828
const url = 'https://www.theverge.com/2020/8/25/21400240/epic-apple-ruling-unreal-engine-fortnite-temporary-restraining-order';
29-
function start(){};
30-
function end(){};
31-
const customJS = function() {
32-
start();
33-
setTimeout(function() {
34-
var loadMoreNode = document.querySelector('a.loadMore');
35-
if (loadMoreNode != null) {
36-
loadMoreNode.click();
37-
setTimeout(function() {
38-
end();
39-
}, 800);
40-
} else {
41-
end();
42-
}
43-
}, 500);
44-
}.toString();
4529

4630
let request = await diffbot.analyze({ url, customJS });
4731

test/article.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Article Tests', function() {
44

@@ -27,22 +27,6 @@ describe('Article Tests', function() {
2727

2828
it('should generate the article GET request with custom JS', async () => {
2929
const url = 'https://www.theverge.com/2020/8/25/21400240/epic-apple-ruling-unreal-engine-fortnite-temporary-restraining-order';
30-
function start(){};
31-
function end(){};
32-
const customJS = function() {
33-
start();
34-
setTimeout(function() {
35-
var loadMoreNode = document.querySelector('a.loadMore');
36-
if (loadMoreNode != null) {
37-
loadMoreNode.click();
38-
setTimeout(function() {
39-
end();
40-
}, 800);
41-
} else {
42-
end();
43-
}
44-
}, 500);
45-
}.toString();
4630

4731
let request = await diffbot.article({ url, customJS });
4832

test/discussion.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Discussion Tests', function() {
44

@@ -23,22 +23,6 @@ describe('Discussion Tests', function() {
2323

2424
it('should generate the discussion GET request with custom JS', async () => {
2525
const url = 'https://www.theverge.com/2020/8/25/21400240/epic-apple-ruling-unreal-engine-fortnite-temporary-restraining-order';
26-
function start(){};
27-
function end(){};
28-
const customJS = function() {
29-
start();
30-
setTimeout(function() {
31-
var loadMoreNode = document.querySelector('a.loadMore');
32-
if (loadMoreNode != null) {
33-
loadMoreNode.click();
34-
setTimeout(function() {
35-
end();
36-
}, 800);
37-
} else {
38-
end();
39-
}
40-
}, 500);
41-
}.toString();
4226

4327
let request = await diffbot.discussion({ url, customJS });
4428

test/event.test.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Event Tests', function() {
44

@@ -22,23 +22,6 @@ describe('Event Tests', function() {
2222
});
2323

2424
it('should generate the event GET request with custom JS', async () => {
25-
function start(){};
26-
function end(){};
27-
const customJS = function() {
28-
start();
29-
setTimeout(function() {
30-
var loadMoreNode = document.querySelector('a.loadMore');
31-
if (loadMoreNode != null) {
32-
loadMoreNode.click();
33-
setTimeout(function() {
34-
end();
35-
}, 800);
36-
} else {
37-
end();
38-
}
39-
}, 500);
40-
}.toString();
41-
4225
let request = await diffbot.event({ url, customJS });
4326

4427
expect(request.url).to.equal(`https://api.diffbot.com/v3/event?token=${diffbot.token}&url=${encodeURIComponent(url)}`);

test/global.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@ const chai = require('chai');
33
const chaiAsPromised = require('chai-as-promised');
44
chai.use(chaiAsPromised);
55

6+
function start(){};
7+
function end(){};
8+
const customJS = function() {
9+
start();
10+
setTimeout(function() {
11+
var loadMoreNode = document.querySelector('a.loadMore');
12+
if (loadMoreNode != null) {
13+
loadMoreNode.click();
14+
setTimeout(function() {
15+
end();
16+
}, 800);
17+
} else {
18+
end();
19+
}
20+
}, 500);
21+
}.toString();
22+
623
const FAKE_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
724
exports.diffbot = new Diffbot(FAKE_TOKEN, true);
825
exports.expect = chai.expect;
26+
exports.customJS = customJS;

test/image.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Image Tests', function() {
44

@@ -22,22 +22,6 @@ describe('Image Tests', function() {
2222

2323
it('should generate the image GET request with custom JS', async () => {
2424
const url = 'https://www.deviantart.com/up-tchi/art/Coral-village-852927725';
25-
function start(){};
26-
function end(){};
27-
const customJS = function() {
28-
start();
29-
setTimeout(function() {
30-
var loadMoreNode = document.querySelector('a.loadMore');
31-
if (loadMoreNode != null) {
32-
loadMoreNode.click();
33-
setTimeout(function() {
34-
end();
35-
}, 800);
36-
} else {
37-
end();
38-
}
39-
}, 500);
40-
}.toString();
4125

4226
let request = await diffbot.image({ url, customJS });
4327

test/product.test.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Product Tests', function() {
44

@@ -36,23 +36,6 @@ describe('Product Tests', function() {
3636
});
3737

3838
it('should generate the product GET request with custom JS', async () => {
39-
function start(){};
40-
function end(){};
41-
const customJS = function() {
42-
start();
43-
setTimeout(function() {
44-
var loadMoreNode = document.querySelector('a.loadMore');
45-
if (loadMoreNode != null) {
46-
loadMoreNode.click();
47-
setTimeout(function() {
48-
end();
49-
}, 800);
50-
} else {
51-
end();
52-
}
53-
}, 500);
54-
}.toString();
55-
5639
let request = await diffbot.product({ url, customJS });
5740

5841
expect(request.url).to.equal(`https://api.diffbot.com/v3/product?token=${diffbot.token}&url=${encodeURIComponent(url)}`);

test/video.test.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { diffbot, expect } = require('./global');
1+
const { diffbot, expect, customJS } = require('./global');
22

33
describe('Video Tests', function() {
44

@@ -22,22 +22,6 @@ describe('Video Tests', function() {
2222

2323
it('should generate the video GET request with custom JS', async () => {
2424
const url = 'https://www.youtube.com/watch?v=HeiPdaTQTfo';
25-
function start(){};
26-
function end(){};
27-
const customJS = function() {
28-
start();
29-
setTimeout(function() {
30-
var loadMoreNode = document.querySelector('a.loadMore');
31-
if (loadMoreNode != null) {
32-
loadMoreNode.click();
33-
setTimeout(function() {
34-
end();
35-
}, 800);
36-
} else {
37-
end();
38-
}
39-
}, 500);
40-
}.toString();
4125

4226
let request = await diffbot.video({ url, customJS });
4327

0 commit comments

Comments
 (0)