Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dansullivan86 committed Oct 19, 2016
1 parent f3c520d commit 0927cc6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/expected/basic_es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function() {
// this is a module definition file that includes this single module.
this.property = "some property";
};
4 changes: 4 additions & 0 deletions test/expected/basic_es6_advanced.js.regex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import\s([^\s]*)\sfrom\s\"([^\s)]*)\"\;export default Application\.Library\.TEMPLATES\['prefix\.basic'\] = function\(\) {
\/\/ this is a module definition file that includes this single module\.
this\.property = "some property";
}\;
4 changes: 4 additions & 0 deletions test/expected/basic_es6_require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Library from "library";export default function() {
// this is a module definition file that includes this single module.
this.property = "some property";
};
32 changes: 32 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('gulp-define-module', function() {
it('makes anonymous AMD modules', basic('amd'));
it('makes named AMD modules', basic('amd', amdNamingOptions, 'named'));
it('makes CommonJS modules', basic('commonjs'));
it('makes ES6 modules', basic('es6'));
it('makes Node modules', basic('node'));
it('makes Hybrid modules', basic('hybrid'));
it('makes plain modules', basic('plain'));
Expand All @@ -77,6 +78,7 @@ describe('gulp-define-module', function() {
it('handles require for AMD', basic('amd', requireOptions, 'require'));
it('handles require for Node', basic('node', requireOptions, 'require'));
it('handles require for CommonJS', basic('commonjs', requireOptions, 'require'));
it('handles require for ES6', basic('es6', requireOptions, 'require'));
it('handles require for Hybrid', basic('hybrid', requireOptions, 'require'));
it('ignores require for plain', basic('plain', requireOptions));

Expand Down Expand Up @@ -180,6 +182,36 @@ describe('gulp-define-module', function() {

});

it('processes options for ES6 both through invocation and incoming file', function(done) {

var stream = defineModule('es6', {
wrapper: 'Application.Library.TEMPLATES[\'<%= name %>\'] = <%= contents %>',
context: function(context) {
return { name: context.prefix + '.' + context.name };
},
require: { Library: 'app-library', Vendor: null }
});

var file = fixtureFile('basic.js');
file.defineModuleOptions = {
wrapper: 'Library.TEMPLATES[\'<%= name %>\'] = <%= contents %>',
context: { prefix: 'prefix' },
require: { Library: 'app-library', Vendor: 'shared-vendor-library' }
};

stream.on('data', function(file) {
fileShouldMatchExpected(file, 'basic_es6_advanced.js', function(match) {
match[1].should.eql('Library');
match[2].should.eql('app-library');
done();
});
});

stream.write(file);
stream.end();

});

describe('wrapper context', function() {
it('defines name', basic('plain', {
wrapper: 'App["<%= name %>"] = <%= contents %>'
Expand Down

0 comments on commit 0927cc6

Please sign in to comment.