Code style preferences.
This commit is contained in:
@@ -10,18 +10,14 @@ import codeExample from './codeExample';
|
||||
|
||||
describe('createIndexCode()', () => {
|
||||
it('describes no children', () => {
|
||||
let indexCode;
|
||||
|
||||
indexCode = createIndexCode([]);
|
||||
const indexCode = createIndexCode([]);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
`));
|
||||
});
|
||||
it('describes a single child', () => {
|
||||
let indexCode;
|
||||
|
||||
indexCode = createIndexCode(['foo']);
|
||||
const indexCode = createIndexCode(['foo']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
@@ -30,9 +26,7 @@ export foo from './foo';
|
||||
`));
|
||||
});
|
||||
it('describes multiple children', () => {
|
||||
let indexCode;
|
||||
|
||||
indexCode = createIndexCode(['bar', 'foo']);
|
||||
const indexCode = createIndexCode(['bar', 'foo']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
@@ -43,9 +37,7 @@ export foo from './foo';
|
||||
});
|
||||
context('file with extension', () => {
|
||||
it('removes the extension from the export statement', () => {
|
||||
let indexCode;
|
||||
|
||||
indexCode = createIndexCode(['foo.js']);
|
||||
const indexCode = createIndexCode(['foo.js']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
@@ -56,9 +48,7 @@ export foo from './foo.js';
|
||||
});
|
||||
context('multiple, unsorted', () => {
|
||||
it('sorts the files', () => {
|
||||
let indexCode;
|
||||
|
||||
indexCode = createIndexCode(['foo', 'bar']);
|
||||
const indexCode = createIndexCode(['foo', 'bar']);
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
+9
-27
@@ -10,81 +10,63 @@ const fixturesPath = path.resolve(__dirname, './../../fixtures/read-directory');
|
||||
describe('readDirectory()', () => {
|
||||
context('target directory contains child directories', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-directories'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories'));
|
||||
|
||||
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', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-directories-without-index'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-without-index'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
});
|
||||
context('target directory contains child directories (unsafe name)', () => {
|
||||
it('gets names of the children directories', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-unsafe-name'));
|
||||
|
||||
expect(names).to.deep.equal(['present']);
|
||||
});
|
||||
});
|
||||
context('target directory contains ./index.js', () => {
|
||||
it('does not include ./index.js', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-index'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-index'));
|
||||
|
||||
expect(names).to.deep.equal(['bar', 'foo']);
|
||||
});
|
||||
});
|
||||
context('target directory contains files', () => {
|
||||
it('refers to the files (with extension)', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-files'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files'));
|
||||
|
||||
expect(names).to.deep.equal(['bar.js', 'foo.js']);
|
||||
});
|
||||
});
|
||||
context('target directory contains dot files', () => {
|
||||
it('ignores files', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-dot-files'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-dot-files'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
});
|
||||
context('target directory contains files with no extension', () => {
|
||||
it('ignores files', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-files-no-extension'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-no-extension'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
});
|
||||
context('target directory contains files with multiple extensions', () => {
|
||||
it('ignores files', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-files-multiple-extensions'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-files-multiple-extensions'));
|
||||
|
||||
expect(names).to.deep.equal(['present.js']);
|
||||
});
|
||||
});
|
||||
context('target directory contains directories and files with the same name', () => {
|
||||
it('prefers file', () => {
|
||||
let names;
|
||||
|
||||
names = readDirectory(path.resolve(fixturesPath, 'children-directories-and-files'));
|
||||
const names = readDirectory(path.resolve(fixturesPath, 'children-directories-and-files'));
|
||||
|
||||
expect(names).to.deep.equal(['foo.js', 'present.js']);
|
||||
});
|
||||
|
||||
@@ -5,17 +5,14 @@ import sortByDepth from './../src/utilities/sortByDepth';
|
||||
|
||||
describe('sortByDepth()', () => {
|
||||
it('sorts from deepest to the most shallow', () => {
|
||||
let paths,
|
||||
sortedPaths;
|
||||
|
||||
paths = [
|
||||
const paths = [
|
||||
'/b',
|
||||
'/a',
|
||||
'/a/b/c',
|
||||
'/a/b'
|
||||
];
|
||||
|
||||
sortedPaths = sortByDepth(paths);
|
||||
const sortedPaths = sortByDepth(paths);
|
||||
|
||||
expect(sortedPaths).to.deep.equal(['/a/b/c', '/a/b', '/b', '/a']);
|
||||
});
|
||||
|
||||
+2
-5
@@ -12,10 +12,7 @@ const fixturesPath = path.resolve(__dirname, './../../fixtures/write-index');
|
||||
|
||||
describe('writeIndex()', () => {
|
||||
it('creates index in target directory', () => {
|
||||
let indexCode,
|
||||
indexFilePath;
|
||||
|
||||
indexFilePath = path.resolve(fixturesPath, './mixed/index.js');
|
||||
const indexFilePath = path.resolve(fixturesPath, './mixed/index.js');
|
||||
|
||||
try {
|
||||
fs.unlinkSync(indexFilePath);
|
||||
@@ -27,7 +24,7 @@ describe('writeIndex()', () => {
|
||||
|
||||
writeIndex([path.resolve(fixturesPath, './mixed')]);
|
||||
|
||||
indexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
const indexCode = fs.readFileSync(indexFilePath, 'utf8');
|
||||
|
||||
expect(indexCode).to.equal(codeExample(`
|
||||
'create index';
|
||||
|
||||
Reference in New Issue
Block a user