Skip to content

Commit

Permalink
Added tests for dist client js
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewblond committed Jul 15, 2015
1 parent 96f2c12 commit 35ec5ca
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ libs
/*.tests
/*.sets
/*.tmpl-specs
/test/dist/fixtures
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ env:
- TEST_SCOPE: specs
- TEST_SCOPE: tmpls
- TEST_SCOPE: gemini
- TEST_SCOPE: dists

matrix:
fast_finish: true
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"devDependencies": {
"bem": "~0.9.0",
"bem-tools-autoprefixer": "~0.0.3",
"bem-walk": "1.0.0-alpha1",
"bh": "3.3.0",
"bower-npm-install": "~0.5.4",
"bower": "1.3.12",
Expand Down Expand Up @@ -62,13 +63,16 @@
"build-specs": "npm run deps",
"build-tmpls": "npm run deps",
"build-gemini": "npm run deps && magic make desktop.tests",
"build-dists": "npm run dist && node test/dist/build-fixtures.js",
"test": "npm run build && npm run ${TEST_SCOPE:-test-all}",
"test-all": "npm run lint && npm run unit && npm run test-tmpls && npm run gemini",
"test-all": "npm run lint && npm run unit && npm run test-tmpls && npm run gemini && npm run test-dists",
"test-specs": "magic run specs",
"test-tmpls": "magic run tmpl-specs",
"test-dists": "node_modules/enb-bem-specs/node_modules/.bin/mocha-phantomjs test/dist/fixtures/*.html",
"lint": "jshint-groups && jscs . && csscomb -vl .",
"specs": "npm run lint && npm run test-specs",
"tmpls": "npm run test-tmpls",
"dists": "npm run test-dists",
"unit": "npm run test-specs",
"gemini": "http-server -s -p 8000 & p=$!; gemini test --reporter html --reporter flat; e=$?; kill -9 ${p}; exit ${e}",
"gemini-gather": "http-server -c \"no-cache, no-store\" -s -p 8000 & p=$!; gemini gather; kill -9 ${p}",
Expand Down
46 changes: 46 additions & 0 deletions test/dist/assets/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<html>
<head>
<meta charset="utf-8">
<link href="mocha.css" rel="stylesheet" />
<link href="../../../dist/${ platform }/bem-components.css" rel="stylesheet" />
</head>
<body>
<div id="mocha"></div>
<script src="../../../dist/${ platform }/bem-components.js+bemhtml.js"></script>
<script src="mocha.js"></script>
<script src="sinon.js"></script>
<script src="chai.js"></script>
<script src="sinon-chai.js"></script>
<script>
(function() {
modules.define('spec', ['mocha', 'chai', 'sinon', 'sinon-chai'],
function(provide, mocha, chai, sinon, sinonChai) {
mocha.ui('bdd');

chai.use(sinonChai);
chai.should();

provide();
});
}());
</script>
${ scripts }
<script>
(function() {
var global = this;

modules.require(["jquery", "mocha", "spec"], function($, mocha) {
if (global.mochaPhantomJS) {
global.mochaPhantomJS.run(done)
} else {
mocha.run(done);
}

function done() {
$("#mocha").show();
}
});
}());
</script>
</body>
</html>
59 changes: 59 additions & 0 deletions test/dist/build-fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var fs = require('fs'),
path = require('path'),
walk = require('bem-walk'),
borschik = require('borschik').api,
sets = require('./config').sets,
platforms = Object.keys(sets),
fixturesDir = path.join(__dirname, 'fixtures'),
blocksDir = path.resolve('libs/bem-pr/spec.blocks'),
asset = fs.readFileSync(path.join(__dirname, 'assets', 'test.html'), 'utf-8');

if(!fs.existsSync(fixturesDir)) {
fs.mkdirSync(fixturesDir);
}

[
'mocha.css',
'mocha.js',
'chai.js',
'sinon.js',
'sinon-chai.js'
].map(function (basename) {
var name = basename.split('.')[0];

borschik({
input : path.join(blocksDir, name, basename),
output : path.join(fixturesDir, basename)
});
});

platforms.forEach(function (platform) {
var levels = sets[platform],
config = {
levels : levels.map(function (levelname) {
return { path : levelname };
})
},
walker = walk(levels, config),
specs = [];

walker.on('data', function (data) {
if(data.tech === 'spec.js') {
specs.push(data.path);
}
});

walker.on('end', function () {
html = buildHTML(platform, specs);

fs.writeFileSync(path.join(fixturesDir, platform + '.html'), html, 'utf-8');
});
});

function buildHTML(platform, specs) {
return asset
.replace(/\${ platform }/g, platform)
.replace(/\${ scripts }/g, specs.map(function (url) {
return ' <script src="../../../' + url + '"></script>';
}).join('\n'));
}
18 changes: 18 additions & 0 deletions test/dist/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
sets : {
desktop : [
'common.blocks',
'desktop.blocks'
],
'touch-pad' : [
'common.blocks',
'touch.blocks',
'touch-pad.blocks'
],
'touch-phone' : [
'common.blocks',
'touch.blocks',
'touch-phone.blocks'
]
}
};

0 comments on commit 35ec5ca

Please sign in to comment.