Missing files.

This commit is contained in:
Gajus Kuizinas
2016-01-06 17:55:09 +00:00
parent e49a03d2ec
commit a91f9b8ead
42 changed files with 554 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
import _ from 'lodash';
export default (code) => {
return _.trim(code) + '\n\n';
};
+89
View File
@@ -0,0 +1,89 @@
/* eslint-disable no-restricted-syntax */
import {
expect
} from 'chai';
import createIndexCode from './../src/createIndexCode';
import codeExample from './codeExample';
describe('createIndexCode()', () => {
it('describes no children', () => {
let indexCode;
indexCode = createIndexCode([]);
expect(indexCode).to.equal(codeExample(`
'create index';
`));
});
it('describes a single child', () => {
let indexCode;
indexCode = createIndexCode(['foo']);
expect(indexCode).to.equal(codeExample(`
'create index';
import foo from './foo';
export {
foo
};
`));
});
it('describes multiple children', () => {
let indexCode;
indexCode = createIndexCode(['bar', 'foo']);
expect(indexCode).to.equal(codeExample(`
'create index';
import bar from './bar';
import foo from './foo';
export {
bar,
foo
};
`));
});
context('file with extension', () => {
it('removes the extension from the export statement', () => {
let indexCode;
indexCode = createIndexCode(['foo.js']);
expect(indexCode).to.equal(codeExample(`
'create index';
import foo from './foo.js';
export {
foo
};
`));
});
});
context('multiple, unsorted', () => {
it('sorts the files', () => {
let indexCode;
indexCode = createIndexCode(['foo', 'bar']);
expect(indexCode).to.equal(codeExample(`
'create index';
import bar from './bar';
import foo from './foo';
export {
bar,
foo
};
`));
});
});
});
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
+1
View File
@@ -0,0 +1 @@
'create index';
@@ -0,0 +1 @@
'create index';
+1
View File
@@ -0,0 +1 @@
'create index';
View File
+1
View File
@@ -0,0 +1 @@
'create index';
+92
View File
@@ -0,0 +1,92 @@
import {
expect
} from 'chai';
import path from 'path';
import readDirectory from './../src/readDirectory';
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'));
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'));
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'));
expect(names).to.deep.equal(['present']);
});
});
context.skip('target directory contains ./index.js', () => {
it('does not include ./index.js', () => {
let names;
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'));
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'));
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'));
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'));
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'));
expect(names).to.deep.equal(['foo.js', 'present.js']);
});
});
});
+22
View File
@@ -0,0 +1,22 @@
import {
expect
} from 'chai';
import sortByDepth from './../src/sortByDepth';
describe('sortByDepth()', () => {
it('sorts from deepest to the most shallow', () => {
let paths,
sortedPaths;
paths = [
'/b',
'/a',
'/a/b/c',
'/a/b'
];
sortedPaths = sortByDepth(paths);
expect(sortedPaths).to.deep.equal(['/a/b/c', '/a/b', '/b', '/a']);
});
});
+47
View File
@@ -0,0 +1,47 @@
/* eslint-disable max-nested-callbacks */
import {
expect
} from 'chai';
import path from 'path';
import validateTargetDirectory from './../src/validateTargetDirectory';
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('target index', () => {
context('no index', () => {
it('returns true', () => {
expect(validateTargetDirectory(path.resolve(fixturesPath, 'no-index'))).to.equal(true);
});
});
context.skip('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.');
});
});
});
});
+42
View File
@@ -0,0 +1,42 @@
/* eslint-disable no-restricted-syntax */
import {
expect
} from 'chai';
import fs from 'fs';
import path from 'path';
import codeExample from './codeExample';
import writeIndex from './../src/writeIndex';
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');
try {
fs.unlinkSync(indexFilePath);
} catch (error) {
}
writeIndex([path.resolve(fixturesPath, './mixed')]);
indexCode = fs.readFileSync(indexFilePath, 'utf8');
expect(indexCode).to.equal(codeExample(`
'create index';
import bar from './bar';
import foo from './foo.js';
export {
bar,
foo
};
`));
});
});