Verified Commit 5769eb36 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add first test

parent 83918a94
......@@ -43,8 +43,8 @@ class Hugo {
// (don’t shoot me, this is a Hugo convention so I’m mirroring it for
// consistency with regular Hugo usage). The returned result is the
// object returned from the exec() call with stdout and stderr properties.
async build (sourcePath = '.', destinationPath = 'public/') {
const hugoBuildCommand = `${this.hugoBinaryPath} --source=${sourcePath} --destination=${destinationPath}`
async build (sourcePath = '.', destinationPath = 'public/', baseURL = 'http://localhost:1313') {
const hugoBuildCommand = `${this.hugoBinaryPath} --source=${sourcePath} --destination=${destinationPath} --baseURL=${baseURL}`
const options = {
env: process.env
}
......@@ -63,7 +63,7 @@ class Hugo {
// hugo server --source=.hugo-source --destination=../.hugo-public --buildDrafts --renderToDisk --baseURL=https://localhost --disableLiveReload --appendPort=false
serve (sourcePath, destinationPath, baseURL) {
serve (sourcePath = '.', destinationPath = 'public/', baseURL = 'http://localhost:1313') {
const args = [
'server',
`--source=${sourcePath}`,
......
// Nothing yet.
\ No newline at end of file
const test = require('tape')
const fs = require('fs-extra')
const http = require('http')
const hugo = new (require('./index'))()
async function httpGet (url) {
return new Promise((resolve, reject) => {
http.get(url, (response) => {
const statusCode = response.statusCode
const location = response.headers.location
// Reject if it’s not one of the status codes we are testing.
if (statusCode !== 200 && statusCode !== 404 && statusCode !== 500 && statusCode !== 302) {
reject({statusCode})
}
let body = ''
response.on('data', _ => body += _)
response.on('end', () => {
resolve({statusCode, location, body})
})
})
})
}
test('[node-hugo] ', async t => {
t.plan(1)
const sourcePath = 'test/site'
const destinationPath = '../public' /* NB. relative to source path */
const baseURL = 'http://localhost:1313'
if (fs.existsSync(destinationPath)) {
fs.removeSync(destinationPath)
}
let hasError = false
let output = null
try {
output = await hugo.build(sourcePath, destinationPath, baseURL)
} catch (error) {
hasError = true
}
t.false(hasError, '[hugo build] does not throw an error')
})
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Categories on My New Hugo Site</title>
<link>https://localhost/categories/</link>
<description>Recent content in Categories on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="https://localhost/categories/index.xml" rel="self" type="application/rss+xml" />
</channel>
</rss>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content="Hugo 0.64.0" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello, world!</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>My New Hugo Site</title>
<link>https://localhost/</link>
<description>Recent content on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="https://localhost/index.xml" rel="self" type="application/rss+xml" />
</channel>
</rss>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://localhost/categories/</loc>
</url>
<url>
<loc>https://localhost/</loc>
</url>
<url>
<loc>https://localhost/tags/</loc>
</url>
</urlset>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Tags on My New Hugo Site</title>
<link>https://localhost/tags/</link>
<description>Recent content in Tags on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="https://localhost/tags/index.xml" rel="self" type="application/rss+xml" />
</channel>
</rss>
\ No newline at end of file
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
title = "node-hugo test site"
......@@ -4,9 +4,9 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello, world!</title>
<title>{{ .Title }}</title>
</head>
<body>
<p>Hello, world!</p>
<h1>{{ .Title }}</h1>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment