2017-11-26 20:45:40 +00:00
|
|
|
const path = require('path');
|
|
|
|
const tag = require('..').templateTags[0];
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function assertTemplate(args, expected) {
|
|
|
|
return async function() {
|
2017-11-26 20:45:40 +00:00
|
|
|
const result = await tag.run(null, ...args);
|
|
|
|
expect(result).toBe(expected);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
function assertTemplateFails(args, expected) {
|
|
|
|
return async function() {
|
2017-11-26 20:45:40 +00:00
|
|
|
try {
|
|
|
|
await tag.run(null, ...args);
|
|
|
|
fail(`Render should have thrown ${expected}`);
|
|
|
|
} catch (err) {
|
|
|
|
expect(err.message).toContain(expected);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('FileExtension', () => {
|
|
|
|
const filename = path.resolve(__dirname, path.join('./test.txt'));
|
|
|
|
const escaped = filename.replace(/\\/g, '\\\\');
|
|
|
|
it('reads from string', assertTemplate([escaped], 'Hello World!'));
|
2018-06-25 17:42:50 +00:00
|
|
|
it(
|
|
|
|
'fails on missing file',
|
|
|
|
assertTemplateFails(
|
|
|
|
['/foo'],
|
|
|
|
`ENOENT: no such file or directory, open '${path.resolve('/foo')}'`
|
|
|
|
)
|
|
|
|
);
|
2017-11-26 20:45:40 +00:00
|
|
|
it('fails on no 2nd param', assertTemplateFails([], 'No file selected'));
|
|
|
|
});
|