Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
m3hari committed May 16, 2020
1 parent aafa8e5 commit b1145f9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ jobs:
with:
node-version: "12.x"
- run: yarn
- run: yarn test
- run: yarn test:ci
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ wasm-pack.log
worker/
node_modules/
.cargo-ok
*.log
*.log
coverage/*
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ module.exports = {
clearMocks: true,
setupFiles: ['./jest.setup.js'],
coverageDirectory: 'coverage',

testMatch: ['**/?(*.)+(unit|integration).[jt]s?(x)'],
testEnvironment: 'node',
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"dev": "wrangler dev",
"preview": "wrangler preview --watch",
"test": "jest",
"test:ci": "jest --coverage",
"format": "prettier --write '**/*.{js,json,md}' --ignore-path .prettierignore "
},
"dependencies": {
"cheerio": "1.x"
"cheerio": "^1.0.0-rc.3"
},
"devDependencies": {
"@babel/core": "7.9.x",
Expand Down
15 changes: 15 additions & 0 deletions tests/test.integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const SERVICE_URL = 'https://lmeta.mehari.workers.dev'

describe('Integration', function() {
it('Extract correct data', async () => {
const url = 'https://www.youtube.com/watch?v=BtN-goy9VOY'
const result = await (await fetch(`${SERVICE_URL}/?url=${url}`)).json()
expect(result).toEqual({
url,
siteName: 'YouTube',
title: 'The Coronavirus Explained & What You Should Do',
image: 'https://i.ytimg.com/vi/BtN-goy9VOY/maxresdefault.jpg',
description: expect.stringMatching(/Get Merch designed with from/),
})
})
})
4 changes: 4 additions & 0 deletions tests/test.spec.js → tests/test.unit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import getMeta from '../lib/index'
import { ValidationError } from '../lib/error'
describe('API', function() {
it('Returns correct format', async () => {
const url = 'https://google.com/'
Expand All @@ -12,6 +13,9 @@ describe('API', function() {
})
})

it('Validates URL', async () => {
await expect(getMeta('youtubecom')).rejects.toThrow(/Invalid URL/)
})
it('Extract correct data', async () => {
const url = 'https://www.youtube.com/watch?v=BtN-goy9VOY'
const result = await getMeta(url, { lang: 'en-US,en;' })
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ chalk@^3.0.0:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

cheerio@1.x:
cheerio@^1.0.0-rc.3:
version "1.0.0-rc.3"
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6"
integrity sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==
Expand Down

0 comments on commit b1145f9

Please sign in to comment.