From a8d8bfc696239be3e490de63fa9c60d113fd7e97 Mon Sep 17 00:00:00 2001 From: polemius Date: Thu, 19 Sep 2019 20:16:17 +0200 Subject: [PATCH] Add new test to src/deploy/util.js --- src/deploy/util.js | 3 +-- src/deploy/util.test.js | 43 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/deploy/util.js b/src/deploy/util.js index 150fe3c..92ab84e 100644 --- a/src/deploy/util.js +++ b/src/deploy/util.js @@ -109,8 +109,7 @@ async function waitForDeploy(api, deployId, siteId, timeout) { } // Transform the fileShaMap and fnShaMap into a generic shaMap that file-uploader.js can use -exports.getUploadList = getUploadList -function getUploadList(required, shaMap) { +exports.getUploadList = function(required, shaMap) { if (!required || !shaMap) return [] return flatten(required.map(sha => shaMap[sha])) } diff --git a/src/deploy/util.test.js b/src/deploy/util.test.js index 9cf1249..907d265 100644 --- a/src/deploy/util.test.js +++ b/src/deploy/util.test.js @@ -1,5 +1,5 @@ const test = require('ava') -const { normalizePath } = require('./util') +const { normalizePath, defaultFilter } = require('./util') test('normalizes relative file paths', t => { const cases = [ @@ -22,3 +22,44 @@ test('normalizes relative file paths', t => { t.is(normalizePath(c.input), c.expect, c.msg) }) }) + +test('normalizePath should throw the error if name is invalid', t => { + t.throws(() => normalizePath('invalid name#')) + t.throws(() => normalizePath('invalid name?')) + t.throws(() => normalizePath('??')) + t.throws(() => normalizePath('#')) +}) + +test('pass empty name to defaultFilter', t => { + const cases = [ + { + input: null, + expect: false + }, + { + input: undefined, + expect: false + }, + { + input: 'foo/bar/baz.js', + expect: true + }, + { + input: 'directory/node_modules', + expect: false + }, + { + input: 'directory/.gitignore', + expect: false + }, + { + input: 'directory/.well-known', + expect: true + }, + { + input: '__MACOSX', + expect: true + } + ] + cases.forEach(c => t.is(defaultFilter(c.input), c.expect)) +})