Skip to content

Commit

Permalink
initial mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Gurianov committed Jun 22, 2015
1 parent a0b0bed commit 28f1b3f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 5 deletions.
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
"bem"
],
"devDependencies": {
"enb": "^0.15.0",
"jscs": "^1.13.1",
"jshint": "^2.8.0"
"enb": "0.15.0",
"jscs": "1.13.1",
"jshint": "2.8.0",
"mocha": "2.2.5",
"mock-enb": "0.0.1",
"mock-fs": "2.7.1",
"must": "0.12.0"
},
"dependencies": {
"ng-annotate": "^1.0.0"
},
"scripts": {
"test": "npm run lint",
"lint": "jshint . && jscs -c .jscs.js ."
"test": "npm run lint && npm run unit",
"lint": "jshint . && jscs -c .jscs.js .",
"unit": "mocha -R spec"
}
}
18 changes: 18 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"bitwise": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"immed": true,
"latedef": "nofunc",
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"undef": true,
"unused": true,
"node": true,
"mocha": true,
"expr": true,
"sub": true
}
4 changes: 4 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test/**/*.test.js
--ui bdd
--reporter dot
--require must
29 changes: 29 additions & 0 deletions test/techs/ng-annotate.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var mock = require('mock-fs'),
MockNode = require('mock-enb/lib/mock-node'),
ngAnnotate = require('../../techs/ng-annotate');

describe('ng-annotate', function () {
var bundle;

afterEach(function () {
mock.restore();
});

it('must apply ng-annotate module', function () {
mock({
blocks: {},
bundle: {
'bundle.pre.js': 'angular.module("MyMod").controller("MyCtrl", function(dep1, dep2) {});'
}
});

bundle = new MockNode('bundle');

var reference = 'angular.module("MyMod").controller("MyCtrl", ["dep1", "dep2", function(dep1, dep2) {}]);';

return bundle.runTechAndGetContent(ngAnnotate, { source: 'bundle.pre.js' })
.spread(function (content) {
content.toString().must.be(reference);
});
});
});
45 changes: 45 additions & 0 deletions test/techs/ng-templates.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var EOL = require('os').EOL,
mock = require('mock-fs'),
FileList = require('enb/lib/file-list'),
MockNode = require('mock-enb/lib/mock-node'),
ngTemplates = require('../../techs/ng-templates');

describe('ng-templates', function () {
var bundle,
fileList;

afterEach(function () {
mock.restore();
});

it('must wrap file content with script tag and use filename as id', function () {
mock({
blocks: {
'block0.tmpl.html': 'Hello0',
'block1.tmpl.html': 'Hello1'
},
bundle: {}
});

bundle = new MockNode('bundle');
fileList = new FileList();

fileList.loadFromDirSync('blocks');

bundle.provideTechData('?.files', fileList);

var reference = [
'<script type="text/ng-template" id="block0.tmpl.html">',
'Hello0',
'</script>',
'<script type="text/ng-template" id="block1.tmpl.html">',
'Hello1',
'</script>'
].join(EOL);

return bundle.runTechAndGetContent(ngTemplates)
.spread(function (content) {
content.toString().must.be(reference);
});
});
});

0 comments on commit 28f1b3f

Please sign in to comment.