serverless/lib/utils/fs/readFileSync.test.js
Mariusz Nowak 8c3c7c4e3a chore: Rename "tests" folder to "test"
Also upgrade @serverless/eslint-config to v2
2020-08-28 16:22:09 +02:00

46 lines
1.2 KiB
JavaScript

'use strict';
const expect = require('chai').expect;
const writeFileSync = require('./writeFileSync');
const readFileSync = require('./readFileSync');
const { getTmpFilePath } = require('../../../test/utils/fs');
describe('#readFileSync()', () => {
it('should read a file synchronously', () => {
const tmpFilePath = getTmpFilePath('anything.json');
writeFileSync(tmpFilePath, { foo: 'bar' });
const obj = readFileSync(tmpFilePath);
expect(obj.foo).to.equal('bar');
});
it('should read a filename extension .yml', () => {
const tmpFilePath = getTmpFilePath('anything.yml');
writeFileSync(tmpFilePath, { foo: 'bar' });
const obj = readFileSync(tmpFilePath);
expect(obj.foo).to.equal('bar');
});
it('should read a filename extension .yaml', () => {
const tmpFilePath = getTmpFilePath('anything.yaml');
writeFileSync(tmpFilePath, { foo: 'bar' });
const obj = readFileSync(tmpFilePath);
expect(obj.foo).to.equal('bar');
});
it('should throw YAMLException with filename if yml file is invalid format', () => {
const tmpFilePath = getTmpFilePath('invalid.yml');
writeFileSync(tmpFilePath, ': a');
expect(() => {
readFileSync(tmpFilePath);
}).to.throw(/.*invalid.yml/);
});
});