-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73c70f1
commit 2e09bfb
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const assert = require('assert/strict') | ||
const { describe, it } = require('node:test') | ||
const nunjucks = require('nunjucks') | ||
const canonicalUrl = require('../../../lib/filters/canonical-url.js') | ||
|
||
describe('canonicalUrl filter', () => { | ||
const ctx = { options: { url: 'https://example.com' } } | ||
const env = new nunjucks.Environment() | ||
env.addFilter('canonicalUrl', canonicalUrl) | ||
|
||
it('Returns given path if no site URL defined', () => { | ||
const result = env.renderString('{{ "/path" | canonicalUrl }}', { | ||
options: {} | ||
}) | ||
|
||
assert.equal(result, '/path') | ||
}) | ||
|
||
it('Returns external URL if doesn’t share hostname with site URL', () => { | ||
const result = env.renderString( | ||
'{{ "http://foo.bar" | canonicalUrl }}', | ||
ctx | ||
) | ||
|
||
assert.equal(result, 'http://foo.bar') | ||
}) | ||
|
||
it('Gets canonical site URL with resolved path', () => { | ||
const result = env.renderString('{{ "/path" | canonicalUrl }}', ctx) | ||
|
||
assert.equal(result, 'https://example.com/path') | ||
}) | ||
}) |