Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for filename prefix on rendering error message #167

Merged
merged 1 commit into from
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.