Skip to content

Commit

Permalink
add createOutout test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaslee119 authored and 李 立 committed Oct 2, 2017
1 parent d9ca1c5 commit 2af795f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/createOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function createOutput(components, buildOption) {
}

output += `require('babel-loader!${compoPath}.js');\n`;
output += `require('css-loader!${compoPath}.css');\n`
output += `require('css-loader!${compoPath}.css');\n`;
});

return output;
Expand Down
15 changes: 15 additions & 0 deletions test/createOutput.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import createOutput from '../lib/createOutput';
import normalBuildOption from './util/buildOption.normal';
import normalComponents from './util/components.normal';


describe('test createOutput', function(){
it('should pass', function(){
const res = createOutput(normalComponents, normalBuildOption);
expect(res).toMatch(/require\('.*'\)/);
});

it('should throw error when pass in a bad Array', function(){
expect(()=>createOutput('NOT AN ARRAY', normalBuildOption)).toThrow('[webpack-component-loader]: the component is not an array');
})
})
31 changes: 31 additions & 0 deletions test/util/components.normal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default
[
{
"root": "",
"dir": "include",
"base": "componentA.tpl",
"ext": ".tpl",
"name": "componentA"
},
{
"root": "",
"dir": "include",
"base": "componentD.tpl",
"ext": ".tpl",
"name": "componentD"
},
{
"root": "",
"dir": "",
"base": "componentB.tpl",
"ext": ".tpl",
"name": "componentB"
},
{
"root": "/",
"dir": "",
"base": "pageC.tpl",
"ext": ".tpl",
"name": "pageC"
}
];

0 comments on commit 2af795f

Please sign in to comment.