Skip to content

Commit

Permalink
fix: fix similar component names load
Browse files Browse the repository at this point in the history
  • Loading branch information
NetCZ committed Mar 19, 2019
1 parent 805d69b commit a4db849
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports.createPart = function createPart(settings, options) {
};

exports.createParts = function createParts(options, dirPath, inputFile, fileNames) {
var inputFileName = inputFile.split(options.test)[0];
var inputFileName = new RegExp(`^${ inputFile.split(options.test)[0] }`);
var parts = {},
that = this;

Expand Down
10 changes: 10 additions & 0 deletions test/files/similar-component-names/Component.vue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>
Empty file.
10 changes: 10 additions & 0 deletions test/files/similar-component-names/SimilarComponent.vue.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>
Empty file.
25 changes: 24 additions & 1 deletion test/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var twoPartsDir = path.resolve(dir + '/files/two-parts') + path.sep,
emptyDir = path.resolve(dir + '/files/empty') + path.sep,
twoComponentsSameDir = path.resolve(dir + '/files/two-components-same-dir') + path.sep,
twoComponentsDuplicateSameDir = path.resolve(dir + '/files/two-components-duplicate-same-dir') + path.sep,
twoPartsDirCustomScript = path.resolve(dir + '/files/two-parts-custom-script') + path.sep;
twoPartsDirCustomScript = path.resolve(dir + '/files/two-parts-custom-script') + path.sep,
similarComponentNamesDir = path.resolve(dir + '/files/similar-component-names') + path.sep;

beforeEach(function () {
loader = require('../index');
Expand Down Expand Up @@ -257,4 +258,26 @@ describe('loader: success', function () {

assert.strictEqual(result, expected);
});

it('should has two parts even when similar component names occurs - first component', function () {
var content = require(similarComponentNamesDir + 'Component.vue');

var expected = '<template separated src="' + similarComponentNamesDir + 'Component.vue.html" lang="html"></template>' +
'<script separated src="' + similarComponentNamesDir + 'Component.vue.js" lang="js"></script>';

var result = loader.apply(_.assign({}, webpack, { context: similarComponentNamesDir }), [content, { file: 'Component.vue.js' }]);

assert.strictEqual(result, expected);
});

it('should has two parts even when similar component names occurs - second component', function () {
var content = require(similarComponentNamesDir + 'SimilarComponent.vue');

var expected = '<template separated src="' + similarComponentNamesDir + 'SimilarComponent.vue.html" lang="html"></template>' +
'<script separated src="' + similarComponentNamesDir + 'SimilarComponent.vue.js" lang="js"></script>';

var result = loader.apply(_.assign({}, webpack, { context: similarComponentNamesDir }), [content, { file: 'SimilarComponent.vue.js' }]);

assert.strictEqual(result, expected);
});
});

0 comments on commit a4db849

Please sign in to comment.