@@ -24,19 +24,20 @@ describe(`gatsby-remark-copy-linked-files`, () => {
24
24
fsExtra . copy . mockReset ( )
25
25
} )
26
26
27
+ const parentDir = `/`
27
28
const markdownNode = {
28
29
parent : { } ,
29
30
}
30
31
const getNode = ( ) => {
31
32
return {
32
- dir : `` ,
33
+ dir : parentDir ,
33
34
internal : {
34
35
type : `File` ,
35
36
} ,
36
37
}
37
38
}
38
39
const getFiles = filePath => {
39
- const absolutePath = path . posix . normalize ( filePath )
40
+ const absolutePath = path . posix . normalize ( parentDir + filePath )
40
41
return [
41
42
{
42
43
absolutePath,
@@ -271,14 +272,32 @@ describe(`gatsby-remark-copy-linked-files`, () => {
271
272
expect ( fsExtra . copy ) . not . toHaveBeenCalled ( )
272
273
} )
273
274
275
+ it ( `do nothing if dir is not found` , async ( ) => {
276
+ const getNode = ( ) => {
277
+ return {
278
+ internal : {
279
+ type : `Node` ,
280
+ } ,
281
+ }
282
+ }
283
+ const path = `images/sample-image.gif`
284
+
285
+ const markdownAST = remark . parse ( `![sample][1]\n\n[1]: ${ path } ` )
286
+
287
+ await plugin ( { files : getFiles ( path ) , markdownAST, markdownNode, getNode } )
288
+
289
+ expect ( fsExtra . copy ) . not . toHaveBeenCalled ( )
290
+ } )
291
+
274
292
describe ( `respects pathPrefix` , ( ) => {
275
293
const imageName = `sample-image`
276
- const imagePath = `images/${ imageName } .svg`
294
+ const imageRelativePath = `images/${ imageName } .svg`
295
+ const imagePath = parentDir + imageRelativePath
277
296
278
297
// pathPrefix passed to plugins already combine pathPrefix and assetPrefix
279
298
it ( `relative pathPrefix (no assetPrefix)` , async ( ) => {
280
299
const pathPrefix = `/path-prefix`
281
- const markdownAST = remark . parse ( `` )
300
+ const markdownAST = remark . parse ( `` )
282
301
283
302
const expectedNewPath = path . posix . join (
284
303
process . cwd ( ) ,
@@ -304,7 +323,7 @@ describe(`gatsby-remark-copy-linked-files`, () => {
304
323
305
324
it ( `absolute pathPrefix (with assetPrefix, empty base path prefix)` , async ( ) => {
306
325
const pathPrefix = `https://cdn.mysiteassets.com`
307
- const markdownAST = remark . parse ( `` )
326
+ const markdownAST = remark . parse ( `` )
308
327
309
328
const expectedNewPath = path . posix . join (
310
329
process . cwd ( ) ,
@@ -330,7 +349,7 @@ describe(`gatsby-remark-copy-linked-files`, () => {
330
349
331
350
it ( `absolute pathPrefix (with assetPrefix, and non-empty base path prefix)` , async ( ) => {
332
351
const pathPrefix = `https://cdn.mysiteassets.com/path-prefix`
333
- const markdownAST = remark . parse ( `` )
352
+ const markdownAST = remark . parse ( `` )
334
353
335
354
const expectedNewPath = path . posix . join (
336
355
process . cwd ( ) ,
@@ -357,10 +376,13 @@ describe(`gatsby-remark-copy-linked-files`, () => {
357
376
358
377
describe ( `options.destinationDir` , ( ) => {
359
378
const imageName = `sample-image`
360
- const imagePath = `images/${ imageName } .gif`
379
+ const imageRelativePath = `images/${ imageName } .gif`
380
+ const imagePath = parentDir + imageRelativePath
361
381
362
382
it ( `throws an error if the destination supplied by destinationDir points outside of the root dir` , async ( ) => {
363
- const markdownAST = remark . parse ( `` )
383
+ const markdownAST = remark . parse (
384
+ ``
385
+ )
364
386
const invalidDestinationDir = `../destination`
365
387
expect . assertions ( 2 )
366
388
return plugin (
@@ -375,7 +397,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
375
397
} )
376
398
377
399
it ( `throws an error if the destination supplied by the destinationDir function points outside of the root dir` , async ( ) => {
378
- const markdownAST = remark . parse ( `` )
400
+ const markdownAST = remark . parse (
401
+ ``
402
+ )
379
403
const invalidDestinationDir = `../destination`
380
404
const customDestinationDir = f =>
381
405
`../destination/${ f . hash } /${ f . name } /${ f . notexist } `
@@ -392,7 +416,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
392
416
} )
393
417
394
418
it ( `copies file to the destination supplied by destinationDir` , async ( ) => {
395
- const markdownAST = remark . parse ( `` )
419
+ const markdownAST = remark . parse (
420
+ ``
421
+ )
396
422
const validDestinationDir = `path/to/dir`
397
423
const fileLocationPart = `some-hash/${ imageName } .gif`
398
424
const expectedNewPath = path . posix . join (
@@ -417,7 +443,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
417
443
} )
418
444
419
445
it ( `copies file to the destination supplied by the destinationDir function` , async ( ) => {
420
- const markdownAST = remark . parse ( `` )
446
+ const markdownAST = remark . parse (
447
+ ``
448
+ )
421
449
const customDestinationDir = f => `foo/${ f . hash } --bar`
422
450
const expectedDestination = `foo/some-hash--bar.gif`
423
451
expect . assertions ( 3 )
@@ -435,7 +463,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
435
463
} )
436
464
437
465
it ( `copies file to the destination supplied by destinationDir (with pathPrefix)` , async ( ) => {
438
- const markdownAST = remark . parse ( `` )
466
+ const markdownAST = remark . parse (
467
+ ``
468
+ )
439
469
const pathPrefix = `/blog`
440
470
const validDestinationDir = `path/to/dir`
441
471
@@ -468,7 +498,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
468
498
} )
469
499
470
500
it ( `copies file to the destination supplied by the destinationDir function (with pathPrefix)` , async ( ) => {
471
- const markdownAST = remark . parse ( `` )
501
+ const markdownAST = remark . parse (
502
+ ``
503
+ )
472
504
const pathPrefix = `/blog`
473
505
const customDestinationDir = f => `hello${ f . name } 123`
474
506
const expectedDestination = `hello${ imageName } 123.gif`
@@ -495,7 +527,9 @@ describe(`gatsby-remark-copy-linked-files`, () => {
495
527
} )
496
528
497
529
it ( `copies file to the root dir when destinationDir is not supplied` , async ( ) => {
498
- const markdownAST = remark . parse ( `` )
530
+ const markdownAST = remark . parse (
531
+ ``
532
+ )
499
533
const expectedNewPath = path . posix . join (
500
534
process . cwd ( ) ,
501
535
`public` ,
0 commit comments