test: make all tests run on Linux + Windows

pull/231/head
Romain 3 years ago
parent 297e13eda8
commit 293cbf8469

@ -12,5 +12,10 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '12'
- run: choco install exiftool graphicsmagick
# GraphicsMagick must be manually added to the path
- run: |
$installPath = Get-ChildItem 'C:\Program Files\GraphicsMagick*' | Select-Object -First 1 | % { $_.FullName }
echo "$installPath" | Out-file -Append -FilePath $env:GITHUB_PATH -Encoding utf8
- run: npm install
- run: npm test

@ -1,5 +1,5 @@
recursive: true
require:
file:
- test/helpers.js
- test/log.js
reporter: list

@ -91,7 +91,9 @@
"describe",
"xdescribe",
"it",
"xit"
"xit",
"itLinux",
"itWindows"
]
}
}

@ -3,6 +3,7 @@ const path = require('path')
module.exports = (target, options) => {
const albumPath = options.data.root.album.path
const relative = path.relative(path.dirname(albumPath), target)
const url = relative.replace(/\\/g, '/')
// Escape single/double quotes
return relative.replace(/'/g, '%27').replace(/"/g, '%22')
return url.replace(/'/g, '%27').replace(/"/g, '%22')
}

@ -3,8 +3,10 @@ const process = require('process')
const should = require('should/as-function')
const sinon = require('sinon')
const options = require('../../src/cli/options.js')
const fixtures = require('../fixtures.js')
const BASE_ARGS = ['--input', 'photos', '--output', 'website']
const ospath = fixtures.ospath
describe('options', function () {
before(() => {
@ -112,11 +114,16 @@ describe('options', function () {
const opts = options.get(args)
should(opts.databaseFile).eql(path.join(process.cwd(), 'album.db'))
})
it('can be overridden with an absolute url', () => {
itLinux('can be overridden with an absolute url (Linux)', () => {
const args = BASE_ARGS.concat(['--database-file', '/media/album.db'])
const opts = options.get(args)
should(opts.databaseFile).eql('/media/album.db')
})
itWindows('can be overridden with an absolute url (Windows)', () => {
const args = BASE_ARGS.concat(['--database-file', 'C:\\media\\album.db'])
const opts = options.get(args)
should(opts.databaseFile).eql('C:\\media\\album.db')
})
})
describe('log file path', () => {
it('defaults to the output folder', () => {
@ -207,7 +214,7 @@ describe('options', function () {
'--css', 'path/to/custom.css'
])
const opts = options.get(args)
should(opts.themeStyle).eql('path/to/custom.css')
should(opts.themeStyle).eql(ospath('path/to/custom.css'))
})
})
})

@ -4,8 +4,8 @@ const fixtures = require('../../fixtures')
const exiftool = require('../../../src/components/exiftool/parallel')
describe('exiftool', function () {
this.slow(1000)
this.timeout(1000)
this.slow(10000)
this.timeout(10000)
it('processes all files', (done) => {
// generate some photos in a temp folder

@ -189,9 +189,10 @@ describe('Index: glob', function () {
], done)
})
it('ignores invalid file names', function (done) {
if (os.platform() === 'darwin') {
it('ignores invalid file names on Linux', function (done) {
if (os.platform() !== 'linux') {
// the invalid filename generates a system error on macOS
// and is actually valid on Windows
return this.skip()
}
const tmpdir = tmp.dirSync({ unsafeCleanup: true })

@ -71,3 +71,8 @@ exports.createTempStructure = function (files) {
})
return tmpdir
}
// convert to OS-dependent style paths for testing
exports.ospath = function (filepath) {
return filepath.replace(RegExp('/', 'g'), path.sep)
}

@ -9,3 +9,11 @@ process.on('unhandledRejection', err => {
// Automatically delete temporary files/folders
// Created during the tests
tmp.setGracefulCleanup()
// Helpers for Linux and Windows-only tests
function test (title, fn) {
it(title, fn)
}
global.itLinux = (process.platform !== 'win32') ? test : () => {}
global.itWindows = (process.platform === 'win32') ? test : () => {}

@ -1,5 +1,4 @@
const _ = require('lodash')
const path = require('path')
const should = require('should/as-function')
const Album = require('../../src/model/album')
const fixtures = require('../fixtures')
@ -9,9 +8,9 @@ function arrayOfFiles (count) {
return Array.from(base, (_, index) => fixtures.photo(`${index}`))
}
function outputName (output) {
const ext = path.extname(output.urls.thumbnail)
return path.basename(output.urls.thumbnail, ext)
function outputName (file) {
const thumb = file.urls.thumbnail
return thumb.substring(thumb.lastIndexOf('/') + 1, thumb.lastIndexOf('.'))
}
describe('Album', function () {

@ -1,12 +1,15 @@
const should = require('should/as-function')
const output = require('../../src/model/output')
const fixtures = require('../fixtures.js')
const ospath = fixtures.ospath
describe('Output paths', function () {
describe('Images', function () {
it('generates a thumbnail', function () {
const o = output.paths('holidays/beach.jpg', 'image', {})
should(o.thumbnail).eql({
path: 'media/thumbs/holidays/beach.jpg',
path: ospath('media/thumbs/holidays/beach.jpg'),
rel: 'photo:thumbnail'
})
})
@ -14,7 +17,7 @@ describe('Output paths', function () {
it('generates a large "web" version', function () {
const o = output.paths('holidays/beach.jpg', 'image', {})
should(o.large).eql({
path: 'media/large/holidays/beach.jpg',
path: ospath('media/large/holidays/beach.jpg'),
rel: 'photo:large'
})
})
@ -24,7 +27,7 @@ describe('Output paths', function () {
photoDownload: 'resize'
})
should(o.download).eql({
path: 'media/large/holidays/beach.jpg',
path: ospath('media/large/holidays/beach.jpg'),
rel: 'photo:large'
})
})
@ -34,7 +37,7 @@ describe('Output paths', function () {
photoPreview: 'copy'
})
should(o.large).eql({
path: 'media/original/holidays/beach.jpg',
path: ospath('media/original/holidays/beach.jpg'),
rel: 'fs:copy'
})
})
@ -44,7 +47,7 @@ describe('Output paths', function () {
photoDownload: 'copy'
})
should(o.download).eql({
path: 'media/original/holidays/beach.jpg',
path: ospath('media/original/holidays/beach.jpg'),
rel: 'fs:copy'
})
})
@ -54,7 +57,7 @@ describe('Output paths', function () {
photoDownload: 'symlink'
})
should(o.download).eql({
path: 'media/original/holidays/beach.jpg',
path: ospath('media/original/holidays/beach.jpg'),
rel: 'fs:symlink'
})
})
@ -65,7 +68,7 @@ describe('Output paths', function () {
linkPrefix: '../myphotos'
})
should(o.download).eql({
path: '../myphotos/holidays/beach.jpg',
path: ospath('../myphotos/holidays/beach.jpg'),
rel: 'fs:link'
})
})
@ -73,7 +76,7 @@ describe('Output paths', function () {
it('keeps the original image format if the browser supports it', function () {
['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF'].forEach(ext => {
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.${ext}`)
should(o.thumbnail.path).eql(ospath(`media/thumbs/holidays/beach.${ext}`))
})
})
@ -81,7 +84,7 @@ describe('Output paths', function () {
// some of these formats are supported on certain browser, but we aim for maximum compatibility
['bmp', 'tiff', 'webp'].forEach(ext => {
const o = output.paths(`holidays/beach.${ext}`, 'image', {})
should(o.thumbnail.path).eql(`media/thumbs/holidays/beach.jpg`)
should(o.thumbnail.path).eql(ospath(`media/thumbs/holidays/beach.jpg`))
})
})
})
@ -90,7 +93,7 @@ describe('Output paths', function () {
it('generates a thumbnail', function () {
const o = output.paths('holidays/seagull.mp4', 'video', {})
should(o.thumbnail).eql({
path: 'media/thumbs/holidays/seagull.jpg',
path: ospath('media/thumbs/holidays/seagull.jpg'),
rel: 'video:thumbnail'
})
})
@ -98,7 +101,7 @@ describe('Output paths', function () {
it('generates a poster image', function () {
const o = output.paths('holidays/seagull.mp4', 'video', {})
should(o.large).eql({
path: 'media/large/holidays/seagull.jpg',
path: ospath('media/large/holidays/seagull.jpg'),
rel: 'video:poster'
})
})
@ -106,7 +109,7 @@ describe('Output paths', function () {
it('generates a resized "web" video', function () {
const o = output.paths('holidays/seagull.mp4', 'video', { videoFormat: 'mp4' })
should(o.video).eql({
path: 'media/large/holidays/seagull.mp4',
path: ospath('media/large/holidays/seagull.mp4'),
rel: 'video:resized'
})
})
@ -117,7 +120,7 @@ describe('Output paths', function () {
videoFormat: 'mp4'
})
should(o.download).eql({
path: 'media/large/holidays/seagull.mp4',
path: ospath('media/large/holidays/seagull.mp4'),
rel: 'video:resized'
})
})
@ -127,7 +130,7 @@ describe('Output paths', function () {
videoDownload: 'copy'
})
should(o.download).eql({
path: 'media/original/holidays/seagull.mp4',
path: ospath('media/original/holidays/seagull.mp4'),
rel: 'fs:copy'
})
})
@ -137,7 +140,7 @@ describe('Output paths', function () {
videoPreview: 'copy'
})
should(o.video).eql({
path: 'media/original/holidays/seagull.mp4',
path: ospath('media/original/holidays/seagull.mp4'),
rel: 'fs:copy'
})
})
@ -147,7 +150,7 @@ describe('Output paths', function () {
videoDownload: 'symlink'
})
should(o.download).eql({
path: 'media/original/holidays/seagull.mp4',
path: ospath('media/original/holidays/seagull.mp4'),
rel: 'fs:symlink'
})
})
@ -158,7 +161,7 @@ describe('Output paths', function () {
linkPrefix: '../myphotos'
})
should(o.download).eql({
path: '../myphotos/holidays/seagull.mp4',
path: ospath('../myphotos/holidays/seagull.mp4'),
rel: 'fs:link'
})
})
@ -171,7 +174,7 @@ describe('Output paths', function () {
linkPrefix: '../myphotos'
})
should(o.download).eql({
path: '../myphotos/holidays/beach.jpg',
path: ospath('../myphotos/holidays/beach.jpg'),
rel: 'fs:link'
})
})
@ -182,12 +185,12 @@ describe('Output paths', function () {
linkPrefix: '../myphotos/'
})
should(o.download).eql({
path: '../myphotos/holidays/beach.jpg',
path: ospath('../myphotos/holidays/beach.jpg'),
rel: 'fs:link'
})
})
it('can use an absolute link prefix', function () {
itLinux('can use an absolute link prefix on Linux', function () {
const o = output.paths('holidays/beach.jpg', 'image', {
photoDownload: 'link',
linkPrefix: '/Photos'
@ -198,7 +201,7 @@ describe('Output paths', function () {
})
})
it('can use an absolute link prefix ending with a slash', function () {
itLinux('can use an absolute link prefix on Linux ending with a slash', function () {
const o = output.paths('holidays/beach.jpg', 'image', {
photoDownload: 'link',
linkPrefix: '/Photos/'
@ -209,6 +212,17 @@ describe('Output paths', function () {
})
})
itWindows('can use an absolute link prefix on Windows', function () {
const o = output.paths('holidays/beach.jpg', 'image', {
photoDownload: 'link',
linkPrefix: 'C:\\Photos'
})
should(o.download).eql({
path: ospath('C:\\Photos\\holidays\\beach.jpg'),
rel: 'fs:link'
})
})
it('can use a URL prefix', function () {
const o = output.paths('holidays/beach.jpg', 'image', {
photoDownload: 'link',
@ -236,7 +250,7 @@ describe('Output paths', function () {
it('defaults to the <folders> structure', function () {
const o = output.paths('holidays/beach.jpg', 'image', {})
should(o.download).eql({
path: 'media/large/holidays/beach.jpg',
path: ospath('media/large/holidays/beach.jpg'),
rel: 'photo:large'
})
})
@ -246,7 +260,7 @@ describe('Output paths', function () {
outputStructure: 'folders'
})
should(o.download).eql({
path: 'media/large/holidays/beach.jpg',
path: ospath('media/large/holidays/beach.jpg'),
rel: 'photo:large'
})
})
@ -256,7 +270,7 @@ describe('Output paths', function () {
outputStructure: 'suffix'
})
should(o.download).eql({
path: 'media/holidays/beach_jpg_large.jpg',
path: ospath('media/holidays/beach_jpg_large.jpg'),
rel: 'photo:large'
})
})

@ -1,77 +1,79 @@
const _ = require('lodash')
const should = require('should/as-function')
const structure = require('../../src/model/structure')
const fixtures = require('../fixtures.js')
const folders = structure.folders
const suffix = structure.suffix
const ospath = fixtures.ospath
describe('Structure', () => {
describe('folders', () => {
it('starts with <media>', () => {
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith('media/')
should(folders('holidays/IMG_0001.jpg', 'photo:large')).startWith('media/')
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith('media/')
should(folders('holidays/IMG_0001.mp4', 'video:poster')).startWith('media/')
should(folders('holidays/IMG_0001.mp4', 'video:resized')).startWith('media/')
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).startWith('media/')
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).startWith('media/')
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.jpg', 'photo:large')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.mp4', 'video:poster')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.mp4', 'video:resized')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).startWith(ospath('media/'))
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).startWith(ospath('media/'))
})
it('can be at the root', () => {
should(folders('IMG_0001.jpg', 'photo:thumbnail')).eql('media/thumbs/IMG_0001.jpg')
should(folders('IMG_0001.jpg', 'photo:thumbnail')).eql(ospath('media/thumbs/IMG_0001.jpg'))
})
it('adds thumbnails to a <thumbs> folder', () => {
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith('media/thumbs/holidays/')
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith('media/thumbs/holidays/')
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith(ospath('media/thumbs/holidays/'))
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith(ospath('media/thumbs/holidays/'))
})
it('adds large versions to a <large> folder', () => {
should(folders('holidays/IMG_0001.jpg', 'photo:large')).startWith('media/large/holidays/')
should(folders('holidays/IMG_0001.mp4', 'video:poster')).startWith('media/large/holidays/')
should(folders('holidays/IMG_0001.mp4', 'video:resized')).startWith('media/large/holidays/')
should(folders('holidays/IMG_0001.jpg', 'photo:large')).startWith(ospath('media/large/holidays/'))
should(folders('holidays/IMG_0001.mp4', 'video:poster')).startWith(ospath('media/large/holidays/'))
should(folders('holidays/IMG_0001.mp4', 'video:resized')).startWith(ospath('media/large/holidays/'))
})
it('adds copies and links to an <original> folder', () => {
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).startWith('media/original/holidays/')
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).startWith('media/original/holidays/')
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).startWith(ospath('media/original/holidays/'))
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).startWith(ospath('media/original/holidays/'))
})
it('keeps the full original name for copies and links', () => {
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.jpg', 'fs:copy')).endWith(ospath('IMG_0001.jpg'))
should(folders('holidays/IMG_0001.jpg', 'fs:symlink')).endWith(ospath('IMG_0001.jpg'))
})
it('preserves the photo thumbnail extension if supported', () => {
// lower case
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.jpeg', 'photo:thumbnail')).endWith('IMG_0001.jpeg')
should(folders('holidays/IMG_0001.png', 'photo:thumbnail')).endWith('IMG_0001.png')
should(folders('holidays/IMG_0001.gif', 'photo:thumbnail')).endWith('IMG_0001.gif')
should(folders('holidays/IMG_0001.jpg', 'photo:thumbnail')).endWith(ospath('IMG_0001.jpg'))
should(folders('holidays/IMG_0001.jpeg', 'photo:thumbnail')).endWith(ospath('IMG_0001.jpeg'))
should(folders('holidays/IMG_0001.png', 'photo:thumbnail')).endWith(ospath('IMG_0001.png'))
should(folders('holidays/IMG_0001.gif', 'photo:thumbnail')).endWith(ospath('IMG_0001.gif'))
// upper case
should(folders('holidays/IMG_0001.JPG', 'photo:thumbnail')).endWith('IMG_0001.JPG')
should(folders('holidays/IMG_0001.JPEG', 'photo:thumbnail')).endWith('IMG_0001.JPEG')
should(folders('holidays/IMG_0001.PNG', 'photo:thumbnail')).endWith('IMG_0001.PNG')
should(folders('holidays/IMG_0001.GIF', 'photo:thumbnail')).endWith('IMG_0001.GIF')
should(folders('holidays/IMG_0001.JPG', 'photo:thumbnail')).endWith(ospath(ospath('IMG_0001.JPG')))
should(folders('holidays/IMG_0001.JPEG', 'photo:thumbnail')).endWith(ospath(ospath('IMG_0001.JPEG')))
should(folders('holidays/IMG_0001.PNG', 'photo:thumbnail')).endWith(ospath(ospath('IMG_0001.PNG')))
should(folders('holidays/IMG_0001.GIF', 'photo:thumbnail')).endWith(ospath(ospath('IMG_0001.GIF')))
})
it('changes the photo thumbnail extension to jpg if not supported', () => {
should(folders('holidays/IMG_0001.tiff', 'photo:thumbnail')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.tiff', 'photo:thumbnail')).endWith(ospath(ospath('IMG_0001.jpg')))
})
it('supports two different resized video extensions', () => {
should(folders('holidays/IMG_0001.mov', 'video:resized', { videoFormat: 'mp4' })).endWith('IMG_0001.mp4')
should(folders('holidays/IMG_0001.mov', 'video:resized', { videoFormat: 'webm' })).endWith('IMG_0001.webm')
should(folders('holidays/IMG_0001.mov', 'video:resized', { videoFormat: 'mp4' })).endWith(ospath('IMG_0001.mp4'))
should(folders('holidays/IMG_0001.mov', 'video:resized', { videoFormat: 'webm' })).endWith(ospath('IMG_0001.webm'))
})
it('always uses jpg for video thumbnails and posters', () => {
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.mp4', 'video:poster')).endWith('IMG_0001.jpg')
should(folders('holidays/IMG_0001.mp4', 'video:thumbnail')).endWith(ospath('IMG_0001.jpg'))
should(folders('holidays/IMG_0001.mp4', 'video:poster')).endWith(ospath('IMG_0001.jpg'))
})
it('can use a file system link', () => {
const res = folders('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '../..' })
should(res).eql('../../holidays/IMG_0001.jpg')
should(res).eql(ospath('../../holidays/IMG_0001.jpg'))
})
it('can use a remote HTTP link', () => {
@ -82,36 +84,36 @@ describe('Structure', () => {
describe('suffix', () => {
it('starts with <media>', () => {
should(suffix('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith('media/')
should(suffix('holidays/IMG_0001.jpg', 'photo:large')).startWith('media/')
should(suffix('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith('media/')
should(suffix('holidays/IMG_0001.mp4', 'video:poster')).startWith('media/')
should(suffix('holidays/IMG_0001.mp4', 'video:resized')).startWith('media/')
should(suffix('holidays/IMG_0001.jpg', 'fs:copy')).startWith('media/')
should(suffix('holidays/IMG_0001.jpg', 'fs:symlink')).startWith('media/')
should(suffix('holidays/IMG_0001.jpg', 'photo:thumbnail')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.jpg', 'photo:large')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.mp4', 'video:thumbnail')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.mp4', 'video:poster')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.mp4', 'video:resized')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.jpg', 'fs:copy')).startWith(ospath('media/'))
should(suffix('holidays/IMG_0001.jpg', 'fs:symlink')).startWith(ospath('media/'))
})
it('can be at the root', () => {
should(suffix('IMG_0001.jpg', 'photo:thumbnail')).eql('media/IMG_0001_jpg_thumb.jpg')
should(suffix('IMG_0001.jpg', 'photo:thumbnail')).eql(ospath('media/IMG_0001_jpg_thumb.jpg'))
})
it('uses an _thumb suffix to denote thumbnails', () => {
should(suffix('holidays/IMG_0001.jpg', 'photo:thumbnail')).endWith('holidays/IMG_0001_jpg_thumb.jpg')
should(suffix('holidays/IMG_0001.mp4', 'video:thumbnail')).endWith('holidays/IMG_0001_mp4_thumb.jpg')
should(suffix('holidays/IMG_0001.jpg', 'photo:thumbnail')).endWith(ospath('holidays/IMG_0001_jpg_thumb.jpg'))
should(suffix('holidays/IMG_0001.mp4', 'video:thumbnail')).endWith(ospath('holidays/IMG_0001_mp4_thumb.jpg'))
})
it('uses a _large suffix to resized versions', () => {
should(suffix('holidays/IMG_0001.jpg', 'photo:large')).endWith('holidays/IMG_0001_jpg_large.jpg')
should(suffix('holidays/IMG_0001.mp4', 'video:resized')).endWith('holidays/IMG_0001_mp4_large.mp4')
should(suffix('holidays/IMG_0001.jpg', 'photo:large')).endWith(ospath('holidays/IMG_0001_jpg_large.jpg'))
should(suffix('holidays/IMG_0001.mp4', 'video:resized')).endWith(ospath('holidays/IMG_0001_mp4_large.mp4'))
})
it('uses a _poster suffix for the video poster', () => {
should(suffix('holidays/IMG_0001.jpg', 'video:poster')).endWith('holidays/IMG_0001_jpg_poster.jpg')
should(suffix('holidays/IMG_0001.jpg', 'video:poster')).endWith(ospath('holidays/IMG_0001_jpg_poster.jpg'))
})
it('uses the original filenames for copies and symlinks', () => {
should(suffix('holidays/IMG_0001.jpg', 'fs:copy')).endWith('holidays/IMG_0001.jpg')
should(suffix('holidays/IMG_0001.jpg', 'fs:symlink')).endWith('holidays/IMG_0001.jpg')
should(suffix('holidays/IMG_0001.jpg', 'fs:copy')).endWith(ospath('holidays/IMG_0001.jpg'))
should(suffix('holidays/IMG_0001.jpg', 'fs:symlink')).endWith(ospath('holidays/IMG_0001.jpg'))
})
it('does not have conflicts between generated photo and video files', () => {
@ -128,7 +130,7 @@ describe('Structure', () => {
it('can use a file system link', () => {
const res = suffix('holidays/IMG_0001.jpg', 'fs:link', { linkPrefix: '../..' })
should(res).eql('../../holidays/IMG_0001.jpg')
should(res).eql(ospath('../../holidays/IMG_0001.jpg'))
})
it('can use a remote HTTP link', () => {

@ -1,10 +1,7 @@
const _ = require('lodash')
const process = require('process')
const should = require('should/as-function')
const url = require('../../src/model/url')
const realPlatform = process.platform
describe('URLs', () => {
it('escapes non-URL-friendly characters', () => {
const chars = {
@ -18,41 +15,23 @@ describe('URLs', () => {
})
})
describe('Linux', () => {
before(() => {
Object.defineProperty(process, 'platform', { value: 'linux' })
})
after(() => {
Object.defineProperty(process, 'platform', { value: realPlatform })
})
it('converts standard Linux paths', function () {
const res = url.fromPath('photos/holidays/IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
it('encodes backslash in Linux paths', function () {
const res = url.fromPath('photos/my\\holidays.jpg')
should(res).eql('photos/my%5Cholidays.jpg')
})
itLinux('converts standard Linux paths', function () {
const res = url.fromPath('photos/holidays/IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
describe('Windows', () => {
before(() => {
Object.defineProperty(process, 'platform', { value: 'win32' })
})
after(() => {
Object.defineProperty(process, 'platform', { value: realPlatform })
})
itLinux('encodes backslash in Linux paths', function () {
const res = url.fromPath('photos/my\\holidays.jpg')
should(res).eql('photos/my%5Cholidays.jpg')
})
it('converts standard Windows paths', function () {
const res = url.fromPath('photos\\holidays\\IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
itWindows('converts standard Windows paths', function () {
const res = url.fromPath('photos\\holidays\\IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
it('slashes are also valid path separators on Windows', function () {
const res = url.fromPath('photos/holidays/IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
itWindows('slashes are also valid path separators on Windows', function () {
const res = url.fromPath('photos/holidays/IMG_001.jpg')
should(res).eql('photos/holidays/IMG_001.jpg')
})
})

@ -4,6 +4,8 @@ const should = require('should/as-function')
const cleanup = require('../../src/steps/step-cleanup')
const fixtures = require('../fixtures')
const ospath = fixtures.ospath
describe('Steps: cleanup', () => {
// we require "mock-fs" inside the tests, otherwise it also affects other tests
var mock = null
@ -50,9 +52,10 @@ describe('Steps: cleanup', () => {
'output/media/large/newyork/IMG_0003.jpg': ''
})
const obs = cleanup.run(input, 'output')
const extraFile = 'media/large/newyork/IMG_0003.jpg'
obs.reduce(toArray, []).subscribe(deletedFiles => {
should(deletedFiles).deepEqual(['media/large/newyork/IMG_0003.jpg'])
should(fs.unlinkSync.args).deepEqual([['output/media/large/newyork/IMG_0003.jpg']])
should(deletedFiles).deepEqual([ospath(extraFile)])
should(fs.unlinkSync.args).deepEqual([[ospath(`output/${extraFile}`)]])
testEnd()
})
})

@ -25,6 +25,7 @@ describe('Handlebars helpers: relative', () => {
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
})
// TODO: this should not be needed anymore because all URLs are already escaped
it('escapes single quotes so they can be used in CSS background-image', () => {
const template = handlebars.compile(`background-image('{{relative url}}')`)
const res = template({
@ -36,6 +37,7 @@ describe('Handlebars helpers: relative', () => {
should(res).eql("background-image('l%27histoire.jpg')")
})
// TODO: this should not be needed anymore because all URLs are already escaped
it('escapes double quotes so they can be used in <img> tags', () => {
const template = handlebars.compile(`<img src="{{relative url}}" />`)
const res = template({

Loading…
Cancel
Save