From e525a11bce359214afab15d3fa5ddedea88eadcb Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Tue, 24 Nov 2015 17:08:59 +0700 Subject: [PATCH] Add tests for nested and deep-nested path --- lib/index.js | 1 - .../deep-nested/src/path/path/data.yaml | 1 + test/fixtures/nested/src/path/data.yaml | 1 + test/index.js | 30 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/deep-nested/src/path/path/data.yaml create mode 100644 test/fixtures/nested/src/path/data.yaml diff --git a/lib/index.js b/lib/index.js index bd99ebb..0c572d0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -31,7 +31,6 @@ function plugin(opts){ return function(files, metalsmith, done){ var metadata = metalsmith.metadata(); var exts = Object.keys(parsers); - for (var key in opts) { var file = opts[key].replace(/(\/|\\)/g, path.sep); var ext = extname(file); diff --git a/test/fixtures/deep-nested/src/path/path/data.yaml b/test/fixtures/deep-nested/src/path/path/data.yaml new file mode 100644 index 0000000..37f188c --- /dev/null +++ b/test/fixtures/deep-nested/src/path/path/data.yaml @@ -0,0 +1 @@ +string: 'string' \ No newline at end of file diff --git a/test/fixtures/nested/src/path/data.yaml b/test/fixtures/nested/src/path/data.yaml new file mode 100644 index 0000000..37f188c --- /dev/null +++ b/test/fixtures/nested/src/path/data.yaml @@ -0,0 +1 @@ +string: 'string' \ No newline at end of file diff --git a/test/index.js b/test/index.js index 743d776..8f6f910 100644 --- a/test/index.js +++ b/test/index.js @@ -58,4 +58,34 @@ describe('metalsmith-metadata', function(){ done(); }); }); + + it('should parse nested path', function(done){ + var m = Metalsmith('test/fixtures/nested').use(metadata({ file: 'path/data.yaml' })); + m.build(function(err){ + if (err) return done(err); + assert.deepEqual(m.metadata().file, { string: 'string' }); + assert(!exists('test/fixtures/nested/build')); + done(); + }); + }); + + it('should parse nested path with backslash', function(done){ + var m = Metalsmith('test/fixtures/nested').use(metadata({ file: 'path\\data.yaml' })); + m.build(function(err){ + if (err) return done(err); + assert.deepEqual(m.metadata().file, { string: 'string' }); + assert(!exists('test/fixtures/nested/build')); + done(); + }); + }); + + it('should parse deep nested path', function(done){ + var m = Metalsmith('test/fixtures/deep-nested').use(metadata({ file: 'path/path/data.yaml' })); + m.build(function(err){ + if (err) return done(err); + assert.deepEqual(m.metadata().file, { string: 'string' }); + assert(!exists('test/fixtures/deep-nested/build')); + done(); + }); + }); }); \ No newline at end of file