-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathtest.js
46 lines (42 loc) · 1.23 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
let websites = require('./websites')
let fetchArticle = require('./src/fetchArticle')
let determineWebsite = require('./src/determineWebsite')
let renderToMarkdown = require('./src/renderToMarkdown')
function assertArticleFormat({title, dom}) {
if (title && dom) {
} else {
throw Error('failed to match article format')
}
}
async function assertFetch(url) {
return assertArticleFormat(await fetchArticle(url))
}
;(async () => {
let cmd = process.argv[2]
switch(cmd) {
case 'test-website':
var website = process.argv[3]
var samples = websites[website].samples
samples.map(async (sample) => {
console.log(await fetchArticle(sample))
})
break
case 'test-all-websites':
Object.values(websites).map(website => {
website.samples.map(async (sample) => {
console.log(await fetchArticle(sample))
})
})
break
case 'test-website-markdown':
var website = process.argv[3]
var samples = websites[website].samples
samples.map(async (sample) => {
console.log(renderToMarkdown(await fetchArticle(sample)))
})
break
case 'determine-website':
let url = process.argv[3]
console.log(determineWebsite(url))
}
})()