style: fix code style
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export default (code) => {
|
||||
return _.trim(code) + '\n\n';
|
||||
return _.trim(code) + '\n\n';
|
||||
};
|
||||
|
||||
+23
-25
@@ -3,59 +3,57 @@
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
|
||||
import createIndexCode from './../src/utilities/createIndexCode';
|
||||
|
||||
import createIndexCode from '../src/utilities/createIndexCode';
|
||||
import codeExample from './codeExample';
|
||||
|
||||
describe('createIndexCode()', () => {
|
||||
it('describes no children', () => {
|
||||
const indexCode = createIndexCode([]);
|
||||
it('describes no children', () => {
|
||||
const indexCode = createIndexCode([]);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
`));
|
||||
});
|
||||
it('describes a single child', () => {
|
||||
const indexCode = createIndexCode(['foo']);
|
||||
});
|
||||
it('describes a single child', () => {
|
||||
const indexCode = createIndexCode(['foo']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
export foo from './foo';
|
||||
`));
|
||||
});
|
||||
it('describes multiple children', () => {
|
||||
const indexCode = createIndexCode(['bar', 'foo']);
|
||||
});
|
||||
it('describes multiple children', () => {
|
||||
const indexCode = createIndexCode(['bar', 'foo']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
export bar from './bar';
|
||||
export foo from './foo';
|
||||
`));
|
||||
});
|
||||
context('file with extension', () => {
|
||||
it('removes the extension from the export statement', () => {
|
||||
const indexCode = createIndexCode(['foo.js']);
|
||||
});
|
||||
context('file with extension', () => {
|
||||
it('removes the extension from the export statement', () => {
|
||||
const indexCode = createIndexCode(['foo.js']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
export foo from './foo.js';
|
||||
`));
|
||||
});
|
||||
});
|
||||
context('multiple, unsorted', () => {
|
||||
it('sorts the files', () => {
|
||||
const indexCode = createIndexCode(['foo', 'bar']);
|
||||
});
|
||||
context('multiple, unsorted', () => {
|
||||
it('sorts the files', () => {
|
||||
const indexCode = createIndexCode(['foo', 'bar']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
export bar from './bar';
|
||||
export foo from './foo';
|
||||
`));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+9
-10
@@ -1,20 +1,19 @@
|
||||
import path from 'path';
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
|
||||
import path from 'path';
|
||||
import glob from 'glob';
|
||||
import findIndexFiles from './../src/utilities/findIndexFiles';
|
||||
import findIndexFiles from '../src/utilities/findIndexFiles';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, './../../fixtures/find-index-files');
|
||||
const fixturesPath = path.resolve(__dirname, '../../fixtures/find-index-files');
|
||||
|
||||
describe('findIndexFiles()', () => {
|
||||
it('finds only the directories that have an existing valid index file', () => {
|
||||
let names;
|
||||
it('finds only the directories that have an existing valid index file', () => {
|
||||
let names;
|
||||
|
||||
names = findIndexFiles(path.resolve(fixturesPath));
|
||||
names = names.sort();
|
||||
names = findIndexFiles(path.resolve(fixturesPath));
|
||||
names = names.sort();
|
||||
|
||||
expect(names).to.deep.equal(glob.sync(path.resolve(fixturesPath, './**/find-*')));
|
||||
});
|
||||
expect(names).to.deep.equal(glob.sync(path.resolve(fixturesPath, './**/find-*')));
|
||||
});
|
||||
});
|
||||
|
||||
+48
-49
@@ -1,74 +1,73 @@
|
||||
import path from 'path';
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import readDirectory from '../src/utilities/readDirectory';
|
||||
|
||||
import path from 'path';
|
||||
import readDirectory from './../src/utilities/readDirectory';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, './../../fixtures/read-directory');
|
||||
const fixturesPath = path.resolve(__dirname, '../fixtures/read-directory');
|
||||
|
||||
describe('readDirectory()', () => {
|
||||
context('target directory contains child directories', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories'));
|
||||
context('target directory contains child directories', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories'));
|
||||
|
||||
expect(names).to.deep.equal(['bar', 'foo']);
|
||||
});
|
||||
expect(names).to.deep.equal(['bar', 'foo']);
|
||||
});
|
||||
context('target directory contains child directories that do not contain index', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-without-index'));
|
||||
});
|
||||
context('target directory contains child directories that do not contain index', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-without-index'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
context('target directory contains child directories (unsafe name)', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
|
||||
});
|
||||
context('target directory contains child directories (unsafe name)', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
|
||||
|
||||
expect(names).to.deep.equal(['present']);
|
||||
});
|
||||
expect(names).to.deep.equal(['present']);
|
||||
});
|
||||
context('target directory contains ./index.js', () => {
|
||||
it('does not include ./index.js', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-index'));
|
||||
});
|
||||
context('target directory contains ./index.js', () => {
|
||||
it('does not include ./index.js', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-index'));
|
||||
|
||||
expect(names).to.deep.equal(['bar', 'foo']);
|
||||
});
|
||||
expect(names).to.deep.equal(['bar', 'foo']);
|
||||
});
|
||||
context('target directory contains files', () => {
|
||||
it('refers to the files (with extension)', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files'));
|
||||
});
|
||||
context('target directory contains files', () => {
|
||||
it('refers to the files (with extension)', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files'));
|
||||
|
||||
expect(names).to.deep.equal(['bar.js', 'foo.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['bar.js', 'foo.js']);
|
||||
});
|
||||
context('target directory contains dot files', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-dot-files'));
|
||||
});
|
||||
context('target directory contains dot files', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-dot-files'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
context('target directory contains files with no extension', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-no-extension'));
|
||||
});
|
||||
context('target directory contains files with no extension', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-no-extension'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
context('target directory contains files with multiple extensions', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-multiple-extensions'));
|
||||
});
|
||||
context('target directory contains files with multiple extensions', () => {
|
||||
it('ignores files', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-multiple-extensions'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
context('target directory contains directories and files with the same name', () => {
|
||||
it('prefers file', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-and-files'));
|
||||
});
|
||||
context('target directory contains directories and files with the same name', () => {
|
||||
it('prefers file', () => {
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-and-files'));
|
||||
|
||||
expect(names).to.deep.equal(['foo.js', 'present.js']);
|
||||
});
|
||||
expect(names).to.deep.equal(['foo.js', 'present.js']);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+10
-10
@@ -4,16 +4,16 @@ import {
|
||||
import sortByDepth from './../src/utilities/sortByDepth';
|
||||
|
||||
describe('sortByDepth()', () => {
|
||||
it('sorts from deepest to the most shallow', () => {
|
||||
const paths = [
|
||||
'/b',
|
||||
'/a',
|
||||
'/a/b/c',
|
||||
'/a/b'
|
||||
];
|
||||
it('sorts from deepest to the most shallow', () => {
|
||||
const paths = [
|
||||
'/b',
|
||||
'/a',
|
||||
'/a/b/c',
|
||||
'/a/b'
|
||||
];
|
||||
|
||||
const sortedPaths = sortByDepth(paths);
|
||||
const sortedPaths = sortByDepth(paths);
|
||||
|
||||
expect(sortedPaths).to.deep.equal(['/a/b/c', '/a/b', '/b', '/a']);
|
||||
});
|
||||
expect(sortedPaths).to.deep.equal(['/a/b/c', '/a/b', '/b', '/a']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/* eslint-disable max-nested-callbacks */
|
||||
|
||||
import path from 'path';
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import path from 'path';
|
||||
import validateTargetDirectory from './../src/utilities/validateTargetDirectory';
|
||||
import validateTargetDirectory from '../src/utilities/validateTargetDirectory';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, './../../fixtures/validate-target-directory');
|
||||
const fixturesPath = path.resolve(__dirname, '../fixtures/validate-target-directory');
|
||||
|
||||
describe('validateTargetDirectory()', () => {
|
||||
describe('directory path', () => {
|
||||
context('refers to a directory that does not exist', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'does-not-exist'));
|
||||
}).to.throw(Error, 'Directory "' + path.resolve(fixturesPath, 'does-not-exist') + '" does not exist.');
|
||||
});
|
||||
});
|
||||
context('refers to a file', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'not-a-directory.js'));
|
||||
}).to.throw(Error, '"' + path.resolve(fixturesPath, 'not-a-directory.js') + '" is not a directory.');
|
||||
});
|
||||
});
|
||||
describe('directory path', () => {
|
||||
context('refers to a directory that does not exist', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'does-not-exist'));
|
||||
}).to.throw(Error, 'Directory "' + path.resolve(fixturesPath, 'does-not-exist') + '" does not exist.');
|
||||
});
|
||||
});
|
||||
describe('target index', () => {
|
||||
context('no index', () => {
|
||||
it('returns true', () => {
|
||||
expect(validateTargetDirectory(path.resolve(fixturesPath, 'no-index'))).to.equal(true);
|
||||
});
|
||||
});
|
||||
context('safe', () => {
|
||||
it('returns true', () => {
|
||||
expect(validateTargetDirectory(path.resolve(fixturesPath, 'safe-index'))).to.equal(true);
|
||||
});
|
||||
});
|
||||
context('unsafe', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'unsafe-index'));
|
||||
}).to.throw(Error, '"' + path.resolve(fixturesPath, 'unsafe-index/index.js') + '" unsafe index.');
|
||||
});
|
||||
});
|
||||
context('refers to a file', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'not-a-directory.js'));
|
||||
}).to.throw(Error, '"' + path.resolve(fixturesPath, 'not-a-directory.js') + '" is not a directory.');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('target index', () => {
|
||||
context('no index', () => {
|
||||
it('returns true', () => {
|
||||
expect(validateTargetDirectory(path.resolve(fixturesPath, 'no-index'))).to.equal(true);
|
||||
});
|
||||
});
|
||||
context('safe', () => {
|
||||
it('returns true', () => {
|
||||
expect(validateTargetDirectory(path.resolve(fixturesPath, 'safe-index'))).to.equal(true);
|
||||
});
|
||||
});
|
||||
context('unsafe', () => {
|
||||
it('throws an error', () => {
|
||||
expect(() => {
|
||||
validateTargetDirectory(path.resolve(fixturesPath, 'unsafe-index'));
|
||||
}).to.throw(Error, '"' + path.resolve(fixturesPath, 'unsafe-index/index.js') + '" unsafe index.');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+16
-16
@@ -1,36 +1,36 @@
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import {
|
||||
expect
|
||||
} from 'chai';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import writeIndex from '../src/utilities/writeIndex';
|
||||
import codeExample from './codeExample';
|
||||
import writeIndex from './../src/utilities/writeIndex';
|
||||
|
||||
const fixturesPath = path.resolve(__dirname, './../../fixtures/write-index');
|
||||
const fixturesPath = path.resolve(__dirname, '../fixtures/write-index');
|
||||
|
||||
describe('writeIndex()', () => {
|
||||
it('creates index in target directory', () => {
|
||||
const indexFilePath = path.resolve(fixturesPath, './mixed/index.js');
|
||||
it('creates index in target directory', () => {
|
||||
const indexFilePath = path.resolve(fixturesPath, './mixed/index.js');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(indexFilePath);
|
||||
/* eslint-disable no-empty */
|
||||
} catch (error) {
|
||||
try {
|
||||
fs.unlinkSync(indexFilePath);
|
||||
|
||||
}
|
||||
/* eslint-enable no-empty */
|
||||
// eslint-disable-next-line no-empty
|
||||
} catch (error) {
|
||||
|
||||
writeIndex([path.resolve(fixturesPath, './mixed')]);
|
||||
}
|
||||
|
||||
const indexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
writeIndex([path.resolve(fixturesPath, './mixed')]);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
const indexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
export bar from './bar';
|
||||
export foo from './foo.js';
|
||||
`));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user