All files readable_file_test.ts

100% Statements 36/36
100% Branches 2/2
100% Functions 10/10
100% Lines 24/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x 1x 1x 1x 4x   1x 1x 4x       4x 1x 1x 1x 2x     1x 1x 1x   1x 1x 1x   1x 1x 1x 2x        
import * as path from 'path';
import * as mock from 'mock-fs';
import {rejects, strictEqual} from 'assert';
import {ReadableFile} from './readable_file';
const cwd = process.cwd();
const here = (filename: string) => path.join(cwd, filename);
 
describe('ReadableFile', () => {
  beforeEach(() =>
    mock({
      [here('hello.txt')]: 'hello world',
    })
  );
  afterEach(() => mock.restore());
  it('should throw', async () => {
    const p = new ReadableFile();
    rejects(async () => {
      await p.content;
    });
  });
  it('should get content', async () => {
    const p = new ReadableFile({basename: './hello.txt'});
    strictEqual(await p.content, 'hello world');
  });
  it('should get default content', async () => {
    const p = new ReadableFile({basename: './any.txt', defaultContent: 'meow'});
    strictEqual(await p.content, 'meow');
  });
  it('should get throw when not found', async () => {
    const p = new ReadableFile({basename: './any.txt'});
    rejects(async () => {
      await p.content;
    });
  });
});