Skip to content

Commit

Permalink
Run the tests of downstream projects.
Browse files Browse the repository at this point in the history
This is done by checking out each project, run npm install, drop-in a
replacement for esprima.js, and run npm test. As of now, this is carried
out only as part of Travis CI build. It can be tested manually by:

  rm -rf downstream
  npm run downstream

Due to some unknown reason, .eslintrc can't exist otherwise it is going
to confuse the linting of the downstream project. The workaround is to
use custom config file.

Closes jquery#1023
Closes jquerygh-1206
  • Loading branch information
ariya committed Jun 30, 2015
1 parent 06adb24 commit 819cada
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
File renamed without changes.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

"check-version": "node test/check-version.js",
"jscs": "jscs esprima.js && jscs test/*.js",
"eslint": "node node_modules/eslint/bin/eslint.js esprima.js",
"eslint": "node node_modules/eslint/bin/eslint.js -c .lintrc esprima.js",
"complexity": "node test/check-complexity.js",
"static-analysis": "npm run check-version && npm run jscs && npm run eslint && npm run complexity",

Expand All @@ -71,7 +71,9 @@
"benchmark": "node test/benchmarks.js",
"benchmark-quick": "node test/benchmarks.js quick",

"travis": "npm test && coveralls < ./coverage/lcov.info",
"coveralls": "coveralls < ./coverage/lcov.info",
"downstream": "node test/downstream.js",
"travis": "npm test && npm run coveralls && npm run downstream",

"generate-regex": "node tools/generate-identifier-regex.js"
}
Expand Down
94 changes: 94 additions & 0 deletions test/downstream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Copyright (c) jQuery Foundation, Inc. and Contributors, All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

var child_process = require('child_process'),
fs = require('fs');

function execute(cmd) {
child_process.execSync(cmd, { stdio: 'inherit' });
}

function copy_file(source, target) {
fs.writeFileSync(target, fs.readFileSync(source));
}

function test_project(project, repo) {
console.log();
console.log('==========', project);
console.log();
console.log('Cloning', repo, '...');
execute('git clone --depth 1 ' + repo + ' ' + project);

process.chdir(project);
console.log();
console.log('HEAD is');
execute('git log -n1');

console.log();
execute('npm install');

console.log();
console.log('Replacing esprima.js with a fresh one...');
copy_file('../../esprima.js', './node_modules/esprima/esprima.js');

console.log();
try {
execute('npm test');
} catch (e) {
console.log('Failing: ', e.toString());
process.exit(1);
}
process.chdir('..');
}

function test_downstream(projects) {
var nodejs_version = 'v0.12',
downstream_path = 'downstream';

if (typeof child_process.execSync !== 'function') {
console.error('This only works with Node.js that support execSync');
process.exit(0);
}
if (process.version.indexOf(nodejs_version) !== 0) {
console.error('This is intended to run only with Node.js', nodejs_version);
process.exit(0);
}

if (!fs.existsSync(downstream_path)) {
fs.mkdirSync(downstream_path, 0766);
}
process.chdir(downstream_path);

Object.keys(projects).forEach(function (project) {
test_project(project, projects[project]);
});
}


test_downstream({
'escope': 'https://github.com/estools/escope.git',
'escomplex-js': 'https://github.com/philbooth/escomplex-js.git',
'js2coffee': 'https://github.com/js2coffee/js2coffee.git',
'istanbul': 'https://github.com/gotwarlost/istanbul.git'
});

0 comments on commit 819cada

Please sign in to comment.