Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bcomnes committed Aug 23, 2021
1 parent c5a644a commit c1fc836
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 325 deletions.
640 changes: 329 additions & 311 deletions dependencygraph.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions lib/build-pages/page-builders/fs-path-to-url.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import tap from 'tap'
import process from 'node:process'

import { fsPathToUrlPath } from './fs-path-to-url.js'

const isWin = process.platform === 'win32'

tap.test('fsPathToUrlPath works for all OS file path types', async (t) => {
const tests = [
{
input: '/foo/bar/baz',
input: 'foo/bar/baz',
expect: '/foo/bar/baz',
note: 'unix style paths'
note: 'unix style paths',
winOnly: false
},
{
input: '\\foo\\bar\\baz',
input: 'foo\\bar\\baz',
expect: '/foo/bar/baz',
note: 'windows style paths'
note: 'windows style paths',
winOnly: true
}
]

for (const test of tests) {
t.equal(fsPathToUrlPath(test.input), test.expect, test.note)
if (isWin && test.winOnly) {
t.equal(fsPathToUrlPath(test.input), test.expect, test.note)
} else if (!isWin && !test.winOnly) {
t.equal(fsPathToUrlPath(test.input), test.expect, test.note)
}
}
})
4 changes: 2 additions & 2 deletions lib/build-pages/resolve-vars.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import tap from 'tap'
import desm from 'desm'
import { resolve } from 'node:path'

import { resolveVars } from './resolve-vars'
import { resolveVars } from './resolve-vars.js'

const __dirname = desm(import.meta.url)

tap.test('resolve vars resolves vars', async (t) => {
const varsFile = resolve(__dirname, '../../test-project/src/global.vars.js')

const vars = resolveVars(varsFile)
const vars = await resolveVars(varsFile)

t.equal(vars.foo, 'global')
})
3 changes: 3 additions & 0 deletions lib/identify-pages.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { asyncFolderWalker } from 'async-folder-walker'
import assert from 'webassert'

/**
* identifyPages returns a bunch of data relating to pages that need to be built, and related file.
* @param {string} src The string path of the src folder of the website to build.
* @return {object} The object containing page info
*/
export async function identifyPages (src, pageBuilders) {
assert(src, 'a src argument is required')
assert(pageBuilders, 'a pageBuilders argument is required')
const walker = asyncFolderWalker([src], {
statFilter: st => !st.isDirectory(),
shaper: ({
Expand Down
12 changes: 6 additions & 6 deletions lib/identify-pages.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import tap from 'tap'
import desm from 'desm'
import { join } from 'node:path'
import { resolve } from 'node:path'

import { identifyPages } from './identify-pages.js'
import { pageBuilders } from './build-pages/index.js'

const __dirname = desm(import.meta.url)

tap.test('identifyPages works as expected', async (t) => {
const results = await identifyPages(join(__dirname, '..', 'test-project', 'src'))
const results = await identifyPages(resolve(__dirname, '../test-project/src'), pageBuilders)
// console.log(results)
t.ok(results.globalStyle, 'Global style is found')
t.ok(results.globalVars, 'Global variabls are found')
Expand All @@ -16,8 +17,7 @@ tap.test('identifyPages works as expected', async (t) => {

t.equal(results.warnings.length, 1, '1 warnings produced')
t.equal(results.nonPageFolders.length, 1, '1 non-page-folder')

t.equal(results.pages['html-page'].page.type, 'html', 'html page is type html')
t.equal(results.pages['md-page'].page.type, 'md', 'md page is type md')
t.equal(results.pages['a-page'].page.type, 'js', 'a-page is type js')
t.equal(results.pages.find(p => p.path === 'html-page').page.type, 'html', 'html page is type html')
t.equal(results.pages.find(p => p.path === 'md-page').page.type, 'md', 'md page is type md')
t.equal(results.pages.find(p => p.path === 'a-page').page.type, 'js', 'a-page is type js')
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"test": "run-s test:*",
"test:standard": "standard --verbose | snazzy",
"test:tap": "tap",
"test:deps": "dependency-check package.json --missing --unused --entry bin/siteup --no-dev",
"test-skip:deptree": "depcruise --validate .dependency-cruiser.json bin/siteup",
"version": "run-s prepare version:*",
"version:changelog": "auto-changelog -p --template keepachangelog auto-changelog --breaking-pattern 'BREAKING CHANGE:'",
"version:git": "git add CHANGELOG.md cjs",
Expand Down

0 comments on commit c1fc836

Please sign in to comment.