Skip to content
This repository has been archived by the owner on Apr 19, 2022. It is now read-only.

Added Tests #55

Merged
merged 4 commits into from
Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/get-help-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = () => {
const { blackBG, cyan, yellow, white } = require('./clc')
var helpMsg =
[
cyan('╔────────────────────────────────╗'),
cyan(` site-validator-cli v${pkg.version}`),
cyan('╚────────────────────────────────╝'),
cyan('╔────────────────────────────────╗'),
cyan(` site-validator-cli v${pkg.version}`),
cyan('╚────────────────────────────────╝'),
'',
white('Get Help ') + yellow('$ site-validator -h'),
white('Get Ver. ') + yellow('$ site-validator -v'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ const getUrlsFromCrawler = require('../../../lib/helpers-get-urls/get-urls-from-
const expectedOutput = [
'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/page.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/from_page.html']
'https://p1ho.github.io/site-validator-cli/test/data/site/from_page.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/page_warning.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/page_fail.html'
]
const unreferenced = 'https://p1ho.github.io/site-validator-cli/test/data/site/unreferenced.html'

test('urls are found (cache/debug set to false)', async (t) => {
var urls = await getUrlsFromCrawler('https://p1ho.github.io/site-validator-cli/test/data/site/index.html', false, false)
t.deepEqual(urls, expectedOutput)
urls.forEach(url => {
t.true(expectedOutput.includes(url))
})
t.not(true, urls.includes(unreferenced))
})
48 changes: 48 additions & 0 deletions test/modules/helpers-validate-pages-test/validate-page-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const test = require('ava')
const validatePage = require('../../../lib/helpers-validate-pages/validate-page')
const urls = {
pass: 'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
warning: 'https://p1ho.github.io/site-validator-cli/test/data/site/page_warning.html',
fail: 'https://p1ho.github.io/site-validator-cli/test/data/site/page_fail.html',
notFound: 'http://please-do-not-register-this-domain.com/'
}

test('pages that should pass', async (t) => {
let result = await validatePage(urls.pass, false, false)
t.deepEqual(result, {
url: urls.pass,
status: 'pass',
errors: []
})

result = await validatePage(urls.warning, true, false)
t.deepEqual(result, {
url: urls.warning,
status: 'pass',
errors: []
})
})

test('pages that should fail', async (t) => {
let result = await validatePage(urls.fail, false, false)
t.true(result.url === urls.fail)
t.true(result.status === 'fail')
t.true(result.errors.length === 2)
t.true(result.errors[0].type === 'error')
t.true(result.errors[1].type === 'error')

result = await validatePage(urls.warning, false, false)
t.true(result.url === urls.warning)
t.true(result.status === 'fail')
t.true(result.errors.length === 1)
t.true(result.errors[0].type === 'warning')
})

test('pages not found', async (t) => {
let result = await validatePage(urls.notFound, false, false)
t.deepEqual(result, {
url: urls.notFound,
status: 'not found',
errors: []
})
})
62 changes: 49 additions & 13 deletions test/modules/validate-pages-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const test = require('ava')
const validatePages = require('../../lib/validate-pages')
const urlList = [
'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/page.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/from_page.html'
]
const urls = {
pass: 'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
warning: 'https://p1ho.github.io/site-validator-cli/test/data/site/page_warning.html',
fail: 'https://p1ho.github.io/site-validator-cli/test/data/site/page_fail.html',
notFound: 'http://please-do-not-register-this-domain.com/'
}
const options = {
isLocal: false,
quiet: false,
Expand All @@ -13,19 +14,54 @@ const options = {
}

test('get single result', async (t) => {
let results = await validatePages([urlList[0]], options)
t.deepEqual(results, [{
url: 'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
status: 'pass',
errors: []
}])
let results = await validatePages([urls.pass], options)
t.true(results[0].url === urls.pass)
t.true(results[0].status === 'pass')
t.true(results[0].errors.length === 0)

results = await validatePages([urls.warning], options)
t.true(results[0].url === urls.warning)
t.true(results[0].status === 'fail')
t.true(results[0].errors.length === 1)

results = await validatePages([urls.fail], options)
t.true(results[0].url === urls.fail)
t.true(results[0].status === 'fail')
t.true(results[0].errors.length === 2)

results = await validatePages([urls.notFound], options)
t.true(results[0].url === urls.notFound)
t.true(results[0].status === 'not found')
t.true(results[0].errors.length === 0)
})

test('get multiple results (cannot test order)', async (t) => {
let urlList = [
'https://p1ho.github.io/site-validator-cli/test/data/site/index.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/page.html',
'https://p1ho.github.io/site-validator-cli/test/data/site/from_page.html'
]

let results = await validatePages(urlList, options)
results.forEach(e => {
t.true(urlList.includes(e.url))
t.deepEqual(e.status, 'pass')
t.deepEqual(e.errors, [])
t.true(e.status === 'pass')
t.true(e.errors.length === 0)
})

results = await validatePages(Object.values(urls), options)
results.forEach(e => {
t.true(Object.values(urls).includes(e.url))
// these cases were tested manually, and thus hardcoded here
if (e.status === 'pass' || e.status === 'not found') {
t.true(e.errors.length === 0)
} else {
if (e.errors.length === 1) {
t.true(e.errors[0].type === 'warning')
} else {
t.true(e.errors[0].type === 'error')
t.true(e.errors[1].type === 'error')
}
}
})
})