All files path_test.ts

100% Statements 80/80
100% Branches 0/0
100% Functions 16/16
100% Lines 64/64

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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 871x 1x 1x 1x 1x 60x   1x 1x 12x                 12x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x   1x 1x 1x   1x 1x 1x 1x   1x 1x 1x   1x 1x 1x      
import * as mock from 'mock-fs';
import * as path from 'path';
import {Path, PathType} from './path';
import {strictEqual} from 'assert';
const cwd = process.cwd();
const here = (filename: string) => path.join(cwd, filename);
 
describe('Path', () => {
  beforeEach(() =>
    mock({
      [here('hello.txt')]: 'hello world',
      [here('directive')]: {},
      [here('regular-file')]: 'file contents',
      [here('a-symlink')]: mock.symlink({
        path: here('regular-file'),
      }),
    })
  );
  afterEach(() => mock.restore());
  it('should use basename', () => {
    const p = new Path({basename: './tsconfig.json'});
    strictEqual(p instanceof Path, true);
    strictEqual(p.basename, 'tsconfig.json');
    strictEqual(p.extname, '.json');
    strictEqual(p.dirname, process.cwd());
  });
  it('should use path', () => {
    const p = new Path({path: '/tmp/tsconfig.json'});
    strictEqual(p instanceof Path, true);
    strictEqual(p.basename, 'tsconfig.json');
    strictEqual(p.extname, '.json');
    strictEqual(p.dirname, '/tmp');
  });
  it('should use cwd', () => {
    const p = new Path({cwd: '/tmp', basename: './tsconfig.json'});
    strictEqual(p instanceof Path, true);
    strictEqual(p.basename, 'tsconfig.json');
    strictEqual(p.extname, '.json');
    strictEqual(p.dirname, '/tmp');
  });
  it('should use replaceExt', () => {
    const p = new Path({cwd: '/tmp', basename: './tsconfig.json'});
    p.replaceExt('.meow');
    strictEqual(p.basename, 'tsconfig.meow');
    strictEqual(p.path, '/tmp/tsconfig.meow');
  });
  it('should extname', () => {
    const p = new Path({cwd: '/tmp', basename: './tsconfig.json'});
    strictEqual(p.extname, '.json');
    strictEqual(p.extname, '.json');
  });
  it('should dirname', () => {
    const p = new Path({cwd: '/tmp', basename: './tsconfig.json'});
    strictEqual(p.dirname, '/tmp');
    strictEqual(p.dirname, '/tmp');
  });
  it('should relativePath', () => {
    const p = new Path({cwd: '/tmp', basename: './love/tsconfig.json'});
    strictEqual(p.relativePath, './love/tsconfig.json');
    strictEqual(p.relativePath, './love/tsconfig.json');
    strictEqual(p.basename, 'tsconfig.json');
    strictEqual(p.basename, 'tsconfig.json');
  });
  it('should coreBasename', () => {
    const p = new Path({cwd: '/tmp', basename: './love/tsconfig.json'});
    strictEqual(p.coreBasename, 'tsconfig');
    strictEqual(p.coreBasename, 'tsconfig');
  });
  it('should get type file', async () => {
    const p = new Path({basename: './hello.txt'});
    strictEqual(await p.type, PathType.file);
  });
  it('should get use type from cache', async () => {
    const p = new Path({basename: './hello.txt'});
    strictEqual(await p.type, PathType.file);
    strictEqual(await p.type, PathType.file);
  });
  it('should get type directory', async () => {
    const p = new Path({basename: 'directive'});
    strictEqual(await p.type, PathType.directory);
  });
  it('should get type missing', async () => {
    const p = new Path({basename: 'missing.svg'});
    strictEqual(await p.type, PathType.missing);
  });
});