Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NetCZ/vue-separate-files-webpack-…
Browse files Browse the repository at this point in the history
…loader
  • Loading branch information
NetCZ committed Mar 19, 2019
2 parents fb93ba2 + 5e02fc4 commit 12f8f21
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
4 changes: 2 additions & 2 deletions 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 All @@ -89,7 +89,7 @@ exports.createParts = function createParts(options, dirPath, inputFile, fileName

if (_.has(parts, settings.tagName) || _.has(parts, settings.fileType)) {
var type = settings.tagName || settings.fileType;
throw new TypeError(`File "${file}" can't be used as "${type}", because it was already defined in "${_.get(parts[type], 'file', null)}".`);
throw new TypeError(`File "${ file }" can't be used as "${ type }", because it was already defined in "${ _.get(parts[type], 'file', null) }".`);
}

parts[settings.tagName || settings.fileType] = that.createPart(settings, options);
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.
31 changes: 27 additions & 4 deletions 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 @@ -48,11 +49,11 @@ describe('loader: errors', function () {
});

it('should throw duplication TypeError - multiple components in same directory', function () {
var content = require(duplicateDir + 'Component.vue');
var content = require(twoComponentsDuplicateSameDir + 'SecondComponent.vue');

assert.throws(function () {
loader.apply(_.assign({}, webpack, { context: twoComponentsDuplicateSameDir }), [content, { file: 'Component.vue.js' }]);
}, TypeError, 'File "SecondComponent.vue.html" can\'t be used as "template", because it was already defined in "FirstComponent.vue.html".');
loader.apply(_.assign({}, webpack, { context: twoComponentsDuplicateSameDir }), [content, { file: 'SecondComponent.vue.js' }]);
}, TypeError, 'File "SecondComponent.vue.pug" can\'t be used as "template", because it was already defined in "SecondComponent.vue.html".');
});
});

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 12f8f21

Please sign in to comment.