chore: rename ./tests to ./test

This commit is contained in:
Gajus Kuizinas
2016-11-01 15:31:00 +00:00
parent 78109764f7
commit 272a836c96
45 changed files with 1 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
import _ from 'lodash';
export default (code) => {
return _.trim(code) + '\n\n';
};
+59
View File
@@ -0,0 +1,59 @@
/* eslint-disable no-restricted-syntax */
import {
expect
} from 'chai';
import createIndexCode from '../src/utilities/createIndexCode';
import codeExample from './codeExample';
describe('createIndexCode()', () => {
it('describes no children', () => {
const indexCode = createIndexCode([]);
expect(indexCode).to.equal(codeExample(`
'create index';
`));
});
it('describes a single child', () => {
const indexCode = createIndexCode(['foo']);
expect(indexCode).to.equal(codeExample(`
'create index';
export foo from './foo';
`));
});
it('describes multiple children', () => {
const indexCode = createIndexCode(['bar', 'foo']);
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']);
expect(indexCode).to.equal(codeExample(`
'create index';
export foo from './foo.js';
`));
});
});
context('multiple, unsorted', () => {
it('sorts the files', () => {
const indexCode = createIndexCode(['foo', 'bar']);
expect(indexCode).to.equal(codeExample(`
'create index';
export bar from './bar';
export foo from './foo';
`));
});
});
});
+19
View File
@@ -0,0 +1,19 @@
import path from 'path';
import {
expect
} from 'chai';
import glob from 'glob';
import findIndexFiles from '../src/utilities/findIndexFiles';
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;
names = findIndexFiles(path.resolve(fixturesPath));
names = names.sort();
expect(names).to.deep.equal(glob.sync(path.resolve(fixturesPath, '**/find-*')));
});
});
@@ -0,0 +1 @@
'create index';
+1
View File
@@ -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';
+1
View File
@@ -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';
@@ -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';
+5
View File
@@ -0,0 +1,5 @@
'create index';
export bar from './bar';
export foo from './foo.js';
+73
View File
@@ -0,0 +1,73 @@
import path from 'path';
import {
expect
} from 'chai';
import readDirectory from '../src/utilities/readDirectory';
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'));
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'));
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'));
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'));
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'));
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'));
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'));
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'));
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'));
expect(names).to.deep.equal(['foo.js', 'present.js']);
});
});
});
+19
View File
@@ -0,0 +1,19 @@
import {
expect
} from 'chai';
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'
];
const 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 path from 'path';
import {
expect
} from 'chai';
import validateTargetDirectory from '../src/utilities/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('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.');
});
});
});
});
+36
View File
@@ -0,0 +1,36 @@
/* eslint-disable no-restricted-syntax */
import fs from 'fs';
import path from 'path';
import {
expect
} from 'chai';
import writeIndex from '../src/utilities/writeIndex';
import codeExample from './codeExample';
const fixturesPath = path.resolve(__dirname, 'fixtures/write-index');
describe('writeIndex()', () => {
it('creates index in target directory', () => {
const indexFilePath = path.resolve(fixturesPath, 'mixed/index.js');
try {
fs.unlinkSync(indexFilePath);
// eslint-disable-next-line no-empty
} catch (error) {
}
writeIndex([path.resolve(fixturesPath, 'mixed')]);
const indexCode = fs.readFileSync(indexFilePath, 'utf8');
expect(indexCode).to.equal(codeExample(`
'create index';
export bar from './bar';
export foo from './foo.js';
`));
});
});