insomnia/plugins/insomnia-plugin-file/__tests__/index.test.js
Gregory Schier 773eefc059
Initial try at creating GitHub actions (#1646)
* Initial try at creating GitHub actions

* Fix Git checkout

* Just Mac for now

* Add Windows back

* Try change run for WIndows

* Configure msvs

* Try again

* Try again

* Try downgrading windows

* Change msvs version

* Separate Windows steps

* Try adding Ubuntu

* Linux packages

* SUdo?

* Try something else

* Make test more robust
2019-08-21 23:59:06 -07:00

35 lines
972 B
JavaScript

const path = require('path');
const tag = require('..').templateTags[0];
function assertTemplate(args, expected) {
return async function() {
const result = await tag.run(null, ...args);
expect(result).toBe(expected);
};
}
function assertTemplateFails(args, expected) {
return async function() {
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!'));
it(
'fails on missing file',
assertTemplateFails(
[path.resolve('/foo')],
`ENOENT: no such file or directory, open '${path.resolve('/foo')}'`,
),
);
it('fails on no 2nd param', assertTemplateFails([], 'No file selected'));
});