-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add METASCRAPER_CWD tests and documentation
Closes #52
- Loading branch information
Showing
13 changed files
with
158 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const clearModule = require('clear-module') | ||
const should = require('should') | ||
|
||
let metascraper | ||
|
||
describe('load rules', () => { | ||
before(() => { | ||
clearModule('metascraper') | ||
process.env.METASCRAPER_CWD = __dirname | ||
metascraper = require('../../../..') | ||
}) | ||
|
||
after(() => { | ||
clearModule('metascraper') | ||
delete process.env.METASCRAPER_CWD | ||
}) | ||
|
||
it('based on a configuration file', async () => { | ||
const url = 'https://facebook.com' | ||
const html = '<div></div>' | ||
|
||
const meta = await metascraper({ url, html }) | ||
should(meta.logo).be.equal( | ||
'https://logo.clearbit.com/facebook.com?size=128&format=jpg' | ||
) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
packages/metascraper/test/unit/load-rules/config/metascraper.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
rules: [ | ||
'metascraper-author', | ||
'metascraper-date', | ||
'metascraper-description', | ||
'metascraper-image', | ||
'metascraper-logo', | ||
{ | ||
'metascraper-clearbit-logo': { | ||
format: 'jpg' | ||
} | ||
}, | ||
'metascraper-publisher', | ||
'metascraper-title', | ||
'metascraper-url' | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const clearModule = require('clear-module') | ||
const should = require('should') | ||
|
||
let metascraper | ||
|
||
describe('load rules', () => { | ||
before(() => { | ||
clearModule('metascraper') | ||
process.env.METASCRAPER_CWD = __dirname | ||
metascraper = require('../../../..') | ||
}) | ||
|
||
after(() => { | ||
clearModule('metascraper') | ||
delete process.env.METASCRAPER_CWD | ||
}) | ||
|
||
it('based on a package file', async () => { | ||
const url = 'https://facebook.com' | ||
const html = '<div></div>' | ||
|
||
const meta = await metascraper({ url, html }) | ||
should(meta.logo).be.equal( | ||
'https://logo.clearbit.com/facebook.com?size=128&format=jpg' | ||
) | ||
}) | ||
}) |
19 changes: 19 additions & 0 deletions
19
packages/metascraper/test/unit/load-rules/pkg/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"metascraper": { | ||
"rules": [ | ||
"metascraper-author", | ||
"metascraper-date", | ||
"metascraper-description", | ||
"metascraper-image", | ||
"metascraper-logo", | ||
{ | ||
"metascraper-clearbit-logo": { | ||
"format": "jpg" | ||
} | ||
}, | ||
"metascraper-publisher", | ||
"metascraper-title", | ||
"metascraper-url" | ||
] | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/metascraper/test/unit/load-rules/rc/.metascraperrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"rules": [ | ||
"metascraper-author", | ||
"metascraper-date", | ||
"metascraper-description", | ||
"metascraper-image", | ||
"metascraper-logo", | ||
{"metascraper-clearbit-logo": { | ||
"format": "jpg" | ||
}}, | ||
"metascraper-publisher", | ||
"metascraper-title", | ||
"metascraper-url" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict' | ||
|
||
const clearModule = require('clear-module') | ||
const should = require('should') | ||
|
||
let metascraper | ||
|
||
describe('load rules', () => { | ||
before(() => { | ||
clearModule('metascraper') | ||
process.env.METASCRAPER_CWD = __dirname | ||
metascraper = require('../../../..') | ||
}) | ||
|
||
after(() => { | ||
clearModule('metascraper') | ||
delete process.env.METASCRAPER_CWD | ||
}) | ||
|
||
it('based on a rc file', async () => { | ||
const url = 'https://facebook.com' | ||
const html = '<div></div>' | ||
|
||
const meta = await metascraper({ url, html }) | ||
should(meta.logo).be.equal( | ||
'https://logo.clearbit.com/facebook.com?size=128&format=jpg' | ||
) | ||
}) | ||
}) |