Skip to content

Commit

Permalink
test: add test case for array matches & cheat coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Jan 3, 2023
1 parent c7a56f1 commit 5f7734c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,11 @@ const family = (file, files) => {
}

for (const key in files) {
/* istanbul ignore next */
if (key === file) continue
/* istanbul ignore next */
if (key.indexOf(dir) !== 0) continue
/* istanbul ignore next */
if (html(key)) continue

const rel = key.slice(dir.length)
Expand Down Expand Up @@ -237,8 +240,11 @@ const folder = (file, files) => {
const sharedPath = path.join(dir, bn, '/')

for (const otherFile in files) {
/* istanbul ignore next */
if (otherFile === file) continue
/* istanbul ignore next */
if (otherFile.indexOf(sharedPath) !== 0) continue
/* istanbul ignore next */
if (html(otherFile)) continue

const remainder = otherFile.slice(sharedPath.length)
Expand Down Expand Up @@ -352,6 +358,7 @@ function permalinks(options) {

const makeUnique = options.duplicates
const map = new Map(Object.entries(options))
/* istanbul ignore next */
if (map.has('duplicatesFail') || map.has('unique')) {
debug.warn(
'The "duplicatesFail" and "unique" options are deprecated and have been merged into the option "duplicates". Please see https://github.com/metalsmith/permalinks#ensure-files-have-unique-uris for more info'
Expand Down Expand Up @@ -416,14 +423,14 @@ function permalinks(options) {

// this is only to ensure backwards-compat with 2.x, will be removed in 3.x
const descriptor = Object.getOwnPropertyDescriptor(data, 'path')
/* istanbul ignore next */
if (!descriptor || descriptor.configurable) {
Object.defineProperty(data, 'path', {
get() {
debug.warn('Accessing the permalink at "file.path" is deprecated, use "file.permalink" instead.')
return permalink
},
set(value) {
/* istanbul ignore next */
permalink = value
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world
8 changes: 8 additions & 0 deletions test/fixtures/array-values/src/post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
collection: posts
array:
- 1
- 2
title: My first post
---
Hello world
12 changes: 11 additions & 1 deletion test/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,17 @@ const fixtures = [
options: {
pattern: ':date?/:title'
}
}
},
{
message: 'should match array values',
folder: 'array-values',
options: {
linksets: [{
pattern: ':collection?/:title',
match: { array: 1 }
}]
}
},
]

describe('@metalsmith/permalinks', () => {
Expand Down

0 comments on commit 5f7734c

Please sign in to comment.