mirror of
https://github.com/wassname/generator-react-webpack.git
synced 2026-09-10 12:00:17 +08:00
Added changes for version 2.0
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
let expect = require('chai').expect;
|
||||
|
||||
let utils = require('../../utils/config');
|
||||
let originalSettings = require('../../utils/configopts.json');
|
||||
|
||||
describe('Utilities:Config', () => {
|
||||
|
||||
describe('#getSetting', () => {
|
||||
|
||||
it('should return "null" if the key could not be found', () => {
|
||||
expect(utils.getSetting('bogus')).to.be.null;
|
||||
});
|
||||
|
||||
it('should return a settings object if it exists', () => {
|
||||
|
||||
let result = utils.getSetting('style');
|
||||
expect(result).to.be.an.object;
|
||||
expect(result).to.deep.equal(originalSettings.style);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChoices', () => {
|
||||
|
||||
it('should return "null" if the key could not be found', () => {
|
||||
expect(utils.getChoices('bogus')).to.be.null;
|
||||
});
|
||||
|
||||
it('should return an array of choices when queried correctly', () => {
|
||||
|
||||
let result = utils.getChoices('style');
|
||||
expect(result).to.be.an.array;
|
||||
expect(result).to.deep.equal(originalSettings.style.options);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getChoiceByKey', () => {
|
||||
|
||||
it('should return "null" if the key or the setting could not be found', () => {
|
||||
|
||||
expect(utils.getChoiceByKey('bogus', 'unknown')).to.be.null;
|
||||
expect(utils.getChoiceByKey('style', 'unknown')).to.be.null;
|
||||
});
|
||||
|
||||
it('should return the configured object when it can be found', () => {
|
||||
|
||||
expect(utils.getChoiceByKey('style', 'css')).to.equal(originalSettings.style.options[0]);
|
||||
expect(utils.getChoiceByKey('style', 'less')).to.equal(originalSettings.style.options[3]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDefaultChoice', () => {
|
||||
|
||||
it('should return "null" if the key could not be found', () => {
|
||||
expect(utils.getDefaultChoice('bogus')).to.be.null;
|
||||
});
|
||||
|
||||
it('should return the default choice when queried correctly', () => {
|
||||
|
||||
let result = utils.getDefaultChoice('style');
|
||||
expect(result).to.equal(originalSettings.style.default);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
let expect = require('chai').expect;
|
||||
let path = require('path');
|
||||
|
||||
let utils = require('../../utils/yeoman');
|
||||
let baseDir = path.basename(process.cwd());
|
||||
|
||||
describe('Utilities:Yeoman', () => {
|
||||
|
||||
describe('#getBaseDir', () => {
|
||||
|
||||
it('should return the current run directory', () => {
|
||||
expect(utils.getBaseDir()).to.equal(baseDir);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getCleanedPathName', () => {
|
||||
|
||||
it('should return normalized paths', () => {
|
||||
|
||||
let tests = {
|
||||
'my/full œ!/path!': 'my/full/path',
|
||||
'Test': 'test',
|
||||
'I am a Test Component!': 'iAmATestComponent',
|
||||
'A very\^specialChary!@componentName with !!!': 'aVerySpecialCharyComponentNameWith'
|
||||
};
|
||||
|
||||
for(let test in tests) {
|
||||
expect(utils.getCleanedPathName(test)).to.be.equal(tests[test]);
|
||||
expect(utils.getCleanedPathName(test, 'suffix')).to.be.equal(tests[test] + 'Suffix');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAppName', () => {
|
||||
|
||||
it('should return a js friendly application name', () => {
|
||||
let result = utils.getAppName('this is a test using % special / chars!');
|
||||
expect(result).to.be.equal('thisIsATestUsingSpecialChars');
|
||||
});
|
||||
|
||||
it('should use the current path for creating the appName if the argument is omitted', () => {
|
||||
|
||||
let resultWithoutArgs = utils.getAppName();
|
||||
let resultWithArgs = utils.getAppName(baseDir);
|
||||
|
||||
expect(resultWithoutArgs).to.be.equal(resultWithArgs);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getComponentStyleName', () => {
|
||||
|
||||
it('should return a components css className', () => {
|
||||
|
||||
let tests = {
|
||||
'my/full œ!/path!': 'path-component',
|
||||
'Test': 'test-component',
|
||||
'I am a Test Component!': 'i-am-a-test-component-component',
|
||||
'A very\^specialChary!@componentName with !!!': 'a-very-specialchary-componentname-with-component'
|
||||
};
|
||||
|
||||
for(let test in tests) {
|
||||
expect(utils.getComponentStyleName(test)).to.be.equal(tests[test]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAllSettingsFromComponentName', () => {
|
||||
|
||||
it('should get all required information for component creation from the components name', () => {
|
||||
|
||||
let expection = {
|
||||
style: {
|
||||
webpackPath: 'styles/my/component/Test.css',
|
||||
path: 'src/styles/my/component/',
|
||||
fileName: 'Test.css',
|
||||
className: 'test-component',
|
||||
suffix: '.css'
|
||||
},
|
||||
component: {
|
||||
webpackPath: 'components/my/component/TestComponent.js',
|
||||
path: 'src/components/my/component/',
|
||||
fileName: 'TestComponent.js',
|
||||
className: 'TestComponent',
|
||||
suffix: '.js'
|
||||
},
|
||||
test: {
|
||||
path: 'test/components/my/component/',
|
||||
fileName: 'TestComponentTest.js'
|
||||
}
|
||||
};
|
||||
|
||||
expect(utils.getAllSettingsFromComponentName('my/component/test')).to.deep.equal(expection);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user