Skip to content

Commit

Permalink
test(unit): Add IP getter and head extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mvsde committed Jun 13, 2021
1 parent f60a680 commit 741f017
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"scripts": {
"lint:js": "eslint \"**/*.js\"",
"lint:css": "stylelint **/*.scss",
"test:unit": "c8 --all ava",
"test:unit": "c8 --reporter text --reporter html --all ava",
"release": "standard-version"
},
"bin": {
Expand Down
11 changes: 11 additions & 0 deletions test/unit/lib/get-host-ips.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import test from 'ava'

import getHostIPs from '../../../lib/get-host-ips.js'

test('gets host IPs', t => {
const result = getHostIPs()

for (const ip of result) {
t.true(typeof ip === 'string')
}
})
29 changes: 29 additions & 0 deletions test/unit/lib/pangolin-head-extension.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import test from 'ava'

import PangolinHeadExtension from '../../../lib/pangolin-head-extension.js'

test.serial('creates <head> markup in dev mode', t => {
const nodeEnvCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'

const publicPath = '/hello/world/'
const assets = { js: [], css: [] }

const result = new PangolinHeadExtension({ publicPath, assets })
t.snapshot(result.run().val)

process.env.NODE_ENV = nodeEnvCopy
})

test.serial('creates <head> markup in prod mode', t => {
const publicPath = '/hello/world/'
const assets = {
js: ['vendor.js', 'app.js'],
css: ['vendor.css', 'app.css']
}

const result = new PangolinHeadExtension({ publicPath, assets })

t.deepEqual(result.tags, ['pangolin_head'])
t.snapshot(result.run().val)
})
20 changes: 20 additions & 0 deletions test/unit/lib/snapshots/pangolin-head-extension.spec.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Snapshot report for `test/unit/lib/pangolin-head-extension.spec.js`

The actual snapshot is saved in `pangolin-head-extension.spec.js.snap`.

Generated by [AVA](https://avajs.dev).

## creates <head> markup in dev mode

> Snapshot 1
'<script src="/hello/world/main.js" defer></script>'

## creates <head> markup in prod mode

> Snapshot 1
`<script src="/hello/world/vendor.js" defer></script>␊
<script src="/hello/world/app.js" defer></script>␊
<link rel="stylesheet" href="/hello/world/vendor.css">␊
<link rel="stylesheet" href="/hello/world/app.css">`
Binary file not shown.

0 comments on commit 741f017

Please sign in to comment.