Skip to content

Commit

Permalink
Add test for filename prefix on rendering error message (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Apr 7, 2019
1 parent 92f42d2 commit 56fd838
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`metalsmith-in-place should prefix rendering errors with the filename 1`] = `"index.hbs: Something went wrong while rendering"`;

exports[`metalsmith-in-place should return an error for an invalid pattern 1`] = `"invalid pattern, the pattern option should be a string or array of strings. See https://www.npmjs.com/package/metalsmith-in-place#pattern"`;

exports[`metalsmith-in-place should return an error when there are no valid files to process 1`] = `"no files to process. See https://www.npmjs.com/package/metalsmith-in-place#no-files-to-process"`;
4 changes: 1 addition & 3 deletions lib/util.js → lib/get-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ function getTransformer(ext) {
return cache[ext];
}

module.exports = {
getTransformer
};
module.exports = getTransformer;
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const debug = require('debug')('metalsmith-in-place');
const match = require('multimatch');
const isUtf8 = require('is-utf8');
const { getTransformer } = require('./util');
const getTransformer = require('./get-transformer');

/**
* Engine, renders file contents with all available transformers
Expand Down
22 changes: 22 additions & 0 deletions lib/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const path = require('path');
const plugin = require('./index');

describe('metalsmith-in-place', () => {
beforeEach(() => {
jest.resetModules();
});

it('should process a single file', done => {
const base = path.join(process.cwd(), 'test', 'fixtures', 'single-file');
const actual = path.join(base, 'build');
Expand Down Expand Up @@ -214,4 +218,22 @@ describe('metalsmith-in-place', () => {
return done();
});
});

it('should prefix rendering errors with the filename', done => {
jest.doMock('./get-transformer', () =>
jest.fn(() => ({
renderAsync: () => Promise.reject(new Error('Something went wrong while rendering'))
}))
);
const plugin = require('./index'); // eslint-disable-line global-require, no-shadow

const base = path.join(process.cwd(), 'test', 'fixtures', 'rendering-error');
const metalsmith = new Metalsmith(base);

return metalsmith.use(plugin()).build(err => {
expect(err).toBeInstanceOf(Error);
expect(err.message).toMatchSnapshot();
done();
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-import": "^2.13.0",
"husky": "^0.14.3",
"jest": "^23.4.1",
"jest": "^24.7.1",
"jstransformer-handlebars": "^1.0.0",
"jstransformer-marked": "^1.0.2",
"lint-staged": "^7.0.0",
Expand Down
Empty file.

0 comments on commit 56fd838

Please sign in to comment.